From d4cdd1a0f304141a6ce6d5c817953f06080a6299 Mon Sep 17 00:00:00 2001 From: kumavis Date: Sun, 3 Jun 2018 11:27:25 -0700 Subject: [PATCH 1/3] metamask - update preferences controller identities on keyring controller update --- app/scripts/controllers/preferences.js | 31 +++++++++++++++++++++++--- app/scripts/metamask-controller.js | 2 ++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index a4ff1207e..38136e174 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -63,6 +63,13 @@ class PreferencesController { this.store.updateState({ currentLocale: key }) } + /** + * Updates identities to only include specified addresses. Removes identities + * not included in addresses array + * + * @param {arrays} addresses An array of hex addresses + * + */ setAddresses (addresses) { const oldIdentities = this.store.getState().identities const identities = addresses.reduce((ids, address, index) => { @@ -73,6 +80,24 @@ class PreferencesController { this.store.updateState({ identities }) } + /** + * Adds addresses to the identities object without removing identities + * + * @param {arrays} addresses An array of hex addresses + * + */ + addAddresses (addresses) { + const identities = this.store.getState().identities + addresses.forEach((address) => { + // skip if already exists + if (identities[address]) return + // add missing identity + const identityCount = Object.keys(identities).length + identities[address] = { name: `Account ${identityCount + 1}`, address } + }) + this.store.updateState({ identities }) + } + /** * Setter for the `selectedAddress` property * @@ -111,7 +136,7 @@ class PreferencesController { /** * Adds a new token to the token array, or updates the token if passed an address that already exists. * Modifies the existing tokens array from the store. All objects in the tokens array array AddedToken objects. - * @see AddedToken {@link AddedToken} + * @see AddedToken {@link AddedToken} * * @param {string} rawAddress Hex address of the token contract. May or may not be a checksum address. * @param {string} symbol The symbol of the token @@ -197,7 +222,7 @@ class PreferencesController { } /** - * Setter for the `currentAccountTab` property + * Setter for the `currentAccountTab` property * * @param {string} currentAccountTab Specifies the new tab to be marked as current * @returns {Promise} Promise resolves with undefined @@ -215,7 +240,7 @@ class PreferencesController { * The returned list will have a max length of 2. If the _url currently exists it the list, it will be moved to the * end of the list. The current list is modified and returned as a promise. * - * @param {string} _url The rpc url to add to the frequentRpcList. + * @param {string} _url The rpc url to add to the frequentRpcList. * @returns {Promise} The updated frequentRpcList. * */ diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index a570f2567..46f4a79a8 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -139,6 +139,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) }) From 54a9c62fd66a367ebca8ae963c080eb8eb9db0a7 Mon Sep 17 00:00:00 2001 From: kumavis Date: Sun, 3 Jun 2018 11:30:11 -0700 Subject: [PATCH 2/3] preferences controller - jsdoc fix --- app/scripts/controllers/preferences.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 38136e174..760868ddf 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -67,7 +67,7 @@ class PreferencesController { * Updates identities to only include specified addresses. Removes identities * not included in addresses array * - * @param {arrays} addresses An array of hex addresses + * @param {string[]} addresses An array of hex addresses * */ setAddresses (addresses) { @@ -83,7 +83,7 @@ class PreferencesController { /** * Adds addresses to the identities object without removing identities * - * @param {arrays} addresses An array of hex addresses + * @param {string[]} addresses An array of hex addresses * */ addAddresses (addresses) { From eb3241ccba8e08d694f6887cae56daabace9efe9 Mon Sep 17 00:00:00 2001 From: kumavis Date: Sun, 3 Jun 2018 12:02:35 -0700 Subject: [PATCH 3/3] metamask-controller - clear account labels on restore from seed phrase --- app/scripts/metamask-controller.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 46f4a79a8..96f976568 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -458,7 +458,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()