From 6f731a4ecf4d8894e8970f5edb63cea9d29bcb3e Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Thu, 4 Sep 2025 13:41:05 -0600 Subject: [PATCH] Pass isInitializingStream to metamask_getProviderState In order to initialize the state of the StreamProvider, `metamask_getProviderState` must be called. In the extension, the current implementation of this RPC method retrieves the network version of the currently selected network via `net_version` and returns it along with other information. This creates a problem, however. Because the StreamProvider must be initialized in order to load the UI, if the network is slow or unresponsive, then users will see an infinite spinner until the request is resolved. To fix this, we inform the RPC method that the StreamProvider is being initialized. The idea is that for this special case, the extension will opt not to make a request for the network version, returning "loading". For requests for `metamask_getProviderState` outside of StreamProvider this will not be the case and the network version will be retrieved as usual. This means that StreamProvider will not have a network version initially. However, while they do expect `metamask_getProviderState` to return a `networkVersion` property, neither BaseProvider nor StreamProvider seem to do anything with it (unlike MetaMaskInpageProvider, which tracks it and allows dapps to read it). --- src/StreamProvider.test.ts | 1 + src/StreamProvider.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/StreamProvider.test.ts b/src/StreamProvider.test.ts index 122b9a41..c53b76a6 100644 --- a/src/StreamProvider.test.ts +++ b/src/StreamProvider.test.ts @@ -62,6 +62,7 @@ describe('StreamProvider', () => { expect(requestMock).toHaveBeenCalledTimes(1); expect(requestMock).toHaveBeenCalledWith({ method: 'metamask_getProviderState', + params: { isInitializingStreamProvider: true }, }); }); diff --git a/src/StreamProvider.ts b/src/StreamProvider.ts index 69faeb13..ef72092e 100644 --- a/src/StreamProvider.ts +++ b/src/StreamProvider.ts @@ -113,6 +113,7 @@ export abstract class AbstractStreamProvider extends BaseProvider { try { initialState = (await this.request({ method: 'metamask_getProviderState', + params: { isInitializingStreamProvider: true }, })) as Parameters[0]; } catch (error) { this._log.error(