2020-01-09 04:34:58 +01:00
|
|
|
import {
|
2018-04-30 18:30:01 +02:00
|
|
|
REQUIRED_ERROR,
|
|
|
|
INVALID_RECIPIENT_ADDRESS_ERROR,
|
2019-01-22 20:05:59 +01:00
|
|
|
KNOWN_RECIPIENT_ADDRESS_ERROR,
|
2019-02-13 21:30:46 +01:00
|
|
|
INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR,
|
2020-01-09 04:34:58 +01:00
|
|
|
} from '../../send.constants'
|
|
|
|
|
|
|
|
import { isValidAddress, isEthNetwork } from '../../../../helpers/utils/util'
|
2019-04-17 21:15:13 +02:00
|
|
|
import { checkExistingAddresses } from '../../../add-token/util'
|
2018-04-07 00:29:51 +02:00
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
import ethUtil from 'ethereumjs-util'
|
|
|
|
import contractMap from 'eth-contract-metadata'
|
2019-01-22 20:05:59 +01:00
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export function getToErrorObject (to, toError = null, hasHexData = false, _, __, network) {
|
2018-04-07 00:29:51 +02:00
|
|
|
if (!to) {
|
2018-10-01 14:50:33 +02:00
|
|
|
if (!hasHexData) {
|
|
|
|
toError = REQUIRED_ERROR
|
|
|
|
}
|
2019-02-13 21:30:46 +01:00
|
|
|
} else if (!isValidAddress(to, network) && !toError) {
|
|
|
|
toError = isEthNetwork(network) ? INVALID_RECIPIENT_ADDRESS_ERROR : INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|
2019-05-08 19:34:56 +02:00
|
|
|
|
2018-04-07 00:29:51 +02:00
|
|
|
return { to: toError }
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export function getToWarningObject (to, toWarning = null, tokens = [], selectedToken = null) {
|
2019-01-23 19:09:56 +01:00
|
|
|
if (selectedToken && (ethUtil.toChecksumAddress(to) in contractMap || checkExistingAddresses(to, tokens))) {
|
|
|
|
toWarning = KNOWN_RECIPIENT_ADDRESS_ERROR
|
|
|
|
}
|
|
|
|
return { to: toWarning }
|
|
|
|
}
|