Repository navigation
Commit 69ccbd9
authored
feat(assets-controller): add balance state in snaps request (#10819)
## Explanation
v6 `SnapDataSource` fetches request the snap's listed holdings plus
visible assets (native, pin, and default tracked). Accounts API and the
websocket already return a wider token set than the snap lists. If a
chain rolls back to the snap, those extra tokens would stop refreshing.
This adds a temporary, deletable block so the v6 request is the union
of:
- the snap's listed holdings
- visible assets
- every token already stored in balance state for the requested chains
Hidden assets stay out, and tokens stored for other chains stay out. A
visible token with no balance entry is still requested. If the snap
omits a balance-state token it was asked for, that token stays out of
the snapshot.
Delete `#includeSnapRollbackBalanceStateTokens` and its call in
`#fetchV6` once balance reads fully move to Accounts API. The
visible-asset path is unchanged.
Unsubscribing from account activity now releases every tracked chain the
same way a WebSocket disconnect does.
`#unsubscribeFromAllAccountActivity` publishes one
`AccountActivityService:statusChanged` event with status `down` for
every tracked chain, including any status still buffered, and then
clears that set. A snaps-migration flag change and an account switch
both go through this unsubscribe before resubscribing. The next system
notification marks the chains that are still up, so chains whose flag
turned off can be subscribed through snaps.
## References
* Related to the Accounts API v6 snap migration notes in
`packages/assets-controller/docs/decisions/2026-09-23-accounts-api-v6-integration.md`
## 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 communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes v6 snap balance fetch scope and when AssetsController sees
chains as down during migration flag toggles; incorrect signaling could
mis-route balance sources until the next system notification.
>
> **Overview**
> **Snap v6 balance requests** temporarily include every token already
in balance state for the requested chains (plus listed holdings and
visible assets), in a marked-for-deletion block, so a rollback to Snaps
still refreshes tokens Accounts API / websocket already track.
Snap-omitted balance-state tokens are **not** zero-filled or backfilled
from state.
>
> **Account activity chain status** is refactored:
`#publishTrackedChainsDown` centralizes publishing `down` for all
tracked chains (including debounced pending). WebSocket disconnect and
**snaps-migration feature-flag** resubscribe use it; **account
switches** only unsubscribe/resubscribe and do **not** publish chains
down.
>
> Docs, changelogs, and tests (`SnapDataSource`,
`AccountActivityService`) are updated for the new request union and
status semantics.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
c18f4a6. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent bb58aab commit 69ccbd9
8 files changed
Lines changed: 508 additions & 142 deletions
File tree
- packages
- assets-controller
- docs/decisions
- src/data-sources
- core-backend
- src/ws
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
816 | 816 | | |
817 | 817 | | |
818 | 818 | | |
819 | | - | |
820 | | - | |
821 | | - | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
826 | | - | |
827 | | - | |
828 | 819 | | |
829 | 820 | | |
830 | 821 | | |
| |||
2553 | 2544 | | |
2554 | 2545 | | |
2555 | 2546 | | |
2556 | | - | |
| 2547 | + | |
2557 | 2548 | | |
2558 | 2549 | | |
2559 | 2550 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
146 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
147 | 152 | | |
148 | 153 | | |
149 | 154 | | |
| |||
184 | 189 | | |
185 | 190 | | |
186 | 191 | | |
187 | | - | |
| 192 | + | |
188 | 193 | | |
189 | 194 | | |
190 | 195 | | |
| |||
0 commit comments