1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-24 04:13:27 +02:00
metamask-extension/ui/app/pages/send/send-content/add-recipient/add-recipient.js
ryanml f080c10cbc
Fixing ENS input entry in send flow (#10923)
* Fixing ENS input entry in send flow

Fixes MetaMask/metamask-extension#10691

* removed unnecessary apostrophe
2021-04-26 07:31:20 -07:00

49 lines
1.4 KiB
JavaScript

import { toChecksumAddress } from 'ethereumjs-util';
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 {
isValidAddress,
checkExistingAddresses,
isValidDomainName,
isOriginContractAddress,
isDefaultMetaMaskChain,
} from '../../../../helpers/utils/util';
export function getToErrorObject(to, sendTokenAddress, chainId) {
let toError = null;
if (!to) {
toError = REQUIRED_ERROR;
} else if (!isValidAddress(to) && !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 &&
(toChecksumAddress(to) in contractMap || checkExistingAddresses(to, tokens))
) {
toWarning = KNOWN_RECIPIENT_ADDRESS_ERROR;
} else if (isValidDomainName(to) && isConfusing(to)) {
toWarning = CONFUSING_ENS_ERROR;
}
return { to: toWarning };
}