Skip to content

Commit

Permalink
metamask: only detectEthereumProvider() once
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnerdhair committed Feb 11, 2022
1 parent fc5e32f commit 3f73754
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/hdwallet-metamask/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 5 additions & 8 deletions packages/hdwallet-metamask/src/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,11 @@ export class MetaMaskHDWallet implements core.HDWallet, core.ETHWallet {
return Promise.resolve("MetaMask");
}

public async initialize(): Promise<any> {
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<any>;
public async initialize(provider?: unknown): Promise<any> {
if (!provider) throw new Error("provider is required");
this.provider = provider;
}

public hasOnDevicePinEntry(): boolean {
Expand Down

0 comments on commit 3f73754

Please sign in to comment.