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 e615e8f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
5 changes: 3 additions & 2 deletions integration/src/wallets/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export function createInfo(): core.HDWalletInfo {
}

export async function createWallet(): Promise<core.HDWallet> {
const wallet = new metamask.MetaMaskHDWallet();
await wallet.initialize();
const keyring = new core.Keyring();
const adapter = metamask.MetaMaskAdapter.useKeyring(keyring);
const wallet = await adapter.pairDevice()
return wallet;
}

Expand Down
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 e615e8f

Please sign in to comment.