1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 03:20:23 +01:00
metamask-extension/ui/app/pages/send/send-content/add-recipient/add-recipient.js

36 lines
1.1 KiB
JavaScript
Raw Normal View History

const {
REQUIRED_ERROR,
INVALID_RECIPIENT_ADDRESS_ERROR,
KNOWN_RECIPIENT_ADDRESS_ERROR,
INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR,
} = require('../../send.constants')
const { isValidAddress, isEthNetwork } = require('../../../../helpers/utils/util')
import { checkExistingAddresses } from '../../../add-token/util'
2018-04-07 00:29:51 +02:00
const ethUtil = require('ethereumjs-util')
const contractMap = require('eth-contract-metadata')
function getToErrorObject (to, toError = null, hasHexData = false, _, __, network) {
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 }
}
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 = {
getToErrorObject,
2019-01-23 19:09:56 +01:00
getToWarningObject,
2018-04-07 00:29:51 +02:00
}