1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00

metamask-controller - update preferences controller addresses after import account

This commit is contained in:
kumavis 2018-05-28 22:58:14 -07:00
parent e2a9b9e2ae
commit fe42de4642

View File

@ -345,7 +345,7 @@ module.exports = class MetamaskController extends EventEmitter {
verifySeedPhrase: nodeify(this.verifySeedPhrase, this), verifySeedPhrase: nodeify(this.verifySeedPhrase, this),
clearSeedWordCache: this.clearSeedWordCache.bind(this), clearSeedWordCache: this.clearSeedWordCache.bind(this),
resetAccount: nodeify(this.resetAccount, this), resetAccount: nodeify(this.resetAccount, this),
importAccountWithStrategy: this.importAccountWithStrategy.bind(this), importAccountWithStrategy: nodeify(this.importAccountWithStrategy, this),
// vault management // vault management
submitPassword: nodeify(keyringController.submitPassword, keyringController), submitPassword: nodeify(keyringController.submitPassword, keyringController),
@ -603,15 +603,15 @@ module.exports = class MetamaskController extends EventEmitter {
* @param {any} args - The data required by that strategy to import an account. * @param {any} args - The data required by that strategy to import an account.
* @param {Function} cb - A callback function called with a state update on success. * @param {Function} cb - A callback function called with a state update on success.
*/ */
importAccountWithStrategy (strategy, args, cb) { async importAccountWithStrategy (strategy, args) {
accountImporter.importAccount(strategy, args) const privateKey = await accountImporter.importAccount(strategy, args)
.then((privateKey) => { const keyring = await this.keyringController.addNewKeyring('Simple Key Pair', [ privateKey ])
return this.keyringController.addNewKeyring('Simple Key Pair', [ privateKey ]) const accounts = await keyring.getAccounts()
}) // update accounts in preferences controller
.then(keyring => keyring.getAccounts()) const allAccounts = await keyringController.getAccounts()
.then((accounts) => this.preferencesController.setSelectedAddress(accounts[0])) this.preferencesController.setAddresses(allAccounts)
.then(() => { cb(null, this.keyringController.fullUpdate()) }) // set new account as selected
.catch((reason) => { cb(reason) }) await this.preferencesController.setSelectedAddress(accounts[0])
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------