-
Notifications
You must be signed in to change notification settings - Fork 168
Restore wallet #612
Restore wallet #612
Conversation
tanx
left a comment
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.
Took a first rough pass at the code. Perhaps let's discuss this via video before the app weekly?
src/action/wallet.js
Outdated
| * @return {Promise<undefined>} | ||
| */ | ||
| async initWallet({ walletPassword, seedMnemonic }) { | ||
| async initWallet({ walletPassword, seedMnemonic, recoveryWindow }) { |
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.
Set default value initWallet({ walletPassword, seedMnemonic, recoveryWindow = 0 }) so that we don't have to set it above.
| type: 'error', | ||
| msg: 'Initializing wallet failed', | ||
| }); | ||
| } |
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 do we need to navigate to SelectSeed in this case?
src/action/wallet.js
Outdated
| * @return {undefined} | ||
| */ | ||
| initRestoreWallet() { | ||
| this._store.wallet.seedVerify = Array(24).fill(''); |
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 restoring the seed is semantically different. Perhaps we should use a separate param than store.wallet.seedVerify which is used in seed verification?
src/action/wallet.js
Outdated
| await this.initWallet({ | ||
| walletPassword: password, | ||
| seedMnemonic: this._store.seedMnemonic.toJSON(), | ||
| recoveryWindow: 0, |
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.
Not needed if default is set.
| const SettingUnitView = ({ store, nav, setting }) => { | ||
| return ( | ||
| <Background color={color.blackDark} style={styles.wrapper}> | ||
| <Background color={color.blackDark}> |
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 catch!
src/action/wallet.js
Outdated
| }); | ||
| } else { | ||
| await this.unlockWallet({ walletPassword: password }); | ||
| } |
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.
Not sure I understand. Why are we using the password check screen for restoration?
src/computed/seed.js
Outdated
| } else { | ||
| const { seedMnemonic: words } = store; | ||
| return words.length ? getSeedIndexes(1, words.length, 3) : []; | ||
| } |
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 mix seed verification logic and seed restore logic? Seems like this code would be much clean if the two were separated.
src/computed/seed.js
Outdated
| : 0; | ||
| const c0 = formatOrdinal(seedVerifyIndexes[startingIndex]); | ||
| const c1 = formatOrdinal(seedVerifyIndexes[startingIndex + 1]); | ||
| const c2 = formatOrdinal(seedVerifyIndexes[startingIndex + 2]); |
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.
Same point as above.
src/view/restore-wallet.js
Outdated
| /> | ||
| ))} | ||
| {store.seedVerifyIndexes | ||
| .slice(store.wallet.restoreIndex, store.wallet.restoreIndex + 3) |
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.
Might be cleaner to pull out the slice(...) logic into a computed attribute?
| nav: PropTypes.object.isRequired, | ||
| }; | ||
|
|
||
| export default observer(SelectSeedView); |
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 cleaned this view up a bit.
76947bf to
65fd00c
Compare
tanx
left a comment
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.
Looks much better. Second pass 🙂
| this._notification.display({ | ||
| type: 'error', | ||
| msg: `Initializing wallet failed: ${JSON.stringify(err)}`, | ||
| }); |
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 no need to set type: error if err is passed. Also, the JSON.stringify(err) is already done by the logger. So we can change this back to the way it was.
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.
When I leave it the way it was, the error appears like this on the screen:

Which allows the user to click "Show error logs," bringing them to the CLI, and from there they can navigate to the home screen even though their wallet hasn't been initialized.
I do think it's a good idea to give some level of detail in the notification's error message.. Let me know if you like the new solution, I just show the detalis field of the error.
65fd00c to
7baa15f
Compare
| this._notification.display({ | ||
| type: 'error', | ||
| msg: `Initializing wallet failed: ${err.details}`, | ||
| }); |
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 above does the same in one line. Why the change?
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.
Sorry, did you see this comment? #612 (comment) This is the reason I changed it, you may not be getting the same issue?
restoreIndex keeps track of how many seed words the user has entered so we know which ones are remaining for the user to enter. We want to reset these values on the start of the restore process, as well as ensure they are up to date as the user goes from one page of restore entries to the next.
This view is shown on a fresh start of the app to allow the user to either restore an existing wallet or initialize a new one.
…es and inits. Correctly initialize the next restore page before navigating to it, display the correct restore seed verify indices and enter the user input into wallet.restoreSeed.
This view was previously named RestoreWallet.
7baa15f to
d778154
Compare
|
@ERKarl Thanks so much for the feedback! I agree that clicking the back button should go to the previous page and not erase the entries, so that's what it does now. :) Not sure about going to home instead of seed success, thought it would be good to tell the user that it succeeded and give them an opportunity to deposit coin? I left that part out, but @tanx let me know what you think. I'm also unable to reproduce the memory leaks. Good thing users don't have devtools open, haha. |
|
@valentinewallace awesome :). I tested out your added changes and the back functionality is much better now. Regarding the memory leak. I was able to consistently reproduce the errors on 2 machines following these steps:
|
tanx
left a comment
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.
LGTM 👍

Closes #423.
The storybook is not happy if you enter values and click
Nextdue to thestorevalues being set as if the user were initializing a new wallet, not restoring an old one. Not sure if this is OK or worth fixing?