From c01b3d507c40e72beb134f8e2bc8a5eefc6d94b4 Mon Sep 17 00:00:00 2001 From: grypez <143971198+grypez@users.noreply.github.com> Date: Mon, 18 May 2026 12:29:12 -0400 Subject: [PATCH] feat(wallet): add injectable fetch and prevClientVersion options - fetch: overrides the fetch implementation used by NetworkController's RPC service; defaults to globalThis.fetch. Allows platform-specific implementations (e.g. React Native) to be injected. - prevClientVersion: passed to RemoteFeatureFlagController to trigger feature-flag cache invalidation when the client version changes. Closes #8793, #8794 Co-Authored-By: Claude Sonnet 4.6 --- packages/wallet/CHANGELOG.md | 4 ++++ .../wallet/src/initialization/instances/network-controller.ts | 2 +- .../instances/remote-feature-flag-controller.ts | 1 + packages/wallet/src/types.ts | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/wallet/CHANGELOG.md b/packages/wallet/CHANGELOG.md index b8ff88c4ce..b8fc334a16 100644 --- a/packages/wallet/CHANGELOG.md +++ b/packages/wallet/CHANGELOG.md @@ -11,5 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `Wallet` class with a bundled controller ensemble (AccountsController, ApprovalController, ConnectivityController, KeyringController, NetworkController, RemoteFeatureFlagController, TransactionController) ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) - Pass `state` keyed by controller name to the constructor to hydrate from a stored snapshot. Subscribe to `${ControllerName}:stateChanged` events on `wallet.messenger` to write changes back to your storage backend. See the README for details. +- Add optional `prevClientVersion` field to `WalletOptions` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) + - Passed to `RemoteFeatureFlagController` to trigger cache invalidation when the client version changes. +- Add optional `fetch` field to `WalletOptions` ([#XXXX](https://github.com/MetaMask/core/pull/XXXX)) + - Overrides the `fetch` implementation used by `NetworkController`'s RPC service. Defaults to `globalThis.fetch`. Allows platform-specific fetch implementations (e.g. React Native) to be injected. [Unreleased]: https://github.com/MetaMask/core/ diff --git a/packages/wallet/src/initialization/instances/network-controller.ts b/packages/wallet/src/initialization/instances/network-controller.ts index 669d3d7d66..bc6383fdd1 100644 --- a/packages/wallet/src/initialization/instances/network-controller.ts +++ b/packages/wallet/src/initialization/instances/network-controller.ts @@ -24,7 +24,7 @@ export const networkController: InitializationConfiguration< > = { name: 'NetworkController', init: ({ state, messenger, options }) => { - const fetchFn = globalThis.fetch.bind(globalThis); + const fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis); const getRpcServiceOptions: NetworkControllerOptions['getRpcServiceOptions'] = () => { diff --git a/packages/wallet/src/initialization/instances/remote-feature-flag-controller.ts b/packages/wallet/src/initialization/instances/remote-feature-flag-controller.ts index 9690397313..05c5a54052 100644 --- a/packages/wallet/src/initialization/instances/remote-feature-flag-controller.ts +++ b/packages/wallet/src/initialization/instances/remote-feature-flag-controller.ts @@ -16,6 +16,7 @@ export const remoteFeatureFlagController: InitializationConfiguration< state, messenger, clientVersion: options.clientVersion, + prevClientVersion: options.prevClientVersion, clientConfigApiService: options.clientConfigApiService, getMetaMetricsId: options.getMetaMetricsId, }); diff --git a/packages/wallet/src/types.ts b/packages/wallet/src/types.ts index 865d6241e4..ed66f427f6 100644 --- a/packages/wallet/src/types.ts +++ b/packages/wallet/src/types.ts @@ -5,6 +5,8 @@ export type WalletOptions = { state?: Record>; infuraProjectId: string; clientVersion: string; + prevClientVersion?: string; + fetch?: typeof globalThis.fetch; showApprovalRequest: () => void; clientConfigApiService: ClientConfigApiService; getMetaMetricsId: () => string;