aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-12-23 05:56:45 +0800
committerDan Finlay <dan@danfinlay.com>2016-12-23 05:56:45 +0800
commit9e54e3baa0799e5083a9f9152f128077a2ee0527 (patch)
tree8d5c9239ef91c60698d1d71862e2a2e9e94ce643 /app/scripts
parent291403c13f0c8f61f29585cc9a80ed618718f60f (diff)
downloadtangerine-wallet-browser-9e54e3baa0799e5083a9f9152f128077a2ee0527.tar
tangerine-wallet-browser-9e54e3baa0799e5083a9f9152f128077a2ee0527.tar.gz
tangerine-wallet-browser-9e54e3baa0799e5083a9f9152f128077a2ee0527.tar.bz2
tangerine-wallet-browser-9e54e3baa0799e5083a9f9152f128077a2ee0527.tar.lz
tangerine-wallet-browser-9e54e3baa0799e5083a9f9152f128077a2ee0527.tar.xz
tangerine-wallet-browser-9e54e3baa0799e5083a9f9152f128077a2ee0527.tar.zst
tangerine-wallet-browser-9e54e3baa0799e5083a9f9152f128077a2ee0527.zip
Break up migration function
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/metamask-controller.js48
1 files changed, 24 insertions, 24 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index ab4cb8ed8..983a590d7 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -442,37 +442,37 @@ module.exports = class MetamaskController {
// with the provided password, so the other unlock steps
// may be completed without interruption.
migrateOldVaultIfAny (password) {
- const shouldMigrate = !!this.configManager.getWallet() && !this.configManager.getVault()
- if (!shouldMigrate) {
+
+ if (!this.checkIfShouldMigrate()) {
return Promise.resolve(password)
}
- return this.idStoreMigrator.migratedVaultForPassword(password)
- .then((result) => {
-
- this.keyringController.password = password
- const { serialized } = result
-
- // Restore the correct accounts first:
- return this.keyringController.restoreKeyring(serialized)
- .then(() => result)
+ const keyringController = this.keyringController
- }).then((result) => {
+ return this.idStoreMigrator.migratedVaultForPassword(password)
+ .then(this.restoreOldVaultAccounts.bind(this))
+ .then(this.restoreOldLostAccounts.bind(this))
+ .then(keyringController.persistAllKeyrings.bind(keyringController))
+ .then(() => password)
+ }
- // Now we restore any lost accounts:
- const { lostAccounts } = result
- if (result && lostAccounts) {
- this.configManager.setLostAccounts(lostAccounts.map((acct) => acct.address))
- return this.importLostAccounts(result)
- }
- return Promise.resolve(result)
- }).then(() => {
+ checkIfShouldMigrate() {
+ return !!this.configManager.getWallet() && !this.configManager.getVault()
+ }
- // Persist all these newly restored items to disk:
- return this.keyringController.persistAllKeyrings()
+ restoreOldVaultAccounts(migratorOutput) {
+ const { serialized } = migratorOutput
+ return this.keyringController.restoreKeyring(serialized)
+ .then(() => migratorOutput)
+ }
- // Ultimately pass the password back for normal unlocking:
- }).then((result) => password)
+ restoreOldLostAccounts(migratorOutput) {
+ const { lostAccounts } = migratorOutput
+ if (lostAccounts) {
+ this.configManager.setLostAccounts(lostAccounts.map(acct => acct.address))
+ return this.importLostAccounts(migratorOutput)
+ }
+ return Promise.resolve(migratorOutput)
}
// IMPORT LOST ACCOUNTS