Skip to content

Commit a780785

Browse files
authored
chore: reduce tokenBalances state updates (#5726)
## 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 <!-- 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 <!-- THIS SECTION IS NO LONGER NEEDED. The process for updating changelogs has changed. Please consult the "Updating changelogs" section of the Contributing doc for more. --> ## 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 communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
1 parent a5384b9 commit a780785

6 files changed

+721
-26
lines changed

eslint-warning-thresholds.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@
7373
"packages/assets-controllers/src/Standards/NftStandards/ERC721/ERC721Standard.ts": {
7474
"prettier/prettier": 1
7575
},
76-
"packages/assets-controllers/src/TokenBalancesController.test.ts": {
77-
"import-x/order": 1
78-
},
7976
"packages/assets-controllers/src/TokenBalancesController.ts": {
8077
"@typescript-eslint/prefer-readonly": 4,
8178
"jsdoc/check-tag-names": 4,

packages/assets-controllers/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- **BREAKING:** Add event listener for `AccountsController:accountRemoved` on `TokenBalancesController` to remove token balances for the removed account ([#5726](https://github.com/MetaMask/core/pull/5726))
13+
14+
- **BREAKING:** Add event listener for `AccountsController:accountRemoved` on `TokensController` to remove tokens for the removed account ([#5726](https://github.com/MetaMask/core/pull/5726))
15+
16+
- **BREAKING:** Add `listAccounts` action to `TokensController` ([#5726](https://github.com/MetaMask/core/pull/5726))
17+
18+
- **BREAKING:** Add `listAccounts` action to `TokenBalancesController` ([#5726](https://github.com/MetaMask/core/pull/5726))
19+
20+
### Changed
21+
22+
- TokenBalancesController will now check if balances has changed before updating the state ([#5726](https://github.com/MetaMask/core/pull/5726))
23+
1024
## [63.1.0]
1125

1226
### Changed

0 commit comments

Comments
 (0)