mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Update AddressBookController to read from preferences store
This commit is contained in:
parent
924cc1fcf7
commit
cbe4d0d88c
@ -13,19 +13,17 @@ class AddressBookController {
|
|||||||
* @param {object} opts Overrides the defaults for the initial state of this.store
|
* @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
|
* @property {array} opts.initState initializes the the state of the AddressBookController. Can contain an
|
||||||
* addressBook property to initialize the addressBook array
|
* addressBook property to initialize the addressBook array
|
||||||
* @param {KeyringController} keyringController (Soon to be deprecated) The keyringController used in the current
|
* @property {object} opts.preferencesStore the {@code PreferencesController} store
|
||||||
* MetamaskController. Contains the identities used in this AddressBookController.
|
|
||||||
* @property {object} store The the store of the current users address book
|
* @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
|
* @property {array} store.addressBook An array of addresses and nicknames. These are set by the user when sending
|
||||||
* to a new address.
|
* to a new address.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
constructor (opts = {}, keyringController) {
|
constructor ({initState, preferencesStore}) {
|
||||||
const initState = extend({
|
this.store = new ObservableStore(extend({
|
||||||
addressBook: [],
|
addressBook: [],
|
||||||
}, opts.initState)
|
}, initState))
|
||||||
this.store = new ObservableStore(initState)
|
this._preferencesStore = preferencesStore
|
||||||
this.keyringController = keyringController
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -62,7 +60,7 @@ class AddressBookController {
|
|||||||
*/
|
*/
|
||||||
_addToAddressBook (address, name) {
|
_addToAddressBook (address, name) {
|
||||||
const addressBook = this._getAddressBook()
|
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 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() })
|
const identitiesIndex = Object.keys(identities).findIndex((element) => { return element.toLowerCase() === address.toLowerCase() })
|
||||||
@ -95,19 +93,6 @@ class AddressBookController {
|
|||||||
_getAddressBook () {
|
_getAddressBook () {
|
||||||
return this.store.getState().addressBook
|
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
|
module.exports = AddressBookController
|
||||||
|
@ -144,7 +144,8 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
// address book controller
|
// address book controller
|
||||||
this.addressBookController = new AddressBookController({
|
this.addressBookController = new AddressBookController({
|
||||||
initState: initState.AddressBookController,
|
initState: initState.AddressBookController,
|
||||||
}, this.keyringController)
|
preferencesStore: this.preferencesController.store,
|
||||||
|
})
|
||||||
|
|
||||||
// tx mgmt
|
// tx mgmt
|
||||||
this.txController = new TransactionController({
|
this.txController = new TransactionController({
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const AddressBookController = require('../../app/scripts/controllers/address-book')
|
const AddressBookController = require('../../app/scripts/controllers/address-book')
|
||||||
|
|
||||||
const mockKeyringController = {
|
const stubPreferencesStore = {
|
||||||
memStore: {
|
getState: function () {
|
||||||
getState: function () {
|
return {
|
||||||
return {
|
identities: {
|
||||||
identities: {
|
'0x0aaa': {
|
||||||
'0x0aaa': {
|
address: '0x0aaa',
|
||||||
address: '0x0aaa',
|
name: 'owned',
|
||||||
name: 'owned',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
describe('address-book-controller', function () {
|
describe('address-book-controller', function () {
|
||||||
var addressBookController
|
var addressBookController
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
addressBookController = new AddressBookController({}, mockKeyringController)
|
addressBookController = new AddressBookController({
|
||||||
|
preferencesStore: stubPreferencesStore,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('addres book management', function () {
|
describe('addres book management', function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user