diff options
author | Whymarrh Whitby <whymarrh.whitby@gmail.com> | 2018-04-19 11:33:51 +0800 |
---|---|---|
committer | Whymarrh Whitby <whymarrh.whitby@gmail.com> | 2018-05-17 23:27:39 +0800 |
commit | c54e4c719110c2033b7cc3757676f97ad3329d42 (patch) | |
tree | ba596e96730a3b8b617278696df9068af0612d70 /app | |
parent | cbe4d0d88c83ee1d8dd8efde537ee753bf19596a (diff) | |
download | tangerine-wallet-browser-c54e4c719110c2033b7cc3757676f97ad3329d42.tar tangerine-wallet-browser-c54e4c719110c2033b7cc3757676f97ad3329d42.tar.gz tangerine-wallet-browser-c54e4c719110c2033b7cc3757676f97ad3329d42.tar.bz2 tangerine-wallet-browser-c54e4c719110c2033b7cc3757676f97ad3329d42.tar.lz tangerine-wallet-browser-c54e4c719110c2033b7cc3757676f97ad3329d42.tar.xz tangerine-wallet-browser-c54e4c719110c2033b7cc3757676f97ad3329d42.tar.zst tangerine-wallet-browser-c54e4c719110c2033b7cc3757676f97ad3329d42.zip |
Add PreferencesController#setAddresses to update ids
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/controllers/preferences.js | 10 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 20 |
2 files changed, 22 insertions, 8 deletions
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 55416d15f..a4ff1207e 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -63,6 +63,16 @@ class PreferencesController { this.store.updateState({ currentLocale: key }) } + setAddresses (addresses) { + const oldIdentities = this.store.getState().identities + const identities = addresses.reduce((ids, address, index) => { + const oldId = oldIdentities[address] || {} + ids[address] = {name: `Account ${index + 1}`, address, ...oldId} + return ids + }, {}) + this.store.updateState({ identities }) + } + /** * Setter for the `selectedAddress` property * diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 06ee6c47a..807c9a0b9 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -434,7 +434,9 @@ module.exports = class MetamaskController extends EventEmitter { } else { vault = await this.keyringController.createNewVaultAndKeychain(password) - this.selectFirstIdentity(vault) + const accounts = await this.keyringController.getAccounts() + this.preferencesController.setAddresses(accounts) + this.selectFirstIdentity() } release() } catch (err) { @@ -454,7 +456,9 @@ module.exports = class MetamaskController extends EventEmitter { const release = await this.createVaultMutex.acquire() try { const vault = await this.keyringController.createNewVaultAndRestore(password, seed) - this.selectFirstIdentity(vault) + const accounts = await this.keyringController.getAccounts() + this.preferencesController.setAddresses(accounts) + this.selectFirstIdentity() release() return vault } catch (err) { @@ -472,12 +476,10 @@ module.exports = class MetamaskController extends EventEmitter { */ /** - * Retrieves the first Identiy from the passed Vault and selects the related address - * - * @param {} vault + * Sets the first address in the state to the selected address */ - selectFirstIdentity (vault) { - const { identities } = vault + selectFirstIdentity () { + const { identities } = this.preferencesController.store.getState() const address = Object.keys(identities)[0] this.preferencesController.setSelectedAddress(address) } @@ -503,13 +505,15 @@ module.exports = class MetamaskController extends EventEmitter { await this.verifySeedPhrase() + this.preferencesController.setAddresses(newAccounts) newAccounts.forEach((address) => { if (!oldAccounts.includes(address)) { this.preferencesController.setSelectedAddress(address) } }) - return keyState + const {identities} = this.preferencesController.store.getState() + return {...keyState, identities} } /** |