mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-04 23:14:56 +01:00
57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
import contractMap from '@metamask/contract-metadata';
|
|
import { isConfusing } from 'unicode-confusables';
|
|
import {
|
|
REQUIRED_ERROR,
|
|
INVALID_RECIPIENT_ADDRESS_ERROR,
|
|
KNOWN_RECIPIENT_ADDRESS_ERROR,
|
|
INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR,
|
|
CONFUSING_ENS_ERROR,
|
|
CONTRACT_ADDRESS_ERROR,
|
|
} from '../../send.constants';
|
|
|
|
import {
|
|
checkExistingAddresses,
|
|
isValidDomainName,
|
|
isOriginContractAddress,
|
|
isDefaultMetaMaskChain,
|
|
} from '../../../../helpers/utils/util';
|
|
import {
|
|
isBurnAddress,
|
|
isValidHexAddress,
|
|
toChecksumHexAddress,
|
|
} from '../../../../../shared/modules/hexstring-utils';
|
|
|
|
export function getToErrorObject(to, sendTokenAddress, chainId) {
|
|
let toError = null;
|
|
if (!to) {
|
|
toError = REQUIRED_ERROR;
|
|
} else if (
|
|
isBurnAddress(to) ||
|
|
(!isValidHexAddress(to, { mixedCaseUseChecksum: true }) &&
|
|
!isValidDomainName(to))
|
|
) {
|
|
toError = isDefaultMetaMaskChain(chainId)
|
|
? INVALID_RECIPIENT_ADDRESS_ERROR
|
|
: INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR;
|
|
} else if (isOriginContractAddress(to, sendTokenAddress)) {
|
|
toError = CONTRACT_ADDRESS_ERROR;
|
|
}
|
|
|
|
return { to: toError };
|
|
}
|
|
|
|
export function getToWarningObject(to, tokens = [], sendToken = null) {
|
|
let toWarning = null;
|
|
if (
|
|
sendToken &&
|
|
(toChecksumHexAddress(to) in contractMap ||
|
|
checkExistingAddresses(to, tokens))
|
|
) {
|
|
toWarning = KNOWN_RECIPIENT_ADDRESS_ERROR;
|
|
} else if (isValidDomainName(to) && isConfusing(to)) {
|
|
toWarning = CONFUSING_ENS_ERROR;
|
|
}
|
|
|
|
return { to: toWarning };
|
|
}
|