feat(wallet): wire PreferencesController into default initialization#9232
feat(wallet): wire PreferencesController into default initialization#9232sirtimid wants to merge 5 commits into
PreferencesController into default initialization#9232Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
e951604 to
a8fd340
Compare
There was a problem hiding this comment.
Before we can do this, we will need metamask-extension and metamask-mobile to both be using PreferencesController from core.
Today they have diverged unfortunately.
EDIT: In theory, we may be able to wire in PreferencesController to wallet and override the initialization on extension to use the diverging version. But will depend on whether their state overlaps enough.
@FrederikBolding Mobile is already on vanilla core |
|
@metamaskbot publish-previews |
Yeah, I realized that and added my EDIT. Have you verified that the controller state on extension is a superset of the We should de-risk by creating integration PRs regardless! |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
|
@metamaskbot publish-previews |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Add an integration test asserting PreferencesController.setAccountLabel routes through the wallet-delegated AccountsController:getAccountByAddress / :setAccountName (real wallet + override). Trim the override comments to the essential rationale and tie both runtime casts to MetaMask/core#9232 for removal once it ships. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
55f1664 to
68c1526
Compare
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
68c1526 to
a7c0a88
Compare
Add an integration test asserting PreferencesController.setAccountLabel routes through the wallet-delegated AccountsController:getAccountByAddress / :setAccountName (real wallet + override). Trim the override comments to the essential rationale and tie both runtime casts to MetaMask/core#9232 for removal once it ships. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add `PreferencesController` to the default wallet initialization set. It has no cross-controller messenger dependencies and its only constructor inputs are `messenger` and `state`, so it wires with a plain namespaced child messenger and no `instanceOptions` slot — per-client values are supplied through the existing `state.PreferencesController` initial state. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Prove a consumer can keep a diverging superset PreferencesController by supplying its own initialization configuration under the same name, which overrides the package default — the adoption path for clients (e.g. the extension) that cannot converge to the package controller's state shape. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Re-export `InitializationConfiguration`, `InitFunctionArguments`, and `InstanceState` from the package root so consumers can annotate their own initialization configurations that override a default controller (e.g. the extension overriding the default `PreferencesController`). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@FrederikBolding check the adoption PRs Extension — MetaMask/metamask-extension#43851 |
Drop the verbose breaking-change sub-bullet to match the one-line style of the other default-controller wiring entries. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
a7c0a88 to
4f9d41d
Compare
|
@metamaskbot publish-previews |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Explanation
Wires the
@metamask/preferences-controllerpackage into@metamask/wallet's default initialization. The defaultWalletnow constructs aPreferencesControllerand registers itsPreferencesController:*messenger actions (getState/stateChangeplus the preference setters), sowallet.state.PreferencesControllerand calls likePreferencesController:setIpfsGatewaywork out of the box.@metamask/walletis the shared controller-integration layer that the extension, mobile, and other clients adopt, so each controller is wired once here.PreferencesControllertakes no client-varying constructor values, so it needs no injectableinstanceOptions. Consumers can still replace the default by supplying aninitializationConfigurationsentry withname: 'PreferencesController'(e.g. a client-specific superset controller); this PR also exportsInitializationConfiguration,InitFunctionArguments, andInstanceStateso consumers can author that override.BREAKING: Clients that pass their own
messengerand already register aPreferencesControllermust drop that wiring before upgrading, or the duplicate messenger registration will collide. The adoption PRs below do exactly that.References
Client adoption PRs (construct
PreferencesControllerthrough@metamask/walletand delete the bespoke client init):Client construction sites (live
main):Jira: N/A
Checklist
🤖 Generated with Claude Code
Note
Medium Risk
Marked breaking because default init adds a new controller and messenger actions; adopters must dedupe or override existing PreferencesController wiring, though behavior is covered by tests and matches prior controllers like AddressBook.
Overview
BREAKING: Default
Walletinitialization now constructs@metamask/preferences-controllerand registersPreferencesController:*messenger actions on the root messenger (state, setters such assetIpfsGateway). Consumers that already wire their ownPreferencesControlleron the same messenger must remove or override it to avoid duplicate registration.Adds a
preferencesControllerinitialization module (same pattern as other default controllers), depends on@metamask/preferences-controller, and exportsInitializationConfiguration,InitFunctionArguments, andInstanceStateso clients can supply aninitializationConfigurationsentry withname: 'PreferencesController'to replace the default (e.g. extension/mobile superset controllers).Tests cover default wiring, constructor initial state, messenger routing, and override behavior; docs/changelog/CODEOWNERS/README dependency graph updated.
Reviewed by Cursor Bugbot for commit 4f9d41d. Bugbot is set up for automated code reviews on this repo. Configure here.