Skip to content

Commit dab189b

Browse files
authored
feat: remove substream instantiation from initializeProvider (#410)
* add comment about createExternalExtensionProvider * remove jsonRpCStreamName and substream instantiation from initializeProvider()
1 parent faf44f8 commit dab189b

File tree

3 files changed

+11
-31
lines changed

3 files changed

+11
-31
lines changed

jest.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ const baseConfig = {
4545
// An object that configures minimum threshold enforcement for coverage results
4646
coverageThreshold: {
4747
global: {
48-
branches: 69.63,
49-
functions: 71.42,
50-
lines: 70.27,
51-
statements: 70.4,
48+
branches: 70.2,
49+
functions: 72.07,
50+
lines: 71.03,
51+
statements: 71.16,
5252
},
5353
},
5454

src/extension-provider/createExternalExtensionProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type ExtensionType = 'stable' | 'flask' | 'beta' | string;
1515

1616
/**
1717
* Creates an external extension provider for the given extension type or ID.
18+
* This is intended for use by 3rd party extensions.
1819
*
1920
* @param typeOrId - The extension type or ID.
2021
* @returns The external extension provider.

src/initializeInpageProvider.ts

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
import ObjectMultiplex from '@metamask/object-multiplex';
2-
import { type Duplex, pipeline } from 'readable-stream';
1+
import { type Duplex } from 'readable-stream';
32

43
import type { CAIP294WalletData } from './CAIP294';
54
import { announceWallet } from './CAIP294';
65
import { announceProvider as announceEip6963Provider } from './EIP6963';
76
import { getBuildType } from './extension-provider/createExternalExtensionProvider';
87
import type { MetaMaskInpageProviderOptions } from './MetaMaskInpageProvider';
9-
import {
10-
MetaMaskInpageProvider,
11-
MetaMaskInpageProviderStreamName,
12-
} from './MetaMaskInpageProvider';
8+
import { MetaMaskInpageProvider } from './MetaMaskInpageProvider';
139
import { shimWeb3 } from './shimWeb3';
1410
import type { BaseProviderInfo } from './types';
1511

@@ -33,18 +29,13 @@ type InitializeProviderOptions = {
3329
* Whether the window.web3 shim should be set.
3430
*/
3531
shouldShimWeb3?: boolean;
36-
/**
37-
* The name of the stream used to connect to the wallet.
38-
*/
39-
jsonRpcStreamName?: string;
4032
} & MetaMaskInpageProviderOptions;
4133

4234
/**
4335
* Initializes a MetaMaskInpageProvider and (optionally) assigns it as window.ethereum.
4436
*
4537
* @param options - An options bag.
4638
* @param options.connectionStream - A Node.js stream.
47-
* @param options.jsonRpcStreamName - The name of the internal JSON-RPC stream.
4839
* @param options.maxEventListeners - The maximum number of event listeners.
4940
* @param options.providerInfo - The EIP-6963 provider info / CAIP-294 wallet data that should be announced if set.
5041
* @param options.shouldSendMetadata - Whether the provider should send page metadata.
@@ -55,30 +46,18 @@ type InitializeProviderOptions = {
5546
*/
5647
export function initializeProvider({
5748
connectionStream,
58-
jsonRpcStreamName = MetaMaskInpageProviderStreamName,
5949
logger = console,
6050
maxEventListeners = 100,
6151
providerInfo,
6252
shouldSendMetadata = true,
6353
shouldSetOnWindow = true,
6454
shouldShimWeb3 = false,
6555
}: InitializeProviderOptions): MetaMaskInpageProvider {
66-
const mux = new ObjectMultiplex();
67-
pipeline(connectionStream, mux, connectionStream, (error: Error | null) => {
68-
let warningMsg = `Lost connection to "${jsonRpcStreamName}".`;
69-
if (error?.stack) {
70-
warningMsg += `\n${error.stack}`;
71-
}
72-
console.warn(warningMsg);
56+
const provider = new MetaMaskInpageProvider(connectionStream, {
57+
logger,
58+
maxEventListeners,
59+
shouldSendMetadata,
7360
});
74-
const provider = new MetaMaskInpageProvider(
75-
mux.createStream(jsonRpcStreamName),
76-
{
77-
logger,
78-
maxEventListeners,
79-
shouldSendMetadata,
80-
},
81-
);
8261

8362
const proxiedProvider = new Proxy(provider, {
8463
// some common libraries, e.g. web3@1.x, mess with our API

0 commit comments

Comments
 (0)