mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Connect keyring controller to address book to prevent additional duplicates.
This commit is contained in:
parent
c47f7f6a76
commit
7dcab52a9e
@ -7,11 +7,12 @@ class AddressBookController {
|
|||||||
// Controller in charge of managing the address book functionality from the
|
// Controller in charge of managing the address book functionality from the
|
||||||
// recipients field on the send screen. Manages a history of all saved
|
// recipients field on the send screen. Manages a history of all saved
|
||||||
// addresses and all currently owned addresses.
|
// addresses and all currently owned addresses.
|
||||||
constructor (opts = {}) {
|
constructor (opts = {}, keyringController) {
|
||||||
const initState = extend({
|
const initState = extend({
|
||||||
addressBook: [],
|
addressBook: [],
|
||||||
}, opts.initState)
|
}, opts.initState)
|
||||||
this.store = new ObservableStore(initState)
|
this.store = new ObservableStore(initState)
|
||||||
|
this.keyringController = keyringController
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -39,9 +40,16 @@ class AddressBookController {
|
|||||||
// upper limit to the number of addresses.
|
// upper limit to the number of addresses.
|
||||||
_addToAddressBook (address, name) {
|
_addToAddressBook (address, name) {
|
||||||
let addressBook = this._getAddressBook()
|
let addressBook = this._getAddressBook()
|
||||||
let index = addressBook.findIndex((element) => { return element.address.toLowerCase() === address.toLowerCase() || element.name === name })
|
let identities = this._getIdentities()
|
||||||
if (index !== -1) {
|
|
||||||
addressBook.splice(index, 1)
|
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({
|
addressBook.push({
|
||||||
address: address,
|
address: address,
|
||||||
@ -56,6 +64,12 @@ class AddressBookController {
|
|||||||
return this.store.getState().addressBook
|
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
|
module.exports = AddressBookController
|
||||||
|
@ -51,11 +51,6 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
initState: initState.PreferencesController,
|
initState: initState.PreferencesController,
|
||||||
})
|
})
|
||||||
|
|
||||||
// address book controller
|
|
||||||
this.addressBookController = new AddressBookController({
|
|
||||||
initState: initState.AddressBookController,
|
|
||||||
})
|
|
||||||
|
|
||||||
// currency controller
|
// currency controller
|
||||||
this.currencyController = new CurrencyController({
|
this.currencyController = new CurrencyController({
|
||||||
initState: initState.CurrencyController,
|
initState: initState.CurrencyController,
|
||||||
@ -86,6 +81,11 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
autoFaucet(address)
|
autoFaucet(address)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// address book controller
|
||||||
|
this.addressBookController = new AddressBookController({
|
||||||
|
initState: initState.AddressBookController,
|
||||||
|
}, this.keyringController)
|
||||||
|
|
||||||
// tx mgmt
|
// tx mgmt
|
||||||
this.txManager = new TxManager({
|
this.txManager = new TxManager({
|
||||||
initState: initState.TransactionManager,
|
initState: initState.TransactionManager,
|
||||||
|
Loading…
Reference in New Issue
Block a user