Skip to content

Commit 21a584b

Browse files
authored
Pass isInitializingStreamProvider to metamask_getProviderState (#422)
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).
1 parent 5b3055f commit 21a584b

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/StreamProvider.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe('StreamProvider', () => {
6262
expect(requestMock).toHaveBeenCalledTimes(1);
6363
expect(requestMock).toHaveBeenCalledWith({
6464
method: 'metamask_getProviderState',
65+
params: { isInitializingStreamProvider: true },
6566
});
6667
});
6768

src/StreamProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export abstract class AbstractStreamProvider extends BaseProvider {
113113
try {
114114
initialState = (await this.request({
115115
method: 'metamask_getProviderState',
116+
params: { isInitializingStreamProvider: true },
116117
})) as Parameters<BaseProvider['_initializeState']>[0];
117118
} catch (error) {
118119
this._log.error(

0 commit comments

Comments
 (0)