diff options
author | Dan <danjm.com@gmail.com> | 2018-06-05 20:26:36 +0800 |
---|---|---|
committer | Dan <danjm.com@gmail.com> | 2018-06-05 20:26:36 +0800 |
commit | 49f0df31742ed09d74ab9cc55d74f23152c19f20 (patch) | |
tree | b853d92a33b6e551cd79c64b3ad362a9f80b9fc3 /app/scripts/metamask-controller.js | |
parent | 8f0a3b83111a9ccf5d515cebbd33cabe9ab16ba7 (diff) | |
parent | 3b6e96bac918925c4edc674e26dba8cc5feb1324 (diff) | |
download | tangerine-wallet-browser-49f0df31742ed09d74ab9cc55d74f23152c19f20.tar.gz tangerine-wallet-browser-49f0df31742ed09d74ab9cc55d74f23152c19f20.tar.zst tangerine-wallet-browser-49f0df31742ed09d74ab9cc55d74f23152c19f20.zip |
Merge branch 'develop' into handle-import-account-failure-in-ui
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 a570f2567..c753fc06f 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), @@ -456,7 +459,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() @@ -468,6 +475,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. |