aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/scripts/controllers/address-book.js27
-rw-r--r--app/scripts/metamask-controller.js3
-rw-r--r--test/unit/address-book-controller.js26
3 files changed, 21 insertions, 35 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/metamask-controller.js b/app/scripts/metamask-controller.js
index 4dcec8ef7..06ee6c47a 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({
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 () {