fix: prevent non-current network tokens from being hidden incorrectly #4967
+83
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation
Current State
Currently, the
ignoreTokens
method in theTokensController
is using a static set of tokens (ignoredTokens
,detectedTokens
, andtokens
) 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
allTokens
,allDetectedTokens
, andallIgnoredTokens
, scoped byinteractingChainId
or the current network'schainId
and selected address.ignoredTokens
array is derived dynamically based on the active network and address, preventing interference from tokens of other networks.How It Works
allTokens
,allDetectedTokens
, andallIgnoredTokens
) scoped to the relevant network and address.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
Changelog
@metamask/assets-controllers
ignoreTokens
could incorrectly hide tokens from networks other than the current one.ignoreTokens
logic to use network- and address-specific token lists (allTokens
,allDetectedTokens
,allIgnoredTokens
).Checklist
This format is ready to be used in your PR description field on platforms like GitHub.