mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 07:16:36 +01:00
76a2a9bb8b
* @metamask/eslint-config@5.0.0 * Update eslintrc and prettierrc * yarn lint:fix
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
import ethUtil from 'ethereumjs-util';
|
|
import contractMap from '@metamask/contract-metadata';
|
|
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';
|
|
|
|
export function getToErrorObject(to, hasHexData = false, network) {
|
|
let toError = null;
|
|
if (!to) {
|
|
if (!hasHexData) {
|
|
toError = REQUIRED_ERROR;
|
|
}
|
|
} else if (!isValidAddress(to) && !toError) {
|
|
toError = isEthNetwork(network)
|
|
? INVALID_RECIPIENT_ADDRESS_ERROR
|
|
: INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR;
|
|
}
|
|
|
|
return { to: toError };
|
|
}
|
|
|
|
export function getToWarningObject(to, tokens = [], sendToken = null) {
|
|
let toWarning = null;
|
|
if (
|
|
sendToken &&
|
|
(ethUtil.toChecksumAddress(to) in contractMap ||
|
|
checkExistingAddresses(to, tokens))
|
|
) {
|
|
toWarning = KNOWN_RECIPIENT_ADDRESS_ERROR;
|
|
}
|
|
return { to: toWarning };
|
|
}
|