Skip to content

fix: prevent non-current network tokens from being hidden incorrectly - #4967

Merged
salimtb merged 3 commits into
mainfrom
salim/fix-ignore-tokens-multichain
Nov 25, 2024
Merged

fix: prevent non-current network tokens from being hidden incorrectly#4967
salimtb merged 3 commits into
mainfrom
salim/fix-ignore-tokens-multichain

Conversation

@salimtb

@salimtbsalimtb commented Nov 24, 2024

Copy link
Copy Markdown
Contributor

Explanation

Current State

Currently, the ignoreTokens method in the TokensController is using a static set of tokens (ignoredTokens, detectedTokens, and tokens) without accounting for tokens scoped to specific networks. This causes issues when attempting to hide tokens that do not belong to the currently active network, potentially leading to incorrect behavior.

Changes Introduced

  • Updated the method to use allTokens, allDetectedTokens, and allIgnoredTokens, scoped by interactingChainId or the current network's chainId and selected address.
  • Ensured the ignoredTokens array is derived dynamically based on the active network and address, preventing interference from tokens of other networks.

How It Works

  • The changes introduce a more granular approach by retrieving the correct token lists (allTokens, allDetectedTokens, and allIgnoredTokens) scoped to the relevant network and address.
  • The method now dynamically calculates ignoredTokens for the active network, avoiding issues with overlapping or incorrect tokens.

These updates ensure that the ignoreTokens function operates correctly when handling network-specific tokens, reducing the risk of unintended behavior.


References

  • None.

Changelog

@metamask/assets-controllers

  • FIXED: Resolved an issue where ignoreTokens could incorrectly hide tokens from networks other than the current one.
  • CHANGED: Updated ignoreTokens logic to use network- and address-specific token lists (allTokens, allDetectedTokens, allIgnoredTokens).

Checklist

  • I've updated the test suite for new or updated code as appropriate.
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate.
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate.
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes.

This format is ready to be used in your PR description field on platforms like GitHub.

@salimtb
salimtb merged commit 216374b into mainNov 25, 2024
@salimtb
salimtb deleted the salim/fix-ignore-tokens-multichain branch November 25, 2024 18:12
github-merge-queueBot pushed a commit to MetaMask/metamask-extension that referenced this pull request Nov 25, 2024
…#28674)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **Description**
fix to prevent non current network tokens from being hidden incorrecly
core PR: MetaMask/core#4967
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->
[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28674?quickstart=1)
## **Related issues**
Fixes:
## **Manual testing steps**
1. add different network accros different chains
2. choose ethereum as current chain
3. try to hide token of polygon for instance
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
https://github.com/user-attachments/assets/2637ed94-6ad1-4025-8000-963906aca187
### **After**
<!-- [screenshots/recordings] -->
https://github.com/user-attachments/assets/4c5d6cbd-4af2-43c5-bcbd-879a71b9997e
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **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.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@salimtb@gambinish