Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use toUnicode function to normalize ens domains in the UI #29231

Conversation

OGPoyraz
Copy link
Member

@OGPoyraz OGPoyraz commented Dec 16, 2024

Description

In ENSController(https://github.com/MetaMask/core/blob/main/packages/ens-controller/src/EnsController.ts#L375) right before saving the ens domain in the state we use toASCII. This function is typically used to convert a domain name from its Unicode representation to ASCII, specifically using the Punycode package encoding. This is necessary because the Domain Name System (DNS) operates with ASCII characters, and internationalized domain names (IDNs) need to be converted to a format that DNS can understand.

On the other side, in the client, we are not converting/normalizing this domain value. That is causing that unwanted ASCII coded domain in the UI when using smileys in the ENS domain.

Open in GitHub Codespaces

Related issues

Fixes: #28610

Manual testing steps

See #28610 for repro steps

Screenshots/Recordings

Before

Screenshot 2024-12-16 at 13 37 04

After

Screenshot 2024-12-16 at 13 36 32

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@metamaskbot metamaskbot added the team-confirmations Push issues to confirmations team label Dec 16, 2024
@@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

punycode lib I think is deprecated, we should avoid using it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should rely on any other package before removing the toASCII util from ENSController - these utils match each other since both using same encoding from punycode package

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, will be nice to mention that as a comment here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, added a comment.

const displayName =
(recipientName ||
recipientNickname ||
recipientMetadataName ||
recipientEns ||
normalizedEnsRecipientName ||
shortenAddress(checksummedRecipientAddress)) ??
(!addressOnly && t('newContract'));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be useful to also test cover this change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's moved in to selector and we are not adding any test on them, I will skip and won't add it.

const displayName =
(recipientName ||
recipientNickname ||
recipientMetadataName ||
recipientEns ||
normalizedEnsRecipientName ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we have this issue rendering ENS proposed names in petnames, and anywhere the ENS controller state is used?

Could we fix this deeper in the getEnsResolutionByAddress selector perhaps so we don't have to manually do this for each usage?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense to do that casting on deeper, done.

@OGPoyraz OGPoyraz force-pushed the 28610-bug-send-to-ens-emojis-domain---wrong-handling-of-emojis-ens-domains branch from 19536a7 to c2bc8b5 Compare December 16, 2024 14:19
@metamaskbot
Copy link
Collaborator

Builds ready [143deb9]
Page Load Metrics (1589 ± 32 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1484169115916632
domContentLoaded1460167815616330
load1486169015896632
domInteractive239237209
backgroundConnect768302010
firstReactRender1568322110
getState45612147
initialActions01000
loadScripts1043129311726430
setupStore65612136
uiStartup1642191117977838
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 140 Bytes (0.00%)

@OGPoyraz OGPoyraz enabled auto-merge December 18, 2024 07:33
@metamaskbot
Copy link
Collaborator

Builds ready [d01b223]
Page Load Metrics (1731 ± 66 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint15302010173113565
domContentLoaded15181989170513263
load15322010173113766
domInteractive267638147
backgroundConnect95927178
firstReactRender16103563316
getState584202512
initialActions00000
loadScripts11221501128110349
setupStore775212411
uiStartup175227712143300144
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 140 Bytes (0.00%)

@OGPoyraz OGPoyraz added this pull request to the merge queue Dec 20, 2024
Merged via the queue into main with commit fd6e755 Dec 20, 2024
77 checks passed
@OGPoyraz OGPoyraz deleted the 28610-bug-send-to-ens-emojis-domain---wrong-handling-of-emojis-ens-domains branch December 20, 2024 10:10
@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2024
@metamaskbot metamaskbot added the release-12.11.0 Issue or pull request that will be included in release 12.11.0 label Dec 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.11.0 Issue or pull request that will be included in release 12.11.0 team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Send to ENS emojis domain - Wrong handling of emojis ENS domains
4 participants