Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ const baseConfig = {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 69.63,
functions: 71.42,
lines: 70.27,
statements: 70.4,
branches: 70.2,
functions: 72.07,
lines: 71.03,
statements: 71.16,
},
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type ExtensionType = 'stable' | 'flask' | 'beta' | string;

/**
* Creates an external extension provider for the given extension type or ID.
* This is intended for use by 3rd party extensions.
*
* @param typeOrId - The extension type or ID.
* @returns The external extension provider.
Expand Down
33 changes: 6 additions & 27 deletions src/initializeInpageProvider.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import ObjectMultiplex from '@metamask/object-multiplex';
import { type Duplex, pipeline } from 'readable-stream';
import { type Duplex } from 'readable-stream';

import type { CAIP294WalletData } from './CAIP294';
import { announceWallet } from './CAIP294';
import { announceProvider as announceEip6963Provider } from './EIP6963';
import { getBuildType } from './extension-provider/createExternalExtensionProvider';
import type { MetaMaskInpageProviderOptions } from './MetaMaskInpageProvider';
import {
MetaMaskInpageProvider,
MetaMaskInpageProviderStreamName,
} from './MetaMaskInpageProvider';
import { MetaMaskInpageProvider } from './MetaMaskInpageProvider';
import { shimWeb3 } from './shimWeb3';
import type { BaseProviderInfo } from './types';

Expand All @@ -33,18 +29,13 @@ type InitializeProviderOptions = {
* Whether the window.web3 shim should be set.
*/
shouldShimWeb3?: boolean;
/**
* The name of the stream used to connect to the wallet.
*/
jsonRpcStreamName?: string;
} & MetaMaskInpageProviderOptions;

/**
* Initializes a MetaMaskInpageProvider and (optionally) assigns it as window.ethereum.
*
* @param options - An options bag.
* @param options.connectionStream - A Node.js stream.
* @param options.jsonRpcStreamName - The name of the internal JSON-RPC stream.
* @param options.maxEventListeners - The maximum number of event listeners.
* @param options.providerInfo - The EIP-6963 provider info / CAIP-294 wallet data that should be announced if set.
* @param options.shouldSendMetadata - Whether the provider should send page metadata.
Expand All @@ -55,30 +46,18 @@ type InitializeProviderOptions = {
*/
export function initializeProvider({
connectionStream,
jsonRpcStreamName = MetaMaskInpageProviderStreamName,
logger = console,
maxEventListeners = 100,
providerInfo,
shouldSendMetadata = true,
shouldSetOnWindow = true,
shouldShimWeb3 = false,
}: InitializeProviderOptions): MetaMaskInpageProvider {
const mux = new ObjectMultiplex();
pipeline(connectionStream, mux, connectionStream, (error: Error | null) => {
let warningMsg = `Lost connection to "${jsonRpcStreamName}".`;
if (error?.stack) {
warningMsg += `\n${error.stack}`;
}
console.warn(warningMsg);
const provider = new MetaMaskInpageProvider(connectionStream, {
logger,
maxEventListeners,
shouldSendMetadata,
});
const provider = new MetaMaskInpageProvider(
mux.createStream(jsonRpcStreamName),
{
logger,
maxEventListeners,
shouldSendMetadata,
},
);

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