Skip to content

Conversation

@Kriys94
Copy link
Contributor

@Kriys94 Kriys94 commented Feb 11, 2026

Explanation

What is the current state of things and why does it need to change?

The AssetsController always uses all balance data sources (BackendWebsocket, AccountsApi, Snap, RPC) for balance fetch and subscribe, and the API for metadata and price. Extension and mobile need a way to run in a "basic functionality" mode where only RPC is used for balance and token/price APIs are not used (e.g. when the user opts in or in constrained environments).

What is the solution your changes offer and how does it work?

  • isBasicFunctionality — Optional constructor option: a getter () => boolean. No value is stored in the controller; the getter is invoked when deciding which data sources to use.
  • When the getter returns true: only balance fetch and balance subscribe use RPC (RpcDataSource only). Token and price APIs are not used: the force-update fetch path omits token and price middlewares (no metadata/price from API), and subscribeAssetsPrice returns early (no price subscription). So in basic mode, getAssets / getAssetsBalance / getAssetsPrice and price subscription do not call the token or price API.
  • handleBasicFunctionalityChange(isBasic: boolean) — New public method. The consumer (extension/mobile) calls it when the user toggles the setting; it stops current subscriptions and re-subscribes so the next run uses the current getter value (RPC-only vs full balance sources).
  • The logic that lived in a #subscriptionBalanceDataSources getter is inlined into #subscribeAssetsBalance (basic: [this.#rpcDataSource], otherwise this.#allBalanceDataSources).

Are there any changes whose purpose might not be obvious?

  • The isBasic parameter to handleBasicFunctionalityChange is for call-site clarity only; the getter remains the source of truth when the controller runs.
  • #allBalanceDataSources is still used in #stop() so we can unsubscribe from every balance source when tearing down (e.g. when switching from full to basic).

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?

N/A — only @metamask/assets-controller was modified.

If you had to upgrade a dependency, why did you do so?

No dependency upgrades in this PR.

References

  • Changelog updated in this repo: packages/assets-controller/CHANGELOG.md.
  • No related issues or client/consumer PRs linked; additive API for extension/mobile to adopt when they add the basic functionality toggle.

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
Touches core asset fetch/subscription routing and selectively disables price/metadata enrichment, which could change observed balances/prices and subscription lifecycles if the toggle is miswired or races with initialization.

Overview
Adds an opt-in basic functionality mode to AssetsController via new constructor options isBasicFunctionality() and subscribeToBasicFunctionalityChange(onChange), plus a public handleBasicFunctionalityChange to tear down and re-subscribe when the setting flips.

When basic functionality is off, the controller switches to RPC-only balance subscriptions, skips token/price middlewares during forceUpdate fetches, and disables subscribeAssetsPrice entirely; cleanup logic is updated to unsubscribe from all balance sources regardless of mode. Tests and docs are updated, and @metamask/preferences-controller is added as a dependency/type reference.

Written by Cursor Bugbot for commit 6255df2. This will update automatically on new commits. Configure here.

@Kriys94 Kriys94 force-pushed the feature/AssetsBasicFuntionality branch 2 times, most recently from 70f54ca to ab7be4d Compare February 11, 2026 14:43
@Kriys94 Kriys94 marked this pull request as ready for review February 11, 2026 14:44
@Kriys94 Kriys94 requested review from a team as code owners February 11, 2026 14:44
@Kriys94 Kriys94 force-pushed the feature/AssetsBasicFuntionality branch from ab7be4d to ca3eb14 Compare February 11, 2026 15:03
Comment on lines 81 to 82
const [{ state = {}, isBasicFunctionality }, fn] =
args.length === 2 ? args : [{}, args[0]];
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - Hmmm unsure if types are lost, can we add strict types?

Suggested change
const [{ state = {}, isBasicFunctionality }, fn] =
args.length === 2 ? args : [{}, args[0]];
const [{ state = {}, isBasicFunctionality }, fn]: [
WithControllerOptions,
WithControllerCallback<ReturnValue>,
] = args.length === 2 ? args : [{}, args[0]];

messenger: messenger as unknown as AssetsControllerMessenger,
state,
queryApiClient: createMockQueryApiClient(),
...(isBasicFunctionality !== undefined && { isBasicFunctionality }),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - can this be simplified?

Suggested change
...(isBasicFunctionality !== undefined && { isBasicFunctionality }),
isBasicFunctionality,

Comment on lines 967 to 969
if (this.#isBasicFunctionality()) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same double check for me, I think this is inverted lol

@Kriys94 Kriys94 force-pushed the feature/AssetsBasicFuntionality branch from caba589 to c43b62c Compare February 12, 2026 12:37
@Kriys94 Kriys94 force-pushed the feature/AssetsBasicFuntionality branch from 3dcf715 to 5800da2 Compare February 12, 2026 16:50
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@Kriys94 Kriys94 force-pushed the feature/AssetsBasicFuntionality branch from 5800da2 to 6255df2 Compare February 12, 2026 17:05
@Kriys94 Kriys94 enabled auto-merge February 12, 2026 17:10
@Kriys94 Kriys94 added this pull request to the merge queue Feb 12, 2026
Merged via the queue into main with commit 21091eb Feb 12, 2026
302 checks passed
@Kriys94 Kriys94 deleted the feature/AssetsBasicFuntionality branch February 12, 2026 17:16
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