-
-
Notifications
You must be signed in to change notification settings - Fork 276
feat(AssetsController): Basic functionality #7904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
70f54ca to
ab7be4d
Compare
ab7be4d to
ca3eb14
Compare
| const [{ state = {}, isBasicFunctionality }, fn] = | ||
| args.length === 2 ? args : [{}, args[0]]; |
There was a problem hiding this comment.
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?
| 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 }), |
There was a problem hiding this comment.
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?
| ...(isBasicFunctionality !== undefined && { isBasicFunctionality }), | |
| isBasicFunctionality, |
| if (this.#isBasicFunctionality()) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
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
Co-authored-by: Cursor <[email protected]>
caba589 to
c43b62c
Compare
3dcf715 to
5800da2
Compare
There was a problem hiding this 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.
5800da2 to
6255df2
Compare
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.subscribeAssetsPricereturns 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).#subscriptionBalanceDataSourcesgetter is inlined into#subscribeAssetsBalance(basic:[this.#rpcDataSource], otherwisethis.#allBalanceDataSources).Are there any changes whose purpose might not be obvious?
isBasicparameter tohandleBasicFunctionalityChangeis for call-site clarity only; the getter remains the source of truth when the controller runs.#allBalanceDataSourcesis 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-controllerwas modified.If you had to upgrade a dependency, why did you do so?
No dependency upgrades in this PR.
References
packages/assets-controller/CHANGELOG.md.Checklist
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
AssetsControllervia new constructor optionsisBasicFunctionality()andsubscribeToBasicFunctionalityChange(onChange), plus a publichandleBasicFunctionalityChangeto 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
forceUpdatefetches, and disablessubscribeAssetsPriceentirely; cleanup logic is updated to unsubscribe from all balance sources regardless of mode. Tests and docs are updated, and@metamask/preferences-controlleris added as a dependency/type reference.Written by Cursor Bugbot for commit 6255df2. This will update automatically on new commits. Configure here.