2018-04-30 18:30:01 +02:00
|
|
|
const {
|
|
|
|
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,
|
2018-04-30 18:30:01 +02:00
|
|
|
} = require('../../send.constants')
|
2019-04-17 21:15:13 +02:00
|
|
|
const { isValidAddress, isEthNetwork } = require('../../../../helpers/utils/util')
|
|
|
|
import { checkExistingAddresses } from '../../../add-token/util'
|
2018-04-07 00:29:51 +02:00
|
|
|
|
2019-01-22 20:05:59 +01:00
|
|
|
const ethUtil = require('ethereumjs-util')
|
|
|
|
const contractMap = require('eth-contract-metadata')
|
|
|
|
|
2019-05-08 21:51:33 +02:00
|
|
|
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 }
|
|
|
|
}
|
|
|
|
|
2019-01-23 19:09:56 +01:00
|
|
|
function getToWarningObject (to, toWarning = null, tokens = [], selectedToken = null) {
|
|
|
|
if (selectedToken && (ethUtil.toChecksumAddress(to) in contractMap || checkExistingAddresses(to, tokens))) {
|
|
|
|
toWarning = KNOWN_RECIPIENT_ADDRESS_ERROR
|
|
|
|
}
|
|
|
|
return { to: toWarning }
|
|
|
|
}
|
|
|
|
|
2018-04-07 00:29:51 +02:00
|
|
|
module.exports = {
|
2018-04-27 02:38:14 +02:00
|
|
|
getToErrorObject,
|
2019-01-23 19:09:56 +01:00
|
|
|
getToWarningObject,
|
2018-04-07 00:29:51 +02:00
|
|
|
}
|