mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Break up migration function
This commit is contained in:
parent
291403c13f
commit
9e54e3baa0
@ -442,37 +442,37 @@ module.exports = class MetamaskController {
|
|||||||
// with the provided password, so the other unlock steps
|
// with the provided password, so the other unlock steps
|
||||||
// may be completed without interruption.
|
// may be completed without interruption.
|
||||||
migrateOldVaultIfAny (password) {
|
migrateOldVaultIfAny (password) {
|
||||||
const shouldMigrate = !!this.configManager.getWallet() && !this.configManager.getVault()
|
|
||||||
if (!shouldMigrate) {
|
if (!this.checkIfShouldMigrate()) {
|
||||||
return Promise.resolve(password)
|
return Promise.resolve(password)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const keyringController = this.keyringController
|
||||||
|
|
||||||
return this.idStoreMigrator.migratedVaultForPassword(password)
|
return this.idStoreMigrator.migratedVaultForPassword(password)
|
||||||
.then((result) => {
|
.then(this.restoreOldVaultAccounts.bind(this))
|
||||||
|
.then(this.restoreOldLostAccounts.bind(this))
|
||||||
|
.then(keyringController.persistAllKeyrings.bind(keyringController))
|
||||||
|
.then(() => password)
|
||||||
|
}
|
||||||
|
|
||||||
this.keyringController.password = password
|
checkIfShouldMigrate() {
|
||||||
const { serialized } = result
|
return !!this.configManager.getWallet() && !this.configManager.getVault()
|
||||||
|
}
|
||||||
|
|
||||||
// Restore the correct accounts first:
|
restoreOldVaultAccounts(migratorOutput) {
|
||||||
return this.keyringController.restoreKeyring(serialized)
|
const { serialized } = migratorOutput
|
||||||
.then(() => result)
|
return this.keyringController.restoreKeyring(serialized)
|
||||||
|
.then(() => migratorOutput)
|
||||||
|
}
|
||||||
|
|
||||||
}).then((result) => {
|
restoreOldLostAccounts(migratorOutput) {
|
||||||
|
const { lostAccounts } = migratorOutput
|
||||||
// Now we restore any lost accounts:
|
if (lostAccounts) {
|
||||||
const { lostAccounts } = result
|
this.configManager.setLostAccounts(lostAccounts.map(acct => acct.address))
|
||||||
if (result && lostAccounts) {
|
return this.importLostAccounts(migratorOutput)
|
||||||
this.configManager.setLostAccounts(lostAccounts.map((acct) => acct.address))
|
}
|
||||||
return this.importLostAccounts(result)
|
return Promise.resolve(migratorOutput)
|
||||||
}
|
|
||||||
return Promise.resolve(result)
|
|
||||||
}).then(() => {
|
|
||||||
|
|
||||||
// Persist all these newly restored items to disk:
|
|
||||||
return this.keyringController.persistAllKeyrings()
|
|
||||||
|
|
||||||
// Ultimately pass the password back for normal unlocking:
|
|
||||||
}).then((result) => password)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IMPORT LOST ACCOUNTS
|
// IMPORT LOST ACCOUNTS
|
||||||
|
Loading…
Reference in New Issue
Block a user