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 incorrect warnings when adding a chain from a dapp #22309

Merged
merged 2 commits into from
Dec 18, 2023

Conversation

danjm
Copy link
Contributor

@danjm danjm commented Dec 15, 2023

Description

When a user adds a chain from a dapp, they will see warnings that the currency symbol is incorrect, even though it is correct.

Part of the problem was that the pendingConfirmation variable inside of fetchSafeChainsList was undefined when it should not be. I guess it closed over the original value or something like that? I didn't verify. This PR corrects it by explictly passing the updated pendingConfirmations variable to fetchSafeChainList

The other problem was that useAlertState was calling getTemplateAlerts twice, without resetting the alert state. On the first call, alerts were being set in state because the request to chainId.network had not yet resolved. This PR fixes it by ensuring that that useAlertState does not call getTemplateAlerts before the fetch to chainId.network has resolved (when this confrimation type is an add ethereum chain approval)

Related issues

An example of the problem can be seen by going to https://chainlist.org/?search=cro and adding Cronos Mainnet to metamask, only to see warnings that the currency symbol is incorrect even though it is correct.

Screenshot from 2023-12-15 18-26-51

Manual testing steps

  1. Go to https://chainlist.org/?search=cro
  2. Add Cronos mainnet to metamask
  3. The confirmation window should open with an add ethereum chain confirmation. There should be no warnings
  4. Reject the confirmation
  5. Open the dev console and paste the below code, and press enter. The confirmation window should open with an add ethereum chain confirmation. There should be warnings about the currency symbol
  6. Reject the confirmation
  7. Modify the below code so that "symbol": "cra", becomes "symbol": "cro",, paste it in the dev console and press enter. There should be no warnings in the new confirmation window
await window.ethereum.request({
  "method": "wallet_addEthereumChain",
  "params": [
    {
      "blockExplorerUrls": [
        "https://blockscout.com/poa/xdai/"
      ],
      "nativeCurrency": {
        "name": "CRO",
        "symbol": "cra",
        "decimals": 18
      },
      "rpcUrls": [
        "https://evm.cronos.org",
        null
      ],
      "chainId": "0x19",
      "chainName": "Cronos Mainnet"
    }
  ]
});

Before

cronos-fail.mp4

After

cronos-pass.mp4

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

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.

@danjm danjm requested a review from a team as a code owner December 15, 2023 22:07
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Dec 15, 2023
Copy link

codecov bot commented Dec 18, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (3f113bd) 67.94% compared to head (9df0c45) 67.90%.

Files Patch % Lines
ui/pages/confirmation/confirmation.js 66.67% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #22309      +/-   ##
===========================================
- Coverage    67.94%   67.90%   -0.04%     
===========================================
  Files         1067     1067              
  Lines        41290    41296       +6     
  Branches     11087    11090       +3     
===========================================
- Hits         28054    28041      -13     
- Misses       13236    13255      +19     

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

@metamaskbot
Copy link
Collaborator

Builds ready [9df0c45]
Page Load Metrics (1259 ± 141 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint904081848440
domContentLoaded11191787234
load84719301259293141
domInteractive11191787234
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 194 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@DDDDDanica DDDDDanica merged commit 1b77dc6 into develop Dec 18, 2023
69 of 70 checks passed
@DDDDDanica DDDDDanica deleted the fix-add-chain-warnings branch December 18, 2023 12:03
@github-actions github-actions bot locked and limited conversation to collaborators Dec 18, 2023
@metamaskbot metamaskbot added the release-11.9.0 Issue or pull request that will be included in release 11.9.0 label Dec 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-11.9.0 Issue or pull request that will be included in release 11.9.0 team-extension-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants