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

refactor: Update ENS utils to accept chain ID #7150

Merged
merged 3 commits into from
Sep 11, 2023

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Sep 6, 2023

Development & PR Process

  1. Follow MetaMask Mobile Coding Standards
  2. Add release-xx label to identify the PR slated for a upcoming release (will be used in release discussion)
  3. Add needs-dev-review label when work is completed
  4. Add the appropiate QA label when dev review is completed
    • needs-qa: PR requires manual QA.
    • No QA/E2E only: PR does not require any manual QA effort. Prior to merging, ensure that you have successful end-to-end test runs in Bitrise.
    • Spot check on release build: PR does not require feature QA but needs non-automated verification. In the description section, provide test scenarios. Add screenshots, and or recordings of what was tested.
  5. Add QA Passed label when QA has signed off (Only required if the PR was labeled with needs-qa)
  6. Add your team's label, i.e. label starting with team- (or external-contributor label if your not a MetaMask employee)

Description

The ENS utility functions now accept chain ID instead of network ID. Chain ID is easier for us to access because we know the chain ID for all configured networks at all times, as it's a required property. The network ID has to be looked up dynamically at runtime, meaning that we don't know what it is until after the network has loaded.

The network ID is still used internally by the ENS utility functions because the library we use for ENS support still expects network ID rather than chain ID.

This was done to simplify the upcoming network controller update. The new update replaces network with networkId and networkStatus, where the ID is null while the network is loading. This forces us to handle that loading state anywhere the network ID had been used. Reducing the usages of network ID means avoiding that work.

Issue

This relates to https://github.com/MetaMask/mobile-planning/issues/1226

Checklist

  • There is a related GitHub issue
  • Tests are included if applicable
  • Any added code is fully documented

@codecov-commenter
Copy link

codecov-commenter commented Sep 6, 2023

Codecov Report

Patch coverage: 65.62% and project coverage change: +0.02% 🎉

Comparison is base (617b0f9) 32.94% compared to head (ea9e94d) 32.97%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7150      +/-   ##
==========================================
+ Coverage   32.94%   32.97%   +0.02%     
==========================================
  Files        1005     1005              
  Lines       32638    32649      +11     
  Branches     8383     8384       +1     
==========================================
+ Hits        10753    10765      +12     
+ Misses      21885    21884       -1     
Files Changed Coverage Δ
app/components/UI/AccountOverview/index.js 4.76% <0.00%> (ø)
app/components/Views/Send/index.js 3.25% <0.00%> (ø)
app/util/address/index.js 39.77% <20.00%> (ø)
app/util/ENSUtils.js 57.77% <81.25%> (+19.54%) ⬆️
...UI/AccountFromToInfoCard/AccountFromToInfoCard.tsx 85.50% <100.00%> (ø)
...s/Views/SendFlow/AddressElement/AddressElement.tsx 85.71% <100.00%> (-4.77%) ⬇️
...ponents/Views/SendFlow/AddressFrom/AddressFrom.tsx 70.58% <100.00%> (ø)
app/components/hooks/useAccounts/useAccounts.ts 90.36% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Gudahtt Gudahtt force-pushed the refactor-ens-cache-to-accept-chain-id branch from 91215d2 to b8d439d Compare September 6, 2023 14:24
@Gudahtt Gudahtt added needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) team-mobile-platform labels Sep 6, 2023
@Gudahtt Gudahtt marked this pull request as ready for review September 6, 2023 14:27
@Gudahtt Gudahtt requested a review from a team as a code owner September 6, 2023 14:27
@Gudahtt Gudahtt added the No QA Needed/E2E Only Apply this label when your PR does not need any QA effort. label Sep 6, 2023
@Gudahtt Gudahtt marked this pull request as draft September 6, 2023 15:12
@Gudahtt Gudahtt force-pushed the refactor-ens-cache-to-accept-chain-id branch 4 times, most recently from 4069161 to ffe0248 Compare September 6, 2023 18:15
@Gudahtt Gudahtt marked this pull request as ready for review September 6, 2023 19:10
@Gudahtt
Copy link
Member Author

Gudahtt commented Sep 6, 2023

@Gudahtt Gudahtt marked this pull request as draft September 7, 2023 13:06
@Gudahtt
Copy link
Member Author

Gudahtt commented Sep 7, 2023

This is ready for review, but I am moving it back into draft temporarily because there is one more related change that I'm planning to add.

@Gudahtt Gudahtt force-pushed the refactor-ens-cache-to-accept-chain-id branch from 422fb94 to 4d51b55 Compare September 7, 2023 21:34
@Gudahtt Gudahtt marked this pull request as ready for review September 7, 2023 21:36
@Gudahtt
Copy link
Member Author

Gudahtt commented Sep 7, 2023

@Gudahtt Gudahtt force-pushed the refactor-ens-cache-to-accept-chain-id branch 2 times, most recently from 03b69cf to 65c1152 Compare September 8, 2023 16:42
The ENS utility functions now accept chain ID instead of network ID.
Chain ID is easier for us to access because we know the chain ID for
all configured networks at all times, as it's a required property. The
network ID has to be looked up dynamically at runtime, meaning that we
don't know what it is until after the network has loaded.

The network ID is still used internally by the ENS utility functions
because the library we use for ENS support still expects network ID
rather than chain ID.

This was done to simplify the upcoming network controller update. The
new update replaces `network` with `networkId` and `networkStatus`,
where the ID is `null` while the network is loading. This forces us to
handle that loading state anywhere the network ID had been used.
Reducing the usages of network ID means avoiding that work.

This relates to MetaMask/mobile-planning#1226
The new `getCachedENSName` function will retrieve a cached name from
the cache, ensuring that we don't need to reference the cache directly
from elsewhere in the codebase. This removes another reference to the
network ID.

The testing setup was a bit awkward because `ENSCache.cache` is a
property, which Jest offers no way to mock out at the moment. But this
is resolved in jest v29 with the `replaceProperty` method. A workaround
using hooks has been used as an interim solution.
@Gudahtt Gudahtt force-pushed the refactor-ens-cache-to-accept-chain-id branch from 65c1152 to ea9e94d Compare September 9, 2023 17:13
@sonarcloud
Copy link

sonarcloud bot commented Sep 9, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@Cal-L Cal-L left a comment

Choose a reason for hiding this comment

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

LGTM

@Gudahtt Gudahtt removed the needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) label Sep 11, 2023
@Gudahtt Gudahtt merged commit aea80fe into main Sep 11, 2023
25 checks passed
@Gudahtt Gudahtt deleted the refactor-ens-cache-to-accept-chain-id branch September 11, 2023 18:31
@github-actions github-actions bot locked and limited conversation to collaborators Sep 11, 2023
@metamaskbot metamaskbot added the release-7.8.0 Issue or pull request that will be included in release 7.8.0 label Sep 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
No QA Needed/E2E Only Apply this label when your PR does not need any QA effort. release-7.8.0 Issue or pull request that will be included in release 7.8.0 team-mobile-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants