Skip to content
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

Fix recreate vault import accounts #1756

Merged
merged 9 commits into from
Aug 12, 2020
17 changes: 17 additions & 0 deletions app/components/Views/ChoosePassword/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,18 @@ class ChoosePassword extends PureComponent {
recreateVault = async password => {
const { KeyringController, PreferencesController } = Engine.context;
const seedPhrase = await this.getSeedPhrase();

const importedAccounts = [];

// Get imported accounts
if (KeyringController.state.keyrings.length === 2) {
Copy link
Member

Choose a reason for hiding this comment

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

On the extension we have one keyring for each imported account - I am guessing mobile is the same? So this should handle all keyrings from index 1 onwards.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right! Thanks, fixing this now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should be fixed now 👍

const simpleKeyring = KeyringController.state.keyrings[1];
for (let i = 0; i < simpleKeyring.accounts.length; i++) {
const privateKey = await KeyringController.exportAccount(password, simpleKeyring.accounts[i]);
importedAccounts.push(privateKey);
}
}

// Recreate keyring with password given to this method
await KeyringController.createNewVaultAndRestore(password, seedPhrase);
// Keyring is set with empty password or not
Expand All @@ -371,6 +383,11 @@ class ChoosePassword extends PureComponent {
await KeyringController.addNewAccount();
}

// Import imported accounts again
for (let i = 0; i < importedAccounts.length; i++) {
await KeyringController.importAccountWithStrategy('privateKey', [importedAccounts[i]]);
}

// Reset preferencesControllerState
preferencesControllerState = PreferencesController.state;

Expand Down