From 06b89eb7003e356f90824c3429b00b445bcca68f Mon Sep 17 00:00:00 2001 From: OGPoyraz Date: Mon, 16 Dec 2024 13:32:41 +0100 Subject: [PATCH 1/4] Use toUnicode function to normalize ens addresses --- .../ui/sender-to-recipient/sender-to-recipient.component.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/components/ui/sender-to-recipient/sender-to-recipient.component.js b/ui/components/ui/sender-to-recipient/sender-to-recipient.component.js index c4deb1e1d8ee..4dd408af8e07 100644 --- a/ui/components/ui/sender-to-recipient/sender-to-recipient.component.js +++ b/ui/components/ui/sender-to-recipient/sender-to-recipient.component.js @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import classnames from 'classnames'; import copyToClipboard from 'copy-to-clipboard'; import { NameType } from '@metamask/name-controller'; +import { toUnicode } from 'punycode'; import Tooltip from '../tooltip'; import Identicon from '../identicon'; import { shortenAddress } from '../../../helpers/utils/util'; @@ -129,11 +130,13 @@ export function RecipientWithAddress({ ); } + const normalizedEnsRecipientName = toUnicode(recipientEns); + const displayName = (recipientName || recipientNickname || recipientMetadataName || - recipientEns || + normalizedEnsRecipientName || shortenAddress(checksummedRecipientAddress)) ?? (!addressOnly && t('newContract')); From bf16c202f4369f563529b8ca96e64f31b8e1b12e Mon Sep 17 00:00:00 2001 From: OGPoyraz Date: Mon, 16 Dec 2024 14:49:07 +0100 Subject: [PATCH 2/4] Add ens casting in the deeper level --- .../ui/sender-to-recipient/sender-to-recipient.component.js | 5 +---- ui/selectors/selectors.js | 5 ++++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/components/ui/sender-to-recipient/sender-to-recipient.component.js b/ui/components/ui/sender-to-recipient/sender-to-recipient.component.js index 4dd408af8e07..c4deb1e1d8ee 100644 --- a/ui/components/ui/sender-to-recipient/sender-to-recipient.component.js +++ b/ui/components/ui/sender-to-recipient/sender-to-recipient.component.js @@ -3,7 +3,6 @@ import PropTypes from 'prop-types'; import classnames from 'classnames'; import copyToClipboard from 'copy-to-clipboard'; import { NameType } from '@metamask/name-controller'; -import { toUnicode } from 'punycode'; import Tooltip from '../tooltip'; import Identicon from '../identicon'; import { shortenAddress } from '../../../helpers/utils/util'; @@ -130,13 +129,11 @@ export function RecipientWithAddress({ ); } - const normalizedEnsRecipientName = toUnicode(recipientEns); - const displayName = (recipientName || recipientNickname || recipientMetadataName || - normalizedEnsRecipientName || + recipientEns || shortenAddress(checksummedRecipientAddress)) ?? (!addressOnly && t('newContract')); diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 02adf1241e30..638e9e24b899 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -1,3 +1,4 @@ +import { toUnicode } from 'punycode'; import { SubjectType } from '@metamask/permission-controller'; import { ApprovalType } from '@metamask/controller-utils'; import { @@ -731,7 +732,9 @@ export function getAddressBook(state) { export function getEnsResolutionByAddress(state, address) { if (state.metamask.ensResolutionsByAddress[address]) { - return state.metamask.ensResolutionsByAddress[address]; + const ensResolution = state.metamask.ensResolutionsByAddress[address]; + const normalizedEnsResolution = toUnicode(ensResolution); + return normalizedEnsResolution; } const entry = From c2bc8b578589c90728e781bfdba6eef6c2a400a3 Mon Sep 17 00:00:00 2001 From: OGPoyraz Date: Mon, 16 Dec 2024 15:19:33 +0100 Subject: [PATCH 3/4] Fix lint --- ui/selectors/selectors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 638e9e24b899..8d833721d55e 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -1,4 +1,4 @@ -import { toUnicode } from 'punycode'; +import { toUnicode } from 'punycode/punycode.js'; import { SubjectType } from '@metamask/permission-controller'; import { ApprovalType } from '@metamask/controller-utils'; import { From 825c14aaac3478b1d609d660cd39cd9ec97438b5 Mon Sep 17 00:00:00 2001 From: OGPoyraz Date: Wed, 18 Dec 2024 15:12:28 +0100 Subject: [PATCH 4/4] Add comment --- ui/selectors/selectors.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 8d833721d55e..9ef74f1ab089 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -733,6 +733,7 @@ export function getAddressBook(state) { export function getEnsResolutionByAddress(state, address) { if (state.metamask.ensResolutionsByAddress[address]) { const ensResolution = state.metamask.ensResolutionsByAddress[address]; + // ensResolution is a punycode encoded string hence toUnicode is used to decode it from same package const normalizedEnsResolution = toUnicode(ensResolution); return normalizedEnsResolution; }