You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Explanation
This change prevents AccountTrackerController from overwriting cached
balances with empty or unchanged state during refresh operations.
Currently, if all balance requests for a chain fail or return undefined
(e.g., due to a temporary network issue), the controller updates the
state with an empty object, erasing previous data. Additionally, even
when the new balance data is identical to the current state, an update
is still triggered, resulting in unnecessary stateChange emissions and
potential UI re-renders.
This update introduces guards within the refresh method to:
- Skip updates if the computed accountsForChain object is empty.
- Skip updates if the resulting balances are identical to the current
state.
- Prevent stale or partial data from overriding valid cached values.
- Reduce unnecessary re-renders and state emissions.
These changes help improve performance and stability, particularly under
poor network conditions or when balance polling is frequent.
<!--
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
* Fixes
[#15472](MetaMask/metamask-mobile#15472)
<!--
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.
-->
### `@metamask/assets-controllers`
UPDATE: Prevent AccountTrackerController from updating state with empty
or unchanged data during balance refresh. Adds checks to avoid
overwriting valid cached balances and reduce unnecessary stateChange
emissions.
## Checklist
- [x] 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
Copy file name to clipboardExpand all lines: packages/assets-controllers/CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
8
8
## [Unreleased]
9
9
10
+
### Fixed
11
+
12
+
- Prevented `AccountTrackerController` from updating state with empty or unchanged account balance data during refresh ([#5942](https://github.com/MetaMask/core/pull/5942))
13
+
- Added guards to skip state updates when fetched balances are empty or identical to existing state
14
+
- Reduces unnecessary `stateChange` emissions and preserves previously-cached balances under network failure scenarios
0 commit comments