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
27 changes: 27 additions & 0 deletions app/components/Views/ChoosePassword/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,24 @@ class ChoosePassword extends PureComponent {
recreateVault = async password => {
const { KeyringController, PreferencesController } = Engine.context;
const seedPhrase = await this.getSeedPhrase();

let importedAccounts = [];
try {
// Get imported accounts
const simpleKeyrings = KeyringController.state.keyrings.filter(
keyring => keyring.type === 'Simple Key Pair'
);
for (let i = 0; i < simpleKeyrings.length; i++) {
const simpleKeyring = simpleKeyrings[i];
const simpleKeyringAccounts = await Promise.all(
simpleKeyring.accounts.map(account => KeyringController.exportAccount(password, account))
);
importedAccounts = [...importedAccounts, ...simpleKeyringAccounts];
}
} catch (e) {
console.warn(e);
Copy link
Contributor

Choose a reason for hiding this comment

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

what if we use the logger here to get the errors in sentry?

}

// 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 +389,15 @@ class ChoosePassword extends PureComponent {
await KeyringController.addNewAccount();
}

try {
// Import imported accounts again
for (let i = 0; i < importedAccounts.length; i++) {
await KeyringController.importAccountWithStrategy('privateKey', [importedAccounts[i]]);
}
} catch (e) {
console.warn(e);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

}

// Reset preferencesControllerState
preferencesControllerState = PreferencesController.state;

Expand Down