1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-24 20:32:02 +02:00
metamask-extension/ui/app/pages/send/send-content/add-recipient/add-recipient.js

32 lines
1021 B
JavaScript
Raw Normal View History

import {
REQUIRED_ERROR,
INVALID_RECIPIENT_ADDRESS_ERROR,
KNOWN_RECIPIENT_ADDRESS_ERROR,
INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR,
} from '../../send.constants'
import { isValidAddress, isEthNetwork, checkExistingAddresses } from '../../../../helpers/utils/util'
import ethUtil from 'ethereumjs-util'
import contractMap from 'eth-contract-metadata'
export function getToErrorObject (to, hasHexData = false, network) {
let toError = null
2018-04-07 00:29:51 +02:00
if (!to) {
if (!hasHexData) {
toError = REQUIRED_ERROR
}
} 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
}
2018-04-07 00:29:51 +02:00
return { to: toError }
}
export function getToWarningObject (to, tokens = [], sendToken = null) {
let toWarning = null
if (sendToken && (ethUtil.toChecksumAddress(to) in contractMap || checkExistingAddresses(to, tokens))) {
2019-01-23 19:09:56 +01:00
toWarning = KNOWN_RECIPIENT_ADDRESS_ERROR
}
return { to: toWarning }
}