diff options
author | Dan <danjm.com@gmail.com> | 2018-06-05 09:02:30 +0800 |
---|---|---|
committer | Dan <danjm.com@gmail.com> | 2018-06-05 09:02:30 +0800 |
commit | aee9247faab984734d2f0278baaf768e2a7926d2 (patch) | |
tree | 1805e6f28975c0002e8cbb15ef9920a96b90ec19 /app/scripts/metamask-controller.js | |
parent | 139f930185f134ef50d547ca07a580e11b5cf731 (diff) | |
parent | 3b6e96bac918925c4edc674e26dba8cc5feb1324 (diff) | |
download | tangerine-wallet-browser-aee9247faab984734d2f0278baaf768e2a7926d2.tar.gz tangerine-wallet-browser-aee9247faab984734d2f0278baaf768e2a7926d2.tar.zst tangerine-wallet-browser-aee9247faab984734d2f0278baaf768e2a7926d2.zip |
Merge branch 'develop' into i3725-refactor-send-component-
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r-- | app/scripts/metamask-controller.js | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 9db7e186a..80eaafd92 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -85,6 +85,7 @@ module.exports = class MetamaskController extends EventEmitter { this.preferencesController = new PreferencesController({ initState: initState.PreferencesController, initLangCode: opts.initLangCode, + getFirstTimeInfo: () => initState.firstTimeInfo, }) // currency controller @@ -139,6 +140,8 @@ module.exports = class MetamaskController extends EventEmitter { const address = addresses[0] this.preferencesController.setSelectedAddress(address) } + // ensure preferences + identities controller know about all addresses + this.preferencesController.addAddresses(addresses) this.accountTracker.syncWithAddresses(addresses) }) @@ -354,7 +357,7 @@ module.exports = class MetamaskController extends EventEmitter { importAccountWithStrategy: nodeify(this.importAccountWithStrategy, this), // vault management - submitPassword: nodeify(keyringController.submitPassword, keyringController), + submitPassword: nodeify(this.submitPassword, this), // network management setProviderType: nodeify(networkController.setProviderType, networkController), @@ -458,7 +461,11 @@ module.exports = class MetamaskController extends EventEmitter { async createNewVaultAndRestore (password, seed) { const release = await this.createVaultMutex.acquire() try { + // clear known identities + this.preferencesController.setAddresses([]) + // create new vault const vault = await this.keyringController.createNewVaultAndRestore(password, seed) + // set new identities const accounts = await this.keyringController.getAccounts() this.preferencesController.setAddresses(accounts) this.selectFirstIdentity() @@ -470,6 +477,22 @@ module.exports = class MetamaskController extends EventEmitter { } } + /* + * Submits the user's password and attempts to unlock the vault. + * Also synchronizes the preferencesController, to ensure its schema + * is up to date with known accounts once the vault is decrypted. + * + * @param {string} password - The user's password + * @returns {Promise<object>} - The keyringController update. + */ + async submitPassword (password) { + await this.keyringController.submitPassword(password) + const accounts = await this.keyringController.getAccounts() + + await this.preferencesController.syncAddresses(accounts) + return this.keyringController.fullUpdate() + } + /** * @type Identity * @property {string} name - The account nickname. |