mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-25 03:20:23 +01:00
92971d3c87
* Update eslint-plugin-import version * Convert JS files to use ESM * Update ESLint rules to check imports * Fix test:unit:global command env * Cleanup mock-dev script
32 lines
1.0 KiB
JavaScript
32 lines
1.0 KiB
JavaScript
import {
|
|
REQUIRED_ERROR,
|
|
INVALID_RECIPIENT_ADDRESS_ERROR,
|
|
KNOWN_RECIPIENT_ADDRESS_ERROR,
|
|
INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR,
|
|
} from '../../send.constants'
|
|
|
|
import { isValidAddress, isEthNetwork } from '../../../../helpers/utils/util'
|
|
import { checkExistingAddresses } from '../../../add-token/util'
|
|
|
|
import ethUtil from 'ethereumjs-util'
|
|
import contractMap from 'eth-contract-metadata'
|
|
|
|
export function getToErrorObject (to, toError = null, hasHexData = false, _, __, network) {
|
|
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
|
|
}
|
|
|
|
return { to: toError }
|
|
}
|
|
|
|
export 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 }
|
|
}
|