aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers/address-book.js
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/scripts/controllers/address-book.js
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/scripts/controllers/address-book.js')
-rw-r--r--app/scripts/controllers/address-book.js22
1 files changed, 18 insertions, 4 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