MetaMask / MetaMask/core

wallet: Make `fetch` injectable in `NetworkController` initialization

Open
#8,793 0 comments 0 reactions 1 assignee Claimed by @grypez View on GitHub
team-ocap-kernel
Dominant language
TypeScript
Stars
413
Forks
308
Avg merge
1d 4h
Merged PRs (30d)
253

Description

### Problem

`getRpcServiceOptions` in `packages/wallet/src/initialization/instances/network-controller.ts` hardcodes `fetch` to `globalThis.fetch`. Platforms that provide their own fetch implementation — React Native being the primary example — cannot supply it, making the wallet non-portable across those environments.

### Proposed direction

Add an optional `fetch?: typeof globalThis.fetch` field to `WalletOptions`. The `NetworkController` init should use `options.fetch ?? globalThis.fetch.bind(globalThis)` when building `getRpcServiceOptions`, so the default behaviour is unchanged and platform-specific implementations can be injected at construction time.

### Acceptance

- `WalletOptions` has an optional `fetch` field.
- `getRpcServiceOptions` uses the injected fetch when provided, falling back to `globalThis.fetch`.
- Existing tests pass; a test covers the injected-fetch path.
- Changelog entry added.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.