You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.4 KiB
49 lines
1.4 KiB
4 years ago
|
import { toChecksumAddress } from 'ethereumjs-util';
|
||
4 years ago
|
import contractMap from '@metamask/contract-metadata';
|
||
4 years ago
|
import { isConfusing } from 'unicode-confusables';
|
||
5 years ago
|
import {
|
||
7 years ago
|
REQUIRED_ERROR,
|
||
|
INVALID_RECIPIENT_ADDRESS_ERROR,
|
||
6 years ago
|
KNOWN_RECIPIENT_ADDRESS_ERROR,
|
||
6 years ago
|
INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR,
|
||
4 years ago
|
CONFUSING_ENS_ERROR,
|
||
4 years ago
|
CONTRACT_ADDRESS_ERROR,
|
||
4 years ago
|
} from '../../send.constants';
|
||
5 years ago
|
|
||
4 years ago
|
import {
|
||
|
isValidAddress,
|
||
|
checkExistingAddresses,
|
||
4 years ago
|
isValidDomainName,
|
||
4 years ago
|
isOriginContractAddress,
|
||
4 years ago
|
isDefaultMetaMaskChain,
|
||
4 years ago
|
} from '../../../../helpers/utils/util';
|
||
6 years ago
|
|
||
4 years ago
|
export function getToErrorObject(to, sendTokenAddress, chainId) {
|
||
4 years ago
|
let toError = null;
|
||
7 years ago
|
if (!to) {
|
||
4 years ago
|
toError = REQUIRED_ERROR;
|
||
4 years ago
|
} else if (!isValidAddress(to) && !isValidDomainName(to)) {
|
||
4 years ago
|
toError = isDefaultMetaMaskChain(chainId)
|
||
4 years ago
|
? INVALID_RECIPIENT_ADDRESS_ERROR
|
||
4 years ago
|
: INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR;
|
||
4 years ago
|
} else if (isOriginContractAddress(to, sendTokenAddress)) {
|
||
|
toError = CONTRACT_ADDRESS_ERROR;
|
||
7 years ago
|
}
|
||
6 years ago
|
|
||
4 years ago
|
return { to: toError };
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
export function getToWarningObject(to, tokens = [], sendToken = null) {
|
||
4 years ago
|
let toWarning = null;
|
||
4 years ago
|
if (
|
||
|
sendToken &&
|
||
4 years ago
|
(toChecksumAddress(to) in contractMap || checkExistingAddresses(to, tokens))
|
||
4 years ago
|
) {
|
||
4 years ago
|
toWarning = KNOWN_RECIPIENT_ADDRESS_ERROR;
|
||
4 years ago
|
} else if (isValidDomainName(to) && isConfusing(to)) {
|
||
|
toWarning = CONFUSING_ENS_ERROR;
|
||
6 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
return { to: toWarning };
|
||
6 years ago
|
}
|