From 924cc1fcf7de1896ac09bbe7a400d5ff5df0b50d Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Thu, 19 Apr 2018 01:03:51 -0230 Subject: Move setAccountLabel into PreferencesController --- app/scripts/controllers/preferences.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 1d3308d36..55416d15f 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -27,6 +27,7 @@ class PreferencesController { useBlockie: false, featureFlags: {}, currentLocale: opts.initLangCode, + identities: {}, }, opts.initState) this.store = new ObservableStore(initState) } @@ -155,6 +156,21 @@ class PreferencesController { return this.store.getState().tokens } + /** + * Sets a custom label for an account + * @param {string} account the account to set a label for + * @param {string} label the custom label for the account + * @return {Promise} + */ + setAccountLabel (account, label) { + const address = normalizeAddress(account) + const {identities} = this.store.getState() + identities[address] = identities[address] || {} + identities[address].name = label + this.store.updateState({ identities }) + return Promise.resolve(label) + } + /** * Gets an updated rpc list from this.addToFrequentRpcList() and sets the `frequentRpcList` to this update list. * @@ -189,8 +205,8 @@ 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. - * @returns {Promise} The updated frequentRpcList. + * @param {string} _url The rpc url to add to the frequentRpcList. + * @returns {Promise} The updated frequentRpcList. * */ addToFrequentRpcList (_url) { -- cgit From cbe4d0d88c83ee1d8dd8efde537ee753bf19596a Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Thu, 19 Apr 2018 01:03:51 -0230 Subject: Update AddressBookController to read from preferences store --- app/scripts/controllers/address-book.js | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/address-book.js b/app/scripts/controllers/address-book.js index c91e6b2e4..4697e074c 100644 --- a/app/scripts/controllers/address-book.js +++ b/app/scripts/controllers/address-book.js @@ -13,19 +13,17 @@ class AddressBookController { * @param {object} opts Overrides the defaults for the initial state of this.store * @property {array} opts.initState initializes the the state of the AddressBookController. Can contain an * addressBook property to initialize the addressBook array - * @param {KeyringController} keyringController (Soon to be deprecated) The keyringController used in the current - * MetamaskController. Contains the identities used in this AddressBookController. + * @property {object} opts.preferencesStore the {@code PreferencesController} store * @property {object} store The the store of the current users address book * @property {array} store.addressBook An array of addresses and nicknames. These are set by the user when sending * to a new address. * */ - constructor (opts = {}, keyringController) { - const initState = extend({ + constructor ({initState, preferencesStore}) { + this.store = new ObservableStore(extend({ addressBook: [], - }, opts.initState) - this.store = new ObservableStore(initState) - this.keyringController = keyringController + }, initState)) + this._preferencesStore = preferencesStore } // @@ -62,7 +60,7 @@ class AddressBookController { */ _addToAddressBook (address, name) { const addressBook = this._getAddressBook() - const identities = this._getIdentities() + const {identities} = this._preferencesStore.getState() const addressBookIndex = addressBook.findIndex((element) => { return element.address.toLowerCase() === address.toLowerCase() || element.name === name }) const identitiesIndex = Object.keys(identities).findIndex((element) => { return element.toLowerCase() === address.toLowerCase() }) @@ -95,19 +93,6 @@ class AddressBookController { _getAddressBook () { return this.store.getState().addressBook } - - /** - * Retrieves identities from the keyring controller in order to avoid - * duplication - * - * @deprecated - * @returns {array} Returns the identies array from the keyringContoller's state - * - */ - _getIdentities () { - return this.keyringController.memStore.getState().identities - } - } module.exports = AddressBookController -- cgit From c54e4c719110c2033b7cc3757676f97ad3329d42 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Thu, 19 Apr 2018 01:03:51 -0230 Subject: Add PreferencesController#setAddresses to update ids --- app/scripts/controllers/preferences.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'app/scripts/controllers') 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 * -- cgit