Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Conversation

@valentinewallace
Copy link
Contributor

@valentinewallace valentinewallace commented Sep 1, 2018

Closes #423.

The storybook is not happy if you enter values and click Next due to the store values 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?

Copy link
Contributor

@tanx tanx left a 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?

* @return {Promise<undefined>}
*/
async initWallet({ walletPassword, seedMnemonic }) {
async initWallet({ walletPassword, seedMnemonic, recoveryWindow }) {
Copy link
Contributor

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',
});
}
Copy link
Contributor

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?

* @return {undefined}
*/
initRestoreWallet() {
this._store.wallet.seedVerify = Array(24).fill('');
Copy link
Contributor

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?

await this.initWallet({
walletPassword: password,
seedMnemonic: this._store.seedMnemonic.toJSON(),
recoveryWindow: 0,
Copy link
Contributor

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}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

});
} else {
await this.unlockWallet({ walletPassword: password });
}
Copy link
Contributor

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?

} else {
const { seedMnemonic: words } = store;
return words.length ? getSeedIndexes(1, words.length, 3) : [];
}
Copy link
Contributor

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.

: 0;
const c0 = formatOrdinal(seedVerifyIndexes[startingIndex]);
const c1 = formatOrdinal(seedVerifyIndexes[startingIndex + 1]);
const c2 = formatOrdinal(seedVerifyIndexes[startingIndex + 2]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same point as above.

/>
))}
{store.seedVerifyIndexes
.slice(store.wallet.restoreIndex, store.wallet.restoreIndex + 3)
Copy link
Contributor

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);
Copy link
Contributor

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.

@valentinewallace valentinewallace force-pushed the restore-wallet branch 3 times, most recently from 76947bf to 65fd00c Compare September 5, 2018 01:55
Copy link
Contributor

@tanx tanx left a 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)}`,
});
Copy link
Contributor

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.

Copy link
Contributor Author

@valentinewallace valentinewallace Sep 5, 2018

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:
deepinscreenshot_select-area_20180905131951

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.

this._notification.display({
type: 'error',
msg: `Initializing wallet failed: ${err.details}`,
});
Copy link
Contributor

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?

Copy link
Contributor Author

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?

@ghost
Copy link

ghost commented Sep 11, 2018

Tested this manually - in general it seems to work as advertised. Nice work :).

Couple of remarks...

Firstly, when I made a mistake typing in the seed the first reaction was to click the back button and toggle through the steps to see if there was a typo. Clicking the back button takes us back to the SelectSeed route which resets all the fields. It would have been a better user experience to go back to the previous RestoreSeed step. This is probably out of scope of this PR and something we can improve upon later.

Secondly, after entering the correct seed and password it redirects to SeedSuccess view which felt strange because I already had my wallet funded. Maybe we should redirect to Home instead after a successful restore?

Additionally, after restoring my console filled up with tons of warnings about a possible memory leak and the application felt janky for a second or two. In my test environment I had 400 blocks mined (simnet).
screen shot 2018-09-12 at 00 41 56

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.
@valentinewallace
Copy link
Contributor Author

@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.

@ghost
Copy link

ghost commented Sep 13, 2018

@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:

  1. rm -Rf data
  2. npm run electron-dev
  3. generate new seed -> add coins (copy address)
  4. close electron-dev
  5. btcd --txindex --simnet --rpcuser=kek --rpcpass=kek --datadir=data/btcd/data --logdir=data/btcd/logs --miningaddr=<YOUR_ADD_COIN_ADDRESS>
  6. btcctl --simnet --rpcuser=kek --rpcpass=kek generate 400
  7. close btcd
  8. rm -Rf data/lnd
  9. npm run electron-dev
  10. restore from seed -> enter password
  11. wait several seconds
  12. error - the console is filled with (node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit. warnings (see screenshot above)

Copy link
Contributor

@tanx tanx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@tanx tanx merged commit 2794795 into master Sep 13, 2018
@tanx tanx deleted the restore-wallet branch September 13, 2018 14:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Restore wallet from recovery phrase

3 participants