diff options
author | kumavis <kumavis@users.noreply.github.com> | 2018-05-22 04:44:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-22 04:44:07 +0800 |
commit | 08d95bbafa3f952b960124c36958edbafa57cb3d (patch) | |
tree | 7935b16f4a926895b2d0efee6589fd48e8780c31 | |
parent | b426b5e58cc136c429ebb7659f414155139f5020 (diff) | |
parent | 67310e151ea75c7aa4fc00bfd63bf41cd4f2db51 (diff) | |
download | tangerine-wallet-browser-08d95bbafa3f952b960124c36958edbafa57cb3d.tar tangerine-wallet-browser-08d95bbafa3f952b960124c36958edbafa57cb3d.tar.gz tangerine-wallet-browser-08d95bbafa3f952b960124c36958edbafa57cb3d.tar.bz2 tangerine-wallet-browser-08d95bbafa3f952b960124c36958edbafa57cb3d.tar.lz tangerine-wallet-browser-08d95bbafa3f952b960124c36958edbafa57cb3d.tar.xz tangerine-wallet-browser-08d95bbafa3f952b960124c36958edbafa57cb3d.tar.zst tangerine-wallet-browser-08d95bbafa3f952b960124c36958edbafa57cb3d.zip |
Merge pull request #4034 from whymarrh/account-nicknames
Move account names out of KeyringController
22 files changed, 332 insertions, 114 deletions
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 diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 1d3308d36..a4ff1207e 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) } @@ -62,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 * @@ -156,6 +167,21 @@ class PreferencesController { } /** + * 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<string>} + */ + 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. * * @param {string} _url The the new rpc url to add to the updated list @@ -189,8 +215,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<array>} The updated frequentRpcList. + * @param {string} _url The rpc url to add to the frequentRpcList. + * @returns {Promise<array>} The updated frequentRpcList. * */ addToFrequentRpcList (_url) { diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index a6b5d3453..807c9a0b9 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -144,7 +144,8 @@ module.exports = class MetamaskController extends EventEmitter { // address book controller this.addressBookController = new AddressBookController({ initState: initState.AddressBookController, - }, this.keyringController) + preferencesStore: this.preferencesController.store, + }) // tx mgmt this.txController = new TransactionController({ @@ -363,6 +364,7 @@ module.exports = class MetamaskController extends EventEmitter { addToken: nodeify(preferencesController.addToken, preferencesController), removeToken: nodeify(preferencesController.removeToken, preferencesController), setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab, preferencesController), + setAccountLabel: nodeify(preferencesController.setAccountLabel, preferencesController), setFeatureFlag: nodeify(preferencesController.setFeatureFlag, preferencesController), // AddressController @@ -373,7 +375,6 @@ module.exports = class MetamaskController extends EventEmitter { createNewVaultAndKeychain: nodeify(this.createNewVaultAndKeychain, this), createNewVaultAndRestore: nodeify(this.createNewVaultAndRestore, this), addNewKeyring: nodeify(keyringController.addNewKeyring, keyringController), - saveAccountLabel: nodeify(keyringController.saveAccountLabel, keyringController), exportAccount: nodeify(keyringController.exportAccount, keyringController), // txController @@ -433,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) { @@ -453,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) { @@ -471,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) } @@ -502,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} } /** diff --git a/app/scripts/migrations/026.js b/app/scripts/migrations/026.js new file mode 100644 index 000000000..1b8a91a45 --- /dev/null +++ b/app/scripts/migrations/026.js @@ -0,0 +1,47 @@ +const version = 26 + +/* + +This migration moves the identities stored in the KeyringController + into the PreferencesController + +*/ + +const clone = require('clone') + +module.exports = { + version, + migrate (originalVersionedData) { + const versionedData = clone(originalVersionedData) + versionedData.meta.version = version + try { + const state = versionedData.data + versionedData.data = transformState(state) + } catch (err) { + console.warn(`MetaMask Migration #${version}` + err.stack) + return Promise.reject(err) + } + return Promise.resolve(versionedData) + }, +} + +function transformState (state) { + if (!state.KeyringController || !state.PreferencesController) { + return + } + + if (!state.KeyringController.walletNicknames) { + return state + } + + state.PreferencesController.identities = Object.keys(state.KeyringController.walletNicknames) + .reduce((identities, address) => { + identities[address] = { + name: state.KeyringController.walletNicknames[address], + address, + } + return identities + }, {}) + delete state.KeyringController.walletNicknames + return state +} diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js index 6c4a51b32..04d90bfff 100644 --- a/app/scripts/migrations/index.js +++ b/app/scripts/migrations/index.js @@ -36,4 +36,5 @@ module.exports = [ require('./023'), require('./024'), require('./025'), + require('./026'), ] diff --git a/old-ui/app/account-detail.js b/old-ui/app/account-detail.js index 692d50491..c67f0cf71 100644 --- a/old-ui/app/account-detail.js +++ b/old-ui/app/account-detail.js @@ -91,7 +91,7 @@ AccountDetailScreen.prototype.render = function () { isEditingLabel: false, }, saveText: (text) => { - props.dispatch(actions.saveAccountLabel(selected, text)) + props.dispatch(actions.setAccountLabel(selected, text)) }, }, [ diff --git a/package-lock.json b/package-lock.json index 1df46989c..c0cf49d0a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8054,9 +8054,9 @@ } }, "eth-keyring-controller": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/eth-keyring-controller/-/eth-keyring-controller-2.2.0.tgz", - "integrity": "sha512-f/g1ZrxciWJs2aHgpfvYmZ3ImP48GA+pobTU0EFNF/y5Yylf1zQyDw671W5opGpIt5TgV4F9sYXcvyjlgbL0Pg==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/eth-keyring-controller/-/eth-keyring-controller-3.1.1.tgz", + "integrity": "sha512-Z9HTzrop/V4Ld8Wq7uwetKecfWIyx25/uL8aFoZxV3kegZGoXaWoRmNy+4oW0WNLp4BcJ1lk6QfsGEdlymGjmA==", "requires": { "bip39": "2.4.0", "bluebird": "3.5.1", @@ -8064,7 +8064,7 @@ "eth-hd-keyring": "1.2.2", "eth-sig-util": "1.4.2", "eth-simple-keyring": "1.2.1", - "ethereumjs-util": "5.1.5", + "ethereumjs-util": "5.2.0", "loglevel": "1.6.0", "obs-store": "2.4.1", "promise-filter": "1.1.0" @@ -8080,9 +8080,9 @@ } }, "ethereumjs-util": { - "version": "5.1.5", - "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.1.5.tgz", - "integrity": "sha512-xPaSEATYJpMTCGowIt0oMZwFP4R1bxd6QsWgkcDvFL0JtXsr39p32WEcD14RscCjfP41YXZPCVWA4yAg0nrJmw==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.0.tgz", + "integrity": "sha512-CJAKdI0wgMbQFLlLRtZKGcy/L6pzVRgelIZqRqNbuVFM3K9VEnyfbcvz0ncWMRNCe4kaHWjwRYQcYMucmwsnWA==", "requires": { "bn.js": "4.11.8", "create-hash": "1.1.3", @@ -8176,16 +8176,16 @@ "integrity": "sha1-bXs1LcWppQINYfafryHvsvY2P0U=", "requires": { "eth-sig-util": "1.4.2", - "ethereumjs-util": "5.1.5", + "ethereumjs-util": "5.2.0", "ethereumjs-wallet": "0.6.0", "events": "1.1.1", "xtend": "4.0.1" }, "dependencies": { "ethereumjs-util": { - "version": "5.1.5", - "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.1.5.tgz", - "integrity": "sha512-xPaSEATYJpMTCGowIt0oMZwFP4R1bxd6QsWgkcDvFL0JtXsr39p32WEcD14RscCjfP41YXZPCVWA4yAg0nrJmw==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.0.tgz", + "integrity": "sha512-CJAKdI0wgMbQFLlLRtZKGcy/L6pzVRgelIZqRqNbuVFM3K9VEnyfbcvz0ncWMRNCe4kaHWjwRYQcYMucmwsnWA==", "requires": { "bn.js": "4.11.8", "create-hash": "1.1.3", diff --git a/package.json b/package.json index c31e8dbb1..011230f7d 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,7 @@ "eth-hd-keyring": "^1.2.1", "eth-json-rpc-filters": "^1.2.6", "eth-json-rpc-infura": "^3.0.0", - "eth-keyring-controller": "^2.2.0", + "eth-keyring-controller": "^3.1.1", "eth-phishing-detect": "^1.1.4", "eth-query": "^2.1.2", "eth-sig-util": "^1.4.2", diff --git a/test/unit/actions/save_account_label_test.js b/test/unit/actions/save_account_label_test.js deleted file mode 100644 index c5ffd6cbf..000000000 --- a/test/unit/actions/save_account_label_test.js +++ /dev/null @@ -1,35 +0,0 @@ -// var jsdom = require('mocha-jsdom') -var assert = require('assert') -var freeze = require('deep-freeze-strict') -var path = require('path') - -var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js')) -var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js')) - -describe('SAVE_ACCOUNT_LABEL', function () { - it('updates the state.metamask.identities[:i].name property of the state to the action.value.label', function () { - var initialState = { - metamask: { - identities: { - foo: { - name: 'bar', - }, - }, - }, - } - freeze(initialState) - - const action = { - type: actions.SAVE_ACCOUNT_LABEL, - value: { - account: 'foo', - label: 'baz', - }, - } - freeze(action) - - var resultingState = reducers(initialState, action) - assert.equal(resultingState.metamask.identities.foo.name, action.value.label) - }) -}) - diff --git a/test/unit/actions/set_account_label_test.js b/test/unit/actions/set_account_label_test.js new file mode 100644 index 000000000..53ea1d130 --- /dev/null +++ b/test/unit/actions/set_account_label_test.js @@ -0,0 +1,34 @@ +const assert = require('assert') +const freeze = require('deep-freeze-strict') +const path = require('path') + +const actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js')) +const reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js')) + +describe('SET_ACCOUNT_LABEL', function () { + it('updates the state.metamask.identities[:i].name property of the state to the action.value.label', function () { + const initialState = { + metamask: { + identities: { + foo: { + name: 'bar', + }, + }, + }, + } + freeze(initialState) + + const action = { + type: actions.SET_ACCOUNT_LABEL, + value: { + account: 'foo', + label: 'baz', + }, + } + freeze(action) + + const resultingState = reducers(initialState, action) + assert.equal(resultingState.metamask.identities.foo.name, action.value.label) + }) +}) + diff --git a/test/unit/address-book-controller.js b/test/unit/address-book-controller.js index 655c9022c..e48e69d98 100644 --- a/test/unit/address-book-controller.js +++ b/test/unit/address-book-controller.js @@ -1,26 +1,26 @@ const assert = require('assert') const AddressBookController = require('../../app/scripts/controllers/address-book') -const mockKeyringController = { - memStore: { - getState: function () { - return { - identities: { - '0x0aaa': { - address: '0x0aaa', - name: 'owned', - }, +const stubPreferencesStore = { + getState: function () { + return { + identities: { + '0x0aaa': { + address: '0x0aaa', + name: 'owned', }, - } - }, + }, + } }, -} +}; describe('address-book-controller', function () { var addressBookController beforeEach(function () { - addressBookController = new AddressBookController({}, mockKeyringController) + addressBookController = new AddressBookController({ + preferencesStore: stubPreferencesStore, + }) }) describe('addres book management', function () { diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index 18c3f9ab9..649b26e1e 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -106,7 +106,7 @@ describe('MetaMaskController', function () { [TEST_ADDRESS]: { address: TEST_ADDRESS, name: DEFAULT_LABEL }, }) - await metamaskController.keyringController.saveAccountLabel(TEST_ADDRESS, 'Account Foo') + await metamaskController.preferencesController.setAccountLabel(TEST_ADDRESS, 'Account Foo') assert.deepEqual(metamaskController.getState().identities, { [TEST_ADDRESS]: { address: TEST_ADDRESS, name: 'Account Foo' }, }) diff --git a/test/unit/migrations/026-test.js b/test/unit/migrations/026-test.js new file mode 100644 index 000000000..b3f5470cf --- /dev/null +++ b/test/unit/migrations/026-test.js @@ -0,0 +1,41 @@ +const assert = require('assert') +const migration26 = require('../../../app/scripts/migrations/026') +const oldStorage = { + 'meta': {'version': 25}, + 'data': { + 'PreferencesController': {}, + 'KeyringController': { + 'walletNicknames': { + '0x1e77e2': 'Test Account 1', + '0x7e57e2': 'Test Account 2', + }, + }, + }, +} + +describe('migration #26', () => { + it('should move the identities from KeyringController', (done) => { + migration26.migrate(oldStorage) + .then((newStorage) => { + const identities = newStorage.data.PreferencesController.identities + assert.deepEqual(identities, { + '0x1e77e2': {name: 'Test Account 1', address: '0x1e77e2'}, + '0x7e57e2': {name: 'Test Account 2', address: '0x7e57e2'}, + }) + assert.strictEqual(newStorage.data.KeyringController.walletNicknames, undefined) + done() + }) + .catch(done) + }) + + it('should successfully migrate first time state', (done) => { + migration26.migrate({ + meta: {}, + data: require('../../../app/scripts/first-time-state'), + }) + .then((migratedData) => { + assert.equal(migratedData.meta.version, migration26.version) + done() + }).catch(done) + }) +}) diff --git a/test/unit/preferences-controller-test.js b/test/unit/preferences-controller-test.js index 9fb5e4251..c613c68f9 100644 --- a/test/unit/preferences-controller-test.js +++ b/test/unit/preferences-controller-test.js @@ -4,16 +4,91 @@ const PreferencesController = require('../../app/scripts/controllers/preferences describe('preferences controller', function () { let preferencesController - before(() => { + beforeEach(() => { preferencesController = new PreferencesController() }) + describe('setAddresses', function () { + it('should keep a map of addresses to names and addresses in the store', function () { + preferencesController.setAddresses([ + '0xda22le', + '0x7e57e2', + ]) + + const {identities} = preferencesController.store.getState() + assert.deepEqual(identities, { + '0xda22le': { + name: 'Account 1', + address: '0xda22le', + }, + '0x7e57e2': { + name: 'Account 2', + address: '0x7e57e2', + }, + }) + }) + + it('should replace its list of addresses', function () { + preferencesController.setAddresses([ + '0xda22le', + '0x7e57e2', + ]) + preferencesController.setAddresses([ + '0xda22le77', + '0x7e57e277', + ]) + + const {identities} = preferencesController.store.getState() + assert.deepEqual(identities, { + '0xda22le77': { + name: 'Account 1', + address: '0xda22le77', + }, + '0x7e57e277': { + name: 'Account 2', + address: '0x7e57e277', + }, + }) + }) + }) + + describe('setAccountLabel', function () { + it('should update a label for the given account', function () { + preferencesController.setAddresses([ + '0xda22le', + '0x7e57e2', + ]) + + assert.deepEqual(preferencesController.store.getState().identities['0xda22le'], { + name: 'Account 1', + address: '0xda22le', + }) + + + preferencesController.setAccountLabel('0xda22le', 'Dazzle') + assert.deepEqual(preferencesController.store.getState().identities['0xda22le'], { + name: 'Dazzle', + address: '0xda22le', + }) + }) + }) + + describe('getTokens', function () { + it('should return an empty list initially', async function () { + await preferencesController.setSelectedAddress('0x7e57e2') + + const tokens = preferencesController.getTokens() + assert.equal(tokens.length, 0, 'empty list of tokens') + }) + }) + describe('addToken', function () { it('should add that token to its state', async function () { const address = '0xabcdef1234567' const symbol = 'ABBR' const decimals = 5 + await preferencesController.setSelectedAddress('0x7e57e2') await preferencesController.addToken(address, symbol, decimals) const tokens = preferencesController.getTokens() @@ -30,6 +105,7 @@ describe('preferences controller', function () { const symbol = 'ABBR' const decimals = 5 + await preferencesController.setSelectedAddress('0x7e57e2') await preferencesController.addToken(address, symbol, decimals) const newDecimals = 6 @@ -43,6 +119,44 @@ describe('preferences controller', function () { assert.equal(added.symbol, symbol, 'set symbol correctly') assert.equal(added.decimals, newDecimals, 'updated decimals correctly') }) + + it('should allow adding tokens to two separate addresses', async function () { + const address = '0xabcdef1234567' + const symbol = 'ABBR' + const decimals = 5 + + await preferencesController.setSelectedAddress('0x7e57e2') + await preferencesController.addToken(address, symbol, decimals) + assert.equal(preferencesController.getTokens().length, 1, 'one token added for 1st address') + + await preferencesController.setSelectedAddress('0xda22le') + await preferencesController.addToken(address, symbol, decimals) + assert.equal(preferencesController.getTokens().length, 1, 'one token added for 2nd address') + }) + }) + + describe('removeToken', function () { + it('should remove the only token from its state', async function () { + await preferencesController.setSelectedAddress('0x7e57e2') + await preferencesController.addToken('0xa', 'A', 5) + await preferencesController.removeToken('0xa') + + const tokens = preferencesController.getTokens() + assert.equal(tokens.length, 0, 'one token removed') + }) + + it('should remove a token from its state', async function () { + await preferencesController.setSelectedAddress('0x7e57e2') + await preferencesController.addToken('0xa', 'A', 4) + await preferencesController.addToken('0xb', 'B', 5) + await preferencesController.removeToken('0xa') + + const tokens = preferencesController.getTokens() + assert.equal(tokens.length, 1, 'one token removed') + + const [token1] = tokens + assert.deepEqual(token1, {address: '0xb', symbol: 'B', decimals: 5}) + }) }) }) diff --git a/ui/app/accounts/new-account/index.js b/ui/app/accounts/new-account/index.js index 207cf7760..795bd7ce6 100644 --- a/ui/app/accounts/new-account/index.js +++ b/ui/app/accounts/new-account/index.js @@ -24,7 +24,7 @@ function mapDispatchToProps (dispatch) { dispatch(actions.showModal({ name: 'EXPORT_PRIVATE_KEY' })) }, hideModal: () => dispatch(actions.hideModal()), - saveAccountLabel: (address, label) => dispatch(actions.saveAccountLabel(address, label)), + setAccountLabel: (address, label) => dispatch(actions.setAccountLabel(address, label)), } } diff --git a/ui/app/actions.js b/ui/app/actions.js index 2d238b2f8..57bffb046 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -124,8 +124,8 @@ var actions = { SHOW_PRIVATE_KEY: 'SHOW_PRIVATE_KEY', showPrivateKey: showPrivateKey, exportAccountComplete, - SAVE_ACCOUNT_LABEL: 'SAVE_ACCOUNT_LABEL', - saveAccountLabel: saveAccountLabel, + SET_ACCOUNT_LABEL: 'SET_ACCOUNT_LABEL', + setAccountLabel, // tx conf screen COMPLETED_TX: 'COMPLETED_TX', TRANSACTION_ERROR: 'TRANSACTION_ERROR', @@ -1598,13 +1598,13 @@ function showPrivateKey (key) { } } -function saveAccountLabel (account, label) { +function setAccountLabel (account, label) { return (dispatch) => { dispatch(actions.showLoadingIndication()) - log.debug(`background.saveAccountLabel`) + log.debug(`background.setAccountLabel`) return new Promise((resolve, reject) => { - background.saveAccountLabel(account, label, (err) => { + background.setAccountLabel(account, label, (err) => { dispatch(actions.hideLoadingIndication()) if (err) { @@ -1613,7 +1613,7 @@ function saveAccountLabel (account, label) { } dispatch({ - type: actions.SAVE_ACCOUNT_LABEL, + type: actions.SET_ACCOUNT_LABEL, value: { account, label }, }) diff --git a/ui/app/components/modals/account-details-modal.js b/ui/app/components/modals/account-details-modal.js index d9885daf5..5607cf051 100644 --- a/ui/app/components/modals/account-details-modal.js +++ b/ui/app/components/modals/account-details-modal.js @@ -25,7 +25,7 @@ function mapDispatchToProps (dispatch) { dispatch(actions.showModal({ name: 'EXPORT_PRIVATE_KEY' })) }, hideModal: () => dispatch(actions.hideModal()), - saveAccountLabel: (address, label) => dispatch(actions.saveAccountLabel(address, label)), + setAccountLabel: (address, label) => dispatch(actions.setAccountLabel(address, label)), } } @@ -49,7 +49,7 @@ AccountDetailsModal.prototype.render = function () { selectedIdentity, network, showExportPrivateKeyModal, - saveAccountLabel, + setAccountLabel, } = this.props const { name, address } = selectedIdentity @@ -57,7 +57,7 @@ AccountDetailsModal.prototype.render = function () { h(EditableLabel, { className: 'account-modal__name', defaultValue: name, - onSubmit: label => saveAccountLabel(address, label), + onSubmit: label => setAccountLabel(address, label), }), h(QrView, { diff --git a/ui/app/components/modals/edit-account-name-modal.js b/ui/app/components/modals/edit-account-name-modal.js index c79645dbf..5681a3cad 100644 --- a/ui/app/components/modals/edit-account-name-modal.js +++ b/ui/app/components/modals/edit-account-name-modal.js @@ -18,8 +18,8 @@ function mapDispatchToProps (dispatch) { hideModal: () => { dispatch(actions.hideModal()) }, - saveAccountLabel: (account, label) => { - dispatch(actions.saveAccountLabel(account, label)) + setAccountLabel: (account, label) => { + dispatch(actions.setAccountLabel(account, label)) }, } } @@ -41,7 +41,7 @@ module.exports = connect(mapStateToProps, mapDispatchToProps)(EditAccountNameMod EditAccountNameModal.prototype.render = function () { - const { hideModal, saveAccountLabel, identity } = this.props + const { hideModal, setAccountLabel, identity } = this.props return h('div', {}, [ h('div.flex-column.edit-account-name-modal-content', { @@ -69,7 +69,7 @@ EditAccountNameModal.prototype.render = function () { h('button.btn-clear.edit-account-name-modal-save-button.allcaps', { onClick: () => { if (this.state.inputText.length !== 0) { - saveAccountLabel(identity.address, this.state.inputText) + setAccountLabel(identity.address, this.state.inputText) hideModal() } }, diff --git a/ui/app/components/modals/new-account-modal.js b/ui/app/components/modals/new-account-modal.js index 0635b3f72..a66a3ed4a 100644 --- a/ui/app/components/modals/new-account-modal.js +++ b/ui/app/components/modals/new-account-modal.js @@ -95,7 +95,7 @@ const mapDispatchToProps = dispatch => { dispatch(actions.addNewAccount()) .then((newAccountAddress) => { if (newAccountName) { - dispatch(actions.saveAccountLabel(newAccountAddress, newAccountName)) + dispatch(actions.setAccountLabel(newAccountAddress, newAccountName)) } dispatch(actions.hideModal()) }) diff --git a/ui/app/components/pages/create-account/index.js b/ui/app/components/pages/create-account/index.js index 0962477d8..475261253 100644 --- a/ui/app/components/pages/create-account/index.js +++ b/ui/app/components/pages/create-account/index.js @@ -75,7 +75,7 @@ const mapDispatchToProps = dispatch => ({ dispatch(actions.showModal({ name: 'EXPORT_PRIVATE_KEY' })) }, hideModal: () => dispatch(actions.hideModal()), - saveAccountLabel: (address, label) => dispatch(actions.saveAccountLabel(address, label)), + setAccountLabel: (address, label) => dispatch(actions.setAccountLabel(address, label)), }) module.exports = connect(mapStateToProps, mapDispatchToProps)(CreateAccountPage) diff --git a/ui/app/components/pages/create-account/new-account.js b/ui/app/components/pages/create-account/new-account.js index 40fa584be..03a5ee72d 100644 --- a/ui/app/components/pages/create-account/new-account.js +++ b/ui/app/components/pages/create-account/new-account.js @@ -87,7 +87,7 @@ const mapDispatchToProps = dispatch => { return dispatch(actions.addNewAccount()) .then(newAccountAddress => { if (newAccountName) { - dispatch(actions.saveAccountLabel(newAccountAddress, newAccountName)) + dispatch(actions.setAccountLabel(newAccountAddress, newAccountName)) } }) }, diff --git a/ui/app/reducers/metamask.js b/ui/app/reducers/metamask.js index bb35cf990..9afaf6a50 100644 --- a/ui/app/reducers/metamask.js +++ b/ui/app/reducers/metamask.js @@ -163,7 +163,7 @@ function reduceMetamask (state, action) { selectedTokenAddress: action.value, }) - case actions.SAVE_ACCOUNT_LABEL: + case actions.SET_ACCOUNT_LABEL: const account = action.value.account const name = action.value.label const id = {} |