Skip to content

fix(assets-controller): price update for AccountActivity updates - #10410

Merged
Kriys94 merged 2 commits into
mainfrom
fix/MiscFixes
Sep 24, 2026
Merged

Kriys94 merged 2 commits into
mainfrom
fix/MiscFixes

Conversation

@Kriys94

@Kriys94 Kriys94 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

After a WS event we didnt call price API for updating existing or new tokens

References

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
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

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 metadata from the payload) and no longer emit stub assetsInfo built from getAssetType. The getAssetType dependency is removed from AccountActivityDataSource and AssetsController wiring.

Each websocket-driven handleAssetsUpdate call now requests metadata and price enrichment (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 bogus erc20:0x000…000 asset 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.

@Kriys94
Kriys94 marked this pull request as ready for review September 23, 2026 18:02
@Kriys94
Kriys94 requested review from a team as code owners September 23, 2026 18:02
@Kriys94
Kriys94 deployed to default-branch September 23, 2026 18:02 — with GitHub Actions Active
@Kriys94 Kriys94 changed the title Fix/misc fixes fix(assets-controller): price update for AccountActivity updates Sep 23, 2026
function processAccountActivityBalanceUpdates(
updates: BalanceUpdate[],
accountId: string,
getAssetType: (assetId: Caip19AssetId) => 'native' | 'erc20' | 'spl',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice cleanup!

Comment on lines -93 to -98
assetsMetadata[assetId] = {
type: getAssetType(assetId),
symbol: asset.unit,
name: asset.unit,
decimals: asset.decimals,
};

@Prithpal-Sooriya Prithpal-Sooriya Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good removal - the metadata is managed by the TokenDataSource responsibility.

@Kriys94
Kriys94 added this pull request to the merge queue Sep 24, 2026
Merged via the queue into main with commit ee641b1 Sep 24, 2026
55 checks passed
@Kriys94
Kriys94 deleted the fix/MiscFixes branch September 24, 2026 10:11
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

1 active deployment
default-branch — 4c1b52fe Deployed Sep 23, 2026 by Kriys94 via Determine whether this PR is a release PR #4521
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants