-
-
Notifications
You must be signed in to change notification settings - Fork 201
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.
…5014) ## 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. <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Changelog <!-- If you're making any consumer-facing changes, list those changes here as if you were updating a changelog, using the template below as a guide. (CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or FIXED. For security-related issues, follow the Security Advisory process.) Please take care to name the exact pieces of the API you've added or changed (e.g. types, interfaces, functions, or methods). If there are any breaking changes, make sure to offer a solution for consumers to follow once they upgrade to the changes. Finally, if you're only making changes to development scripts or tests, you may replace the template below with "None". --> ### `@metamask/assets-controllers` - **FIXED**: Prevented updates to `tokens`, `ignoreTokens`, `delectedTokens` state when we call `ignoredTokens` on networks other than the currently selected one. ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] 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
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