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: Prevent State Changes for ignoreTokens on Non-Current Network #5014

Merged
merged 9 commits into from
Dec 17, 2024

Conversation

salimtb
Copy link
Contributor

@salimtb salimtb commented Dec 2, 2024

Explanation

This pull request addresses an issue in the ignoreTokens function where tokens' states were being updated even if the operation did not pertain to the currently selected network. This behavior could lead to unintended state changes and potential inconsistencies across networks.

Code Changes

  1. Modified TokensController.ts to include conditional updates for ignoredTokens and tokens based on the currently selected network.
  2. Adjusted unit tests in TokensController.test.ts to reflect the new behavior, ensuring state changes only occur for the active network.

References

Changelog

@metamask/assets-controllers

  • FIXED: Prevented updates to tokens, ignoreTokens, delectedTokens state when we call ignoredTokens on networks other than the currently selected one.

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

@salimtb salimtb marked this pull request as ready for review December 2, 2024 18:54
@salimtb salimtb requested a review from a team as a code owner December 2, 2024 18:54
gambinish
gambinish previously approved these changes Dec 2, 2024
Copy link
Contributor

@gambinish gambinish left a comment

Choose a reason for hiding this comment

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

LGTM, but maybe we should also wait for Mark or Elliot's review as well

@salimtb salimtb force-pushed the fix/ignore-tokens-state-selected-network branch from a655a00 to 3681c95 Compare December 3, 2024 14:34
@salimtb salimtb requested review from mcmire and gambinish December 4, 2024 10:38
cryptodev-2s
cryptodev-2s previously approved these changes Dec 6, 2024
Copy link
Contributor

@cryptodev-2s cryptodev-2s left a comment

Choose a reason for hiding this comment

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

LGTM!

@salimtb salimtb requested a review from a team as a code owner December 6, 2024 12:10
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

A couple of suggestions.

@@ -845,6 +845,57 @@ describe('TokensController', () => {
);
});

it('should add tokens to allIgnoredTokens state only if we are not using current network', async () => {
Copy link
Contributor

@mcmire mcmire Dec 6, 2024

Choose a reason for hiding this comment

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

Is this test name as accurate as it could be?

  • It says that tokens should only be added to allIgnoredTokens state, but we are never checking that state. We are just checking that tokens and ignoredTokens are not affected, which is a slightly different thing to check.
  • Who are "we" in this context?

Perhaps a better name would be:

Suggested change
it('should add tokens to allIgnoredTokens state only if we are not using current network', async () => {
it('should not update detectedTokens, tokens, and ignoredTokens state given a network that is different from the globally selected network', async () => {

Copy link
Contributor

Choose a reason for hiding this comment

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

On top of this, do we have a test which ensures that detectedTokens, tokens, and ignoredTokens do get updated when passed the globally selected network? I'm not quite seeing that.

Copy link
Contributor Author

@salimtb salimtb Dec 9, 2024

Choose a reason for hiding this comment

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

suggestions implemented with two tests scenarios

  • should not update detectedTokens, tokens, and ignoredTokens state given a network that is different from the globally selected network
  • should update tokens, and ignoredTokens and detectedTokens state for the globally selected network

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for detected tokens, it's a bit complex to test them, so I've put some assertions to make sure they're not affected, but I'm open to suggestions.

@salimtb salimtb force-pushed the fix/ignore-tokens-state-selected-network branch from 7d0cf7d to 437a006 Compare December 9, 2024 00:17
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Thanks for adding those tests. It would be great to improve the test coverage for this controller in the future, but I think this helps in the meantime.

@salimtb salimtb merged commit 2094380 into main Dec 17, 2024
120 checks passed
@salimtb salimtb deleted the fix/ignore-tokens-state-selected-network branch December 17, 2024 16:10
Sign up for free to 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.

4 participants