Skip to content

Commit

Permalink
Merge pull request #6372 from MetaMask/addAddressIfNew
Browse files Browse the repository at this point in the history
prevent add duplicates when address is not new
  • Loading branch information
kumavis authored Mar 29, 2019
2 parents 8675263 + 0961449 commit 133ed80
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
4 changes: 3 additions & 1 deletion ui/app/components/app/send/send-footer/send-footer.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 133ed80

Please sign in to comment.