Skip to content

feat: source PreferencesController from @metamask/wallet#32346

Draft
sirtimid wants to merge 4 commits into
mainfrom
sirtimid/adopt-wallet-preferences-controller
Draft

feat: source PreferencesController from @metamask/wallet#32346
sirtimid wants to merge 4 commits into
mainfrom
sirtimid/adopt-wallet-preferences-controller

Conversation

@sirtimid

Copy link
Copy Markdown
Member

Description

Sources PreferencesController from @metamask/wallet's default controller set instead of mobile's own wiring, validated against a core preview build of core#9232.

Mobile already used the package @metamask/preferences-controller unchanged, so there's no override — it resolves the wallet-owned instance and only seeds initial state. Mirrors the prior Keyring/Accounts/Connectivity/RFFC adoptions:

  • Delete the local preferences-controller-init.ts / -messenger.ts (+ tests).
  • Drop it from the init registry, MESSENGER_FACTORIES, and MessengerClientsToInitialize; keep it in MessengerClients, EngineState, the Actions/Events unions, and BACKGROUND_STATE_CHANGE_EVENT_NAMES.
  • Resolve via wallet.getInstance('PreferencesController').
  • Seed mobile's defaults via state.PreferencesController (new wallet-init/instance-options/preferences-controller.ts), since the package controller takes no instance options. Persisted state wins.

Also drops now-obsolete PreferencesState casts in the preferences selectors (those fields are upstream now).

The preview pin lives in a TEMP chore: commit — bump to the real @metamask/wallet release once core#9232 ships, and drop that commit.

Changelog

CHANGELOG entry: null

Related issues

Refs: MetaMask/core#9232

Manual testing steps

Verified locally: yarn install --immutable, yarn dedupe --check, yarn lint:tsc, and yarn lint all clean (only the pre-existing unrelated termsOfUse tsc noise). Install resolves @metamask/wallet to the preview, which wires PreferencesController by default.

On a simulator (not run here): boot the app, confirm no duplicate PreferencesController registration, and that a preferences-driven flow (NFT detection / IPFS gateway / privacy mode) applies defaults on a fresh install and persists across relaunch.

Screenshots/Recordings

N/A — no user-facing UI change.

Before

After

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

🤖 Generated with Claude Code

sirtimid and others added 3 commits June 24, 2026 18:13
Temporarily alias @metamask/wallet to the published core preview
@metamask-previews/wallet@4.0.0-preview-55f166437 (branch
sirtimid/wire-preferences-controller, core#9232), which wires
PreferencesController into the wallet's default controller set.

This is an integration-prototype pin: bump it to the real
@metamask/wallet release once core#9232 ships, and drop this commit.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ntegration)

Adopt the wallet-owned PreferencesController now that core#9232 wires the
package @metamask/preferences-controller into @metamask/wallet's default
controller set. Mobile already ran the package controller unchanged (its
local init/messenger delegated nothing), so no override config is needed —
mobile resolves the wallet's default instance and only seeds its own initial
state.

Mirroring the prior Keyring/Accounts/Connectivity/RFFC adoptions:
- Delete the standalone preferences-controller-init.ts and
  preferences-controller-messenger.ts (+ tests).
- Drop PreferencesController from the init registry (Engine.ts initFunctions),
  the MESSENGER_FACTORIES map, and the MessengerClientsToInitialize union.
- Keep it in the MessengerClients type, EngineState, the Actions/Events
  unions, and BACKGROUND_STATE_CHANGE_EVENT_NAMES so background/Redux state
  and consuming selectors keep working.
- Resolve it via this.#wallet.getInstance('PreferencesController') (with the
  existing messengerClientsByName fallback in getMessengerClientOrThrow).

The package controller exposes no instance-options slot, so mobile's defaults
(IPFS gateway, detection toggles, smart-transactions opt-in, token sort order)
are seeded through WalletOptions.state.PreferencesController via the new
wallet-init/instance-options/preferences-controller.ts builder (alongside the
other per-controller wallet wiring). Persisted state is spread last so a
returning user's saved preferences win — identical to the deleted init.

Add a CODEOWNERS entry for the new builder owned by @MetaMask/mobile-platform
and @MetaMask/core-platform, matching the other wallet-init instance-options.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
isMultiAccountBalancesEnabled, showTestNetworks, isIpfsGatewayEnabled,
securityAlertsEnabled and useTransactionSimulations are now real fields on
the upstream @metamask/preferences-controller PreferencesState, so the
`as PreferencesState & {...}` casts (and the stale comments referencing the
long-removed @MetaMask+preferences-controller+2.1.0.patch) are dead weight.
Access them directly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. label Jun 24, 2026
@mm-token-exchange-service mm-token-exchange-service Bot added the team-ocap-kernel Ocap Kernel team label Jun 24, 2026
@sirtimid sirtimid changed the title feat: source PreferencesController from @metamask/wallet (core#9232 integration) feat: source PreferencesController from @metamask/wallet Jun 24, 2026
@sirtimid sirtimid added no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed and removed pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. labels Jun 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeAccounts, SmokeConfirmations, SmokeNetworkAbstractions, SmokeNetworkExpansion, SmokeSwap, SmokeStake, SmokeWalletPlatform, SmokeMoney, SmokePerps, SmokeMultiChainAPI, SmokePredictions, SmokeSeedlessOnboarding, SmokeBrowser, SmokeSnaps
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: high
  • AI Confidence: 100%
click to see 🤖 AI reasoning details

E2E Test Selection:
Hard rule (global-infrastructure-change): Global infrastructure changed: app/core/Engine/Engine.ts. Running all tests.

Performance Test Selection:
The changes are architectural refactoring of PreferencesController initialization - moving from a messenger-client init pattern to wallet.getInstance() pattern. While this affects many features, the changes are about initialization pathway and state seeding, not rendering performance or UI responsiveness. No performance-sensitive flows (account list rendering, onboarding, login, swaps, app launch, asset loading) are directly impacted by this refactoring. The @metamask/wallet preview package change could theoretically affect performance, but there's no evidence of performance-impacting changes in the diff. No performance test tags are warranted.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed size-M team-ocap-kernel Ocap Kernel team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant