From 3f73754a88933ef20119eadd7da53100796715ec Mon Sep 17 00:00:00 2001 From: MrNerdHair Date: Fri, 11 Feb 2022 16:55:47 -0500 Subject: [PATCH] metamask: only detectEthereumProvider() once --- packages/hdwallet-metamask/src/adapter.ts | 2 +- packages/hdwallet-metamask/src/metamask.ts | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/hdwallet-metamask/src/adapter.ts b/packages/hdwallet-metamask/src/adapter.ts index f1d674dd9..b5422813e 100644 --- a/packages/hdwallet-metamask/src/adapter.ts +++ b/packages/hdwallet-metamask/src/adapter.ts @@ -35,7 +35,7 @@ export class MetaMaskAdapter { throw error; } const wallet = new MetaMaskHDWallet(); - await wallet.initialize(); + await wallet.initialize(provider); const deviceID = await wallet.getDeviceID(); this.keyring.add(wallet, deviceID); this.currentDeviceID = deviceID; diff --git a/packages/hdwallet-metamask/src/metamask.ts b/packages/hdwallet-metamask/src/metamask.ts index 73440a9c3..8f38c8139 100644 --- a/packages/hdwallet-metamask/src/metamask.ts +++ b/packages/hdwallet-metamask/src/metamask.ts @@ -77,14 +77,11 @@ export class MetaMaskHDWallet implements core.HDWallet, core.ETHWallet { return Promise.resolve("MetaMask"); } - public async initialize(): Promise { - try { - this.provider = await detectEthereumProvider({ mustBeMetaMask: true, silent: false, timeout: 3000 }); - } catch (e) { - console.error(e); - } - - return Promise.resolve(); + public initialize(): never; + public initialize(provider: unknown): Promise; + public async initialize(provider?: unknown): Promise { + if (!provider) throw new Error("provider is required"); + this.provider = provider; } public hasOnDevicePinEntry(): boolean {