mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-28 23:06:37 +01:00
b04120dd0f
* Add warning system for 'confusable' ENS names (#9129) Uses unicode.org's TR39 confusables.txt to display a warning when 'confusable' unicode points are detected. Currently only the `AddRecipient` component has been updated, but the new `Confusable` component could be used elsewhere The new `unicode-confusables` dependency adds close to 100KB to the bundle size, and around 30KB when gzipped. Adds 'tag' prop to the tooltop-v2 component Use $Red-500 for confusable ens warning Lint Tooltip component Update copy for confusing ENS domain warning. * Fix prop type Co-authored-by: Mark Stacey <markjstacey@gmail.com>
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
import ethUtil 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,
|
|
} from '../../send.constants';
|
|
|
|
import {
|
|
isValidAddress,
|
|
isEthNetwork,
|
|
checkExistingAddresses,
|
|
isValidDomainName,
|
|
} 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;
|
|
} else if (isValidDomainName(to) && isConfusing(to)) {
|
|
toWarning = CONFUSING_ENS_ERROR;
|
|
}
|
|
|
|
return { to: toWarning };
|
|
}
|