From 084fd486c12ee9fde6414f323f330b5be2398039 Mon Sep 17 00:00:00 2001 From: Esteban MIno Date: Mon, 21 Jan 2019 18:11:56 -0300 Subject: [PATCH] check for tokens in state --- .../send/send-content/send-to-row/send-to-row.component.js | 5 +++-- .../send/send-content/send-to-row/send-to-row.container.js | 2 ++ .../send/send-content/send-to-row/send-to-row.selectors.js | 5 +++++ .../send/send-content/send-to-row/send-to-row.utils.js | 6 ++++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ui/app/components/send/send-content/send-to-row/send-to-row.component.js b/ui/app/components/send/send-content/send-to-row/send-to-row.component.js index ce5325314d0b..bf17643f216d 100644 --- a/ui/app/components/send/send-content/send-to-row/send-to-row.component.js +++ b/ui/app/components/send/send-content/send-to-row/send-to-row.component.js @@ -15,6 +15,7 @@ export default class SendToRow extends Component { to: PropTypes.string, toAccounts: PropTypes.array, toDropdownOpen: PropTypes.bool, + tokens: PropTypes.array, updateGas: PropTypes.func, updateSendTo: PropTypes.func, updateSendToError: PropTypes.func, @@ -26,8 +27,8 @@ export default class SendToRow extends Component { } handleToChange (to, nickname = '', toError) { - const { hasHexData, updateSendTo, updateSendToError, updateGas } = this.props - const toErrorObject = getToErrorObject(to, toError, hasHexData) + const { hasHexData, updateSendTo, updateSendToError, updateGas, tokens } = this.props + const toErrorObject = getToErrorObject(to, toError, hasHexData, tokens) updateSendTo(to, nickname) updateSendToError(toErrorObject) if (toErrorObject.to === null) { diff --git a/ui/app/components/send/send-content/send-to-row/send-to-row.container.js b/ui/app/components/send/send-content/send-to-row/send-to-row.container.js index 3ee188badec5..cb5519161017 100644 --- a/ui/app/components/send/send-content/send-to-row/send-to-row.container.js +++ b/ui/app/components/send/send-content/send-to-row/send-to-row.container.js @@ -7,6 +7,7 @@ import { } from '../../send.selectors.js' import { getToDropdownOpen, + getTokens, sendToIsInError, } from './send-to-row.selectors.js' import { @@ -29,6 +30,7 @@ function mapStateToProps (state) { to: getSendTo(state), toAccounts: getSendToAccounts(state), toDropdownOpen: getToDropdownOpen(state), + tokens: getTokens(state), } } diff --git a/ui/app/components/send/send-content/send-to-row/send-to-row.selectors.js b/ui/app/components/send/send-content/send-to-row/send-to-row.selectors.js index 8919014bed8d..982fd2e46d47 100644 --- a/ui/app/components/send/send-content/send-to-row/send-to-row.selectors.js +++ b/ui/app/components/send/send-content/send-to-row/send-to-row.selectors.js @@ -1,5 +1,6 @@ const selectors = { getToDropdownOpen, + getTokens, sendToIsInError, } @@ -12,3 +13,7 @@ function getToDropdownOpen (state) { function sendToIsInError (state) { return Boolean(state.send.errors.to) } + +function getTokens (state) { + return state.metamask.tokens +} diff --git a/ui/app/components/send/send-content/send-to-row/send-to-row.utils.js b/ui/app/components/send/send-content/send-to-row/send-to-row.utils.js index 0e11c9423a50..aaaa75109755 100644 --- a/ui/app/components/send/send-content/send-to-row/send-to-row.utils.js +++ b/ui/app/components/send/send-content/send-to-row/send-to-row.utils.js @@ -4,17 +4,19 @@ const { KNOWN_RECIPIENT_ADDRESS_ERROR, } = require('../../send.constants') const { isValidAddress } = require('../../../../util') +import { checkExistingAddresses } from '../../../pages/add-token/util' + const ethUtil = require('ethereumjs-util') const contractMap = require('eth-contract-metadata') -function getToErrorObject (to, toError = null, hasHexData = false) { +function getToErrorObject (to, toError = null, hasHexData = false, tokens = []) { if (!to) { if (!hasHexData) { toError = REQUIRED_ERROR } } else if (!isValidAddress(to) && !toError) { toError = INVALID_RECIPIENT_ADDRESS_ERROR - } else if (ethUtil.toChecksumAddress(to) in contractMap) { + } else if (ethUtil.toChecksumAddress(to) in contractMap || checkExistingAddresses(to, tokens)) { toError = KNOWN_RECIPIENT_ADDRESS_ERROR }