1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Merge pull request #6372 from MetaMask/addAddressIfNew

prevent add duplicates when address is not new
This commit is contained in:
kumavis 2019-03-29 13:48:15 +08:00 committed by GitHub
commit 133ed80aee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -96,9 +96,10 @@ function mapDispatchToProps (dispatch) {
return dispatch(updateTransaction(editingTx))
},
addToAddressBookIfNew: (newAddress, toAccounts, nickname = '') => {
const hexPrefixedAddress = ethUtil.addHexPrefix(newAddress)
if (addressIsNew(toAccounts)) {
if (addressIsNew(toAccounts, hexPrefixedAddress)) {
// TODO: nickname, i.e. addToAddressBook(recipient, nickname)
dispatch(addToAddressBook(hexPrefixedAddress, nickname))
}

View File

@ -74,7 +74,9 @@ function constructUpdatedTx ({
}
function addressIsNew (toAccounts, newAddress) {
return !toAccounts.find(({ address }) => newAddress === address)
const newAddressNormalized = newAddress.toLowerCase()
const foundMatching = toAccounts.some(({ address }) => address === newAddressNormalized)
return !foundMatching
}
module.exports = {