fix(assets-controller): price update for AccountActivity updates - #10410
Merged
Merged
Conversation
Kriys94
force-pushed
the
fix/MiscFixes
branch
from
September 23, 2026 18:02
1d6e982 to
4c1b52f
Compare
Kriys94
marked this pull request as ready for review
September 23, 2026 18:02
| function processAccountActivityBalanceUpdates( | ||
| updates: BalanceUpdate[], | ||
| accountId: string, | ||
| getAssetType: (assetId: Caip19AssetId) => 'native' | 'erc20' | 'spl', |
Comment on lines
-93
to
-98
| assetsMetadata[assetId] = { | ||
| type: getAssetType(assetId), | ||
| symbol: asset.unit, | ||
| name: asset.unit, | ||
| decimals: asset.decimals, | ||
| }; |
Contributor
There was a problem hiding this comment.
Good removal - the metadata is managed by the TokenDataSource responsibility.
Prithpal-Sooriya
approved these changes
Sep 24, 2026
1 of 4 tasks
cryptodev-2s
pushed a commit
to cryptodev-2s/core
that referenced
this pull request
Sep 28, 2026
…taMask#10476) ## Explanation Code Walkthrough: https://www.loom.com/share/a4226f00271249e0aa65d002468914f5 Adds integration tests covering the websocket (AccountActivity) balance-update pipeline behavior from MetaMask#10410 — after a `balanceUpdated` event, the pipeline now requests `metadata` and `price` enrichment so both existing holdings and tokens first surfaced by the websocket get Tokens API metadata and a Price API spot price in the same pass (instead of waiting for the next price poll). To make that pass testable in isolation (mirroring `buildFastFetchSources` for the fast pipeline, which serves both the v5 and v6 fast-fetch lanes), the websocket-update source construction is extracted from `AssetsController#handleAssetsUpdateV5` and `#handleAssetsUpdateV6` into `buildWsUpdateSources`. Like `buildFastFetchSources`, the builder takes an `includeCustomAssetGraduation` option (`true` on the v5 lane; the v6 lane never graduates custom assets and instead runs the RPC fallback ahead of detection), and is tested at three layers: - `buildWsUpdateSources.test.ts` — unit tests of the builder. - `buildWsUpdateSources.price-updates.integration.test.ts` — drives the real `AccountActivityDataSource` and `executeAssetsPipeline` (via `buildWsUpdateSources`) against recorded API responses: - brand-new tokens surfaced by the websocket get metadata + a spot price in the same pass (the MetaMask#10410 fix), - existing tokens missing prices are re-queued for pricing, - tokens whose state metadata already has an icon are skipped by the Tokens API while natives are always fetched. - `AssetsController.ws-price-updates.integration.test.ts` — full-controller integration test: a closed lifecycle, `AccountActivityService:balanceUpdated` published on the root messenger, asserting state balances, metadata, and spot prices all land from the same pipeline pass — on the default v5 lane and again with `assetsAccountsApiV6: true` (the v6 lane, where the RPC fallback replaces graduation). API fixtures are captured from the live APIs into `__fixtures__/ws-price-updates/` (re-runnable via `captureWsApiResponses.ts`), mirroring the `scam-token-cleanup` fixture layout. Like that folder, `captureWsApiResponses.ts` uses the async `writeFile` helpers from `@metamask/utils/node` so it passes `import-x/no-nodejs-modules`. No consumer-facing behavior changes: `buildWsUpdateSources` is internal-only (the pipeline module is not re-exported from the package index), so no changelog entry is needed. ## References * Tests the fix from MetaMask#10410 (`AccountActivityDataSource` metadata/price enrichment on websocket updates) * Fixture layout mirrors `__fixtures__/scam-token-cleanup/`; pipeline extraction mirrors `buildFastFetchSources` ## 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/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] > **Low Risk** > Changes are an internal pipeline refactor plus tests; PR description states no consumer-facing behavior change. > > **Overview** > Refactors **AssetsController** update enrichment so inline middleware lists in `#handleAssetsUpdateV5` / `#handleAssetsUpdateV6` are replaced by **`buildUpdateSources`** (Accounts API and other non-websocket updates) and **`buildWsUpdateSources`** (AccountActivity websocket updates), mirroring the existing **`buildFastFetchSources`** pattern. Websocket lanes still differ by v5 vs v6 flags (custom-asset graduation vs RPC fallback, plus occurrence filtering on basic functionality). > > Adds **integration and unit coverage** for the websocket balance-update path: metadata and spot prices land in the **same pass** as a `AccountActivityService:balanceUpdated` event (new holdings, held-but-unpriced natives, and skipping re-price/refetch for already-enriched tokens), exercised both through **`executeAssetsPipeline`** and full **`AssetsController`** runs on v5 and **`assetsAccountsApiV6`** v6 lanes. > > Ships recorded API **fixtures** under `__fixtures__/ws-price-updates/` and a **`captureWsApiResponses.ts`** script to refresh them. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1a942e6. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
After a WS event we didnt call price API for updating existing or new tokens
References
Checklist
Note
Medium Risk
Changes real-time balance merge behavior and native asset ID resolution for Bitcoin; incorrect enrichment could affect displayed balances/prices until the next fetch, but scope is limited to Account Activity and native seeding.
Overview
Account Activity websocket updates now merge balances only (plus optional balance
metadatafrom the payload) and no longer emit stubassetsInfobuilt fromgetAssetType. ThegetAssetTypedependency is removed fromAccountActivityDataSourceandAssetsControllerwiring.Each websocket-driven
handleAssetsUpdatecall now requestsmetadataandpriceenrichment (dataTypes: ['balance', 'metadata', 'price']), so assets first seen on the websocket get proper metadata and a spot price in the same pipeline pass instead of waiting for a later poll.Bitcoin mainnet is added to
NATIVE_ASSETS(bip122:…/slip44:0), so native BTC resolution no longer falls back to a boguserc20:0x000…000asset id when seeding zero balances or resolving#getNativeAssetForChain.Reviewed by Cursor Bugbot for commit 4c1b52f. Bugbot is set up for automated code reviews on this repo. Configure here.