aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2017-03-11 02:34:46 +0800
committerKevin Serrano <kevgagser@gmail.com>2017-03-11 02:34:46 +0800
commit7dcab52a9e6aa0532a712cb4e502846a383efc94 (patch)
tree081263abd43898ea0fb29a6e86d29d2b011b11fc /app
parentc47f7f6a765e748c33ffde6ff38e881199251eda (diff)
downloadtangerine-wallet-browser-7dcab52a9e6aa0532a712cb4e502846a383efc94.tar
tangerine-wallet-browser-7dcab52a9e6aa0532a712cb4e502846a383efc94.tar.gz
tangerine-wallet-browser-7dcab52a9e6aa0532a712cb4e502846a383efc94.tar.bz2
tangerine-wallet-browser-7dcab52a9e6aa0532a712cb4e502846a383efc94.tar.lz
tangerine-wallet-browser-7dcab52a9e6aa0532a712cb4e502846a383efc94.tar.xz
tangerine-wallet-browser-7dcab52a9e6aa0532a712cb4e502846a383efc94.tar.zst
tangerine-wallet-browser-7dcab52a9e6aa0532a712cb4e502846a383efc94.zip
Connect keyring controller to address book to prevent additional duplicates.
Diffstat (limited to 'app')
-rw-r--r--app/scripts/controllers/address-book.js22
-rw-r--r--app/scripts/metamask-controller.js10
2 files changed, 23 insertions, 9 deletions
diff --git a/app/scripts/controllers/address-book.js b/app/scripts/controllers/address-book.js
index 914fbded2..0e97cc477 100644
--- a/app/scripts/controllers/address-book.js
+++ b/app/scripts/controllers/address-book.js
@@ -7,11 +7,12 @@ class AddressBookController {
// Controller in charge of managing the address book functionality from the
// recipients field on the send screen. Manages a history of all saved
// addresses and all currently owned addresses.
- constructor (opts = {}) {
+ constructor (opts = {}, keyringController) {
const initState = extend({
addressBook: [],
}, opts.initState)
this.store = new ObservableStore(initState)
+ this.keyringController = keyringController
}
//
@@ -39,9 +40,16 @@ class AddressBookController {
// upper limit to the number of addresses.
_addToAddressBook (address, name) {
let addressBook = this._getAddressBook()
- let index = addressBook.findIndex((element) => { return element.address.toLowerCase() === address.toLowerCase() || element.name === name })
- if (index !== -1) {
- addressBook.splice(index, 1)
+ let identities = this._getIdentities()
+
+ let addressBookIndex = addressBook.findIndex((element) => { return element.address.toLowerCase() === address.toLowerCase() || element.name === name })
+ let identitiesIndex = Object.keys(identities).findIndex((element) => { return element.toLowerCase() === address.toLowerCase() })
+ // trigger this condition if we own this address--no need to overwrite.
+ if (identitiesIndex !== -1) {
+ return Promise.resolve(addressBook)
+ // trigger this condition if we've seen this address before--may need to update nickname.
+ } else if (addressBookIndex !== -1) {
+ addressBook.splice(addressBookIndex, 1)
}
addressBook.push({
address: address,
@@ -56,6 +64,12 @@ class AddressBookController {
return this.store.getState().addressBook
}
+ // Retrieves identities from the keyring controller in order to avoid
+ // duplication
+ _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 45905db72..1fcee61da 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -51,11 +51,6 @@ module.exports = class MetamaskController extends EventEmitter {
initState: initState.PreferencesController,
})
- // address book controller
- this.addressBookController = new AddressBookController({
- initState: initState.AddressBookController,
- })
-
// currency controller
this.currencyController = new CurrencyController({
initState: initState.CurrencyController,
@@ -86,6 +81,11 @@ module.exports = class MetamaskController extends EventEmitter {
autoFaucet(address)
})
+ // address book controller
+ this.addressBookController = new AddressBookController({
+ initState: initState.AddressBookController,
+ }, this.keyringController)
+
// tx mgmt
this.txManager = new TxManager({
initState: initState.TransactionManager,