-
-
Notifications
You must be signed in to change notification settings - Fork 223
chore: reduce tokenBalances state updates #5726
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
base: main
Are you sure you want to change the base?
Conversation
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
af73133
to
aa59638
Compare
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
this.update((state) => { | ||
// Reset so that when accounts or tokens are removed, | ||
// their balances are removed rather than left stale. | ||
for (const accountAddress of Object.keys(state.tokenBalances)) { |
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.
Instead of resetting account balances here; we will explicitly handle the case when an account is removed and when a token is removed
const { accountAddress, tokenAddress } = accountTokenPairs[i]; | ||
// if all values of isTokenBalanceValueChanged are false, return | ||
if (updatedResults.every((result) => !result.isTokenBalanceValueChanged)) { | ||
return; |
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.
If none of the balances has changed, return and dnt update state
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
Explanation
When a user removes an account; tokenBalances controller would still fetch balances for the tokens and update state.
This was happening because tokensController does not remove tokens from state when a user removes the account.
This PR cleans up tokens from tokensController state once a user removes an account.
It also cleans up the balances from state when the user removes the account.
This PR also adds a check to see if token balances has changed after fetching them; if none of the balances changed; no need to update state.
References
Changelog
Checklist