Skip to content

Commit

Permalink
check for tokens in state
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanmino committed Jan 21, 2019
1 parent b55c8c6 commit 084fd48
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../../send.selectors.js'
import {
getToDropdownOpen,
getTokens,
sendToIsInError,
} from './send-to-row.selectors.js'
import {
Expand All @@ -29,6 +30,7 @@ function mapStateToProps (state) {
to: getSendTo(state),
toAccounts: getSendToAccounts(state),
toDropdownOpen: getToDropdownOpen(state),
tokens: getTokens(state),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const selectors = {
getToDropdownOpen,
getTokens,
sendToIsInError,
}

Expand All @@ -12,3 +13,7 @@ function getToDropdownOpen (state) {
function sendToIsInError (state) {
return Boolean(state.send.errors.to)
}

function getTokens (state) {
return state.metamask.tokens
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 084fd48

Please sign in to comment.