-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query and record exchange rate using notification service #1020
Conversation
…o-org/celo-monorepo into annakaz/ex-rate-notification-service
Codecov Report
@@ Coverage Diff @@
## master #1020 +/- ##
=======================================
Coverage 66.45% 66.45%
=======================================
Files 256 256
Lines 7349 7349
Branches 424 424
=======================================
Hits 4884 4884
Misses 2377 2377
Partials 88 88
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice first pass! A few comments below :)
@@ -19,6 +19,8 @@ | |||
"deploy": "./deploy.sh" | |||
}, | |||
"dependencies": { | |||
"@celo/utils": "^0.0.6-beta5", | |||
"@celo/walletkit": "^0.0.14", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we shouldn't add a dependency on walletkit here given that we want to deprecate that in favor of contract kit anyway. Can you change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to be consistent with the mobile app, which uses walletkit
: https://github.com/celo-org/celo-monorepo/blob/master/packages/mobile/src/exchange/actions.ts#L6
contractkit
doesn't have the same getExchangeRate()
function, so using contractkit
would mean pasting over the code in walletkit
.
I created an issue to migrate this and the mobile app away from walletkit
after the exchange (or another util where this and the mobile app can share logic) is implemented in contractkit
. #1026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated ContractKit with the needed functionality
#1083
@@ -36,6 +36,10 @@ export const DEFAULT_LOCALE = process.env.DEFAULT_LOCALE | |||
export const POLLING_INTERVAL = Number(process.env.POLLING_INTERVAL) || 1000 | |||
export const NOTIFICATIONS_TTL_MS = Number(process.env.NOTIFICATION_TTL_MS) || 3600 * 1000 * 24 * 7 // 1 week in milliseconds | |||
|
|||
export const EXCHANGE_POLLING_INTERVAL = | |||
Number(process.env.EXCHANGE_POLLING_INTERVAL) || 30 * 60 * 1000 // 30 minutes in milliseconds | |||
export const WEB3_PROVIDER_URL = process.env.WEB3_PROVIDER_URL || 'http://34.83.137.48:8545' // Default to integration transaction node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this ip seems likely to change as integration churns right? I don't feel strongly but I'd prefer to have it just error if it can find a web3 provider value. Or, even better, have it skip exchange rate polling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Updated to skip exchange polling if it can't find a web3 provider value
let web3: Web3 | ||
export function getWeb3Instance(): Web3 { | ||
if (web3) { | ||
if (web3.eth.net.isListening()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
|
||
export const exchangePolling = AsyncPolling(async (end) => { | ||
try { | ||
const web3 = await getWeb3Instance() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, any reason to get web3 here given that it's in the same file as handleExchangeQuery?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@@ -13,3 +14,14 @@ export const notificationPolling = AsyncPolling(async (end) => { | |||
end() | |||
} | |||
}, POLLING_INTERVAL) | |||
|
|||
export const exchangePolling = AsyncPolling(async (end) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm slightly concerned about the impact of having two things polling at the same time given that JS is single threaded, though admittedly this one doesn't run often. If you can confirm that it doesn't seem to interfere with the notification polling then I think we're good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From running locally, this doesn't seem to interfere, but I'm going to test deploying this to integration to confirm
let dollarMakerRate: number | ||
let goldMakerRate: number | ||
it('should fetch a working web3 instance', async () => { | ||
web3 = await getWeb3Instance() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you mocking web3 for this? if not, I recommend we do.
If you need a semi-realistic web3 mock, you can use the one in mobile/__mocks__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After moving the getExchangeRate function to ContractKit
, these tests don't improve coverage, as they are directly testing a function in ContractKit
. So I removed this
…o-org/celo-monorepo into annakaz/ex-rate-notification-service
…o-org/celo-monorepo into annakaz/ex-rate-notification-service
Note that since integration is having issues with view functions (running into same |
Added instructions to update |
Note that the build is failing, but this is happening on master right now and will be fixed by #1088 |
* master: (61 commits) Remove locales as website is now just in English (#1050) Add MetadataURL to account struct (#1103) Allow validators to use any valid combination of gold commitments as stake (#885) Fix blockscout websocket jsonrpc url (#1096) [Wallet] Preliminary iOS support (#1098) [Wallet] Set security fee description translation in Spanish (#1097) Exclude generated in vscode file watcher setting (#1082) Update .env and .env.integration files (#1087) Allow a testnet to run without ethstats (#1085) Collect exchange rate time series using notification service (#1020) Return to preview view when Fee Education is closed (#1068) [Wallet] Pin Setup Flow v2 (#1054) Added a variable for electoral threshold (#1023) [celotool]Store .env config on GCS after deployment (#1086) Group size limit (#1035) Fix governance unit tests (#1084) Add getExchangeRate to ContractKit (#1083) [CLI]Unlock till the geth exits (#1070) Add Quorum and Refactor Governance (#430) Shuffle elected validators using block randomness (#1033) ...
Description
To allow for a time series of the gold/dollar exchange rate, query the Exchange contract exchange rate using the notification service polling every 30 minutes, and store the result in Firebas. This allows developers to build like showing a time series of the gold/dollar exchange rate to app users.
The view calls are made by a web3 instance that uses a transaction node as a provider.
Tested
Tested locally with
yarn start:local
.Not yet deployed to GCP, so storage in firebase has not been tested.
Other changes
Updated readme deploy script.
Related issues
Backwards compatibility
Yes, this builds on top of notification service but does not modify what is already there.