-
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
[Wallet] Wallet can switch between hosted and local node #1419
Conversation
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.
Great progress! See questions below
@@ -4,23 +4,23 @@ | |||
|
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.
yeah it did the same for me, i had to manually revert it. But it's nbd feel free to leave in this PR
packages/mobile/.env.alfajores
Outdated
DEFAULT_SYNC_MODE=5 | ||
ZERO_SYNC_INITIALLY=true |
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.
Can you clarify what this config is for exactly? My first guess would be it's whether or not the app should use zero sync when it starts, but that would conflict with the DEFAULT_SYNC_MODE config we already have.
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.
DEFAULT_SYNC_MODE now specifies the sync mode for when geth is turned on
Because geth will turn on and off, DEFAULT_SYNC_MODE can't encode whether the app should use zeroSync initially. Added a comment in the .env file
throw new Error('addLocalAccount can only be called in Zero sync mode') | ||
// Mutates web3 with new provider | ||
export function switchWeb3ProviderForSyncMode(zeroSync: boolean) { | ||
if (zeroSync) { |
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.
Can we get a bit more logging here? Unless you already have it elsewhere where it's called.
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.
There's already some logging where it's called but I added logging for each provider switch
// Note that if geth is running it saves the key using web3.personal. | ||
const privateKey = String(key) | ||
account = getAccountAddressFromPrivateKey(privateKey) | ||
yield savePrivateKeyToLocalDisk(account, privateKey, pincode) |
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 makes me nervous. We allowed it for zerosync mode, which I half-assumed was just a temporary thing. but if we're now going to permanently store the user's private key (encrypted by their pincode which could be poor and/or lost), I think we should have a broader discussion about it first. Maybe we already have but I missed it?
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.
Thanks for flagging this. After looking into it, geth also stores the private keys in a file encrypted with the password (for which we use the same pincode), so I will keep this as is for now.
See https://celo-org.slack.com/archives/CL7BVQPHB/p1571763622020000
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.
Ok
packages/mobile/src/web3/saga.ts
Outdated
// TODO(anna) implement switching geth on/off, changing web3 provider | ||
return true | ||
// Stores account and private key in web3 keystore using web3.eth.personal | ||
export function* addAccountToWeb3Keystore(key: string, currentAccount: string, pincode: any) { |
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.
any reason pincode isn't a string?
packages/mobile/src/web3/saga.ts
Outdated
|
||
export function* switchZeroSyncMode(action: SetIsZeroSyncAction) { | ||
Logger.debug(TAG + '@switchZeroSyncMode', ` to: ${action.zeroSyncMode}`) | ||
yield call(getConnectedAccount) // Ensure web3 connected before switching provider |
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.
why wait for us to be connected first?
packages/mobile/src/web3/saga.ts
Outdated
export function* switchToGethFromZeroSync() { | ||
yield call(initGethSaga) | ||
|
||
setZeroSyncMode(false) |
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 missing a yield put
here?
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.
Yeah thanks for catching this
packages/mobile/src/web3/saga.ts
Outdated
|
||
export function* switchToZeroSyncFromGeth() { | ||
Logger.debug(TAG + 'Switching to zeroSync from geth..') | ||
setZeroSyncMode(true) |
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.
ditto
packages/mobile/src/web3/saga.ts
Outdated
'Importing account from private key to web3 keystore' | ||
) | ||
const pincode = yield call(getPincode) | ||
const privateKey: string = yield readPrivateKeyFromLocalDisk(currentAccount, pincode) |
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: yield call?
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
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.
The code changes lgtm. See my question below about the default value for ZERO_SYNC_ENABLED_INITIALLY
and see CI tests, which seem to have failed.
packages/mobile/.env
Outdated
# -1 == ZeroSync, 5 == Ultralight, see src/geth/consts.ts for more info | ||
# If ZERO_SYNC_ENABLED_INITIALLY, local geth will not run initially. | ||
# If toggled on, it will use DEFAULT_SYNC_MODE. See src/geth/consts.ts for more info | ||
ZERO_SYNC_ENABLED_INITIALLY=true |
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.
Thanks for clarifying the this. My next question is then: should this be true? My understanding from my chat with Connor about this a while back was that we'd keep using geth by default during development, so we could catch bugs early (since prod still uses geth)
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 point for usually using geth during development. I'll have this be false for all env files for now.
// Note that if geth is running it saves the key using web3.personal. | ||
const privateKey = String(key) | ||
account = getAccountAddressFromPrivateKey(privateKey) | ||
yield savePrivateKeyToLocalDisk(account, privateKey, pincode) |
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.
Ok
Codecov Report
@@ Coverage Diff @@
## master #1419 +/- ##
==========================================
- Coverage 65.86% 65.48% -0.39%
==========================================
Files 271 271
Lines 8062 8144 +82
Branches 559 560 +1
==========================================
+ Hits 5310 5333 +23
- Misses 2639 2697 +58
- Partials 113 114 +1
Continue to review full report at Codecov.
|
* master: [Wallet] Wallet can switch between hosted and local node (#1419) [Wallet] Prevent error from Avatar when name is missing (#1454) [Wallet] Show splash screen until JS is ready on iOS (#1453) Use new segment api keys used by both iOS and Android (#1452) [Wallet] Don't log all props, which includes i18n (#1445) [Helm] Updated the helm package to deploy the upgraded blockscout version (#1129) Tiny copy change (#1429) [contractkit] SortedOraclesWrapper + tests (#1405) [wallet] Refactor leftover thunk to sagas (#1388) [Wallet] Fix repeated QR code scanning and related navigation issues (#1439) [Wallet] Show the currency values with correct rounding. (#1435) [Wallet] Fix firebase initialization error on iOS after reinstalling the app (#1423) [Wallet] Use exit on iOS since we can't restart like Android (#1424) [Wallet] Update local currency styles and layout (#1325) Reset pincode cache if unlock fails (#1430)
Description
Allow wallet users to switch between a local and a hosted node.
Handle storing the private key in web3.eth.personal (with local node) vs in the WalletKit Celo provider (with hosted node)
Tested
Tested on device on alfajores.
Build that starts in zeroSync mode:
sent tx, turned zeroSync mode off and confirmed that geth starts, sent tx, turned zeroSync mode off and confirmed that geth stops, sent tx
Build that starts in ultralight mode:
sent tx, turned on zeroSync mode, confirmed that geth turns off, sent tx
More testing to be done by the QA team
Other changes
Related issues
Backwards compatibility
Not with pervious code with ZeroSync mode encoded as
DEFAULT_SYNC_MODE=-1
.There are now Separate parameters (
DEFAULT_SYNC_MODE
andZERO_SYNC_INITIALLY
) in .env file