-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
Conversation
There was a problem hiding this 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
a655a00
to
3681c95
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this 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 () => { |
There was a problem hiding this comment.
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 thattokens
andignoredTokens
are not affected, which is a slightly different thing to check. - Who are "we" in this context?
Perhaps a better name would be:
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 () => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
7d0cf7d
to
437a006
Compare
There was a problem hiding this 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.
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
TokensController.ts
to include conditional updates for ignoredTokens and tokens based on the currently selected network.TokensController.test.ts
to reflect the new behavior, ensuring state changes only occur for the active network.References
Changelog
@metamask/assets-controllers
tokens
,ignoreTokens
,delectedTokens
state when we callignoredTokens
on networks other than the currently selected one.Checklist