Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bitbox02 does not work in Firefox #2735

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
16 changes: 9 additions & 7 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3474,9 +3474,9 @@ export class WalletController extends BaseController {
} catch {
const Keyring = keyringService.getKeyringClassForType(type);
keyring = new Keyring(
hasBridge(type)
(await hasBridge(type))
? {
bridge: getKeyringBridge(type),
bridge: await getKeyringBridge(type),
}
: undefined
);
Expand Down Expand Up @@ -3542,7 +3542,7 @@ export class WalletController extends BaseController {
keyringType
);
keyring = new keystoneKeyring({
bridge: getKeyringBridge(keyringType),
bridge: await getKeyringBridge(keyringType),
});
stashKeyringId = Object.values(stashKeyrings).length + 1;
stashKeyrings[stashKeyringId] = keyring;
Expand Down Expand Up @@ -3571,7 +3571,7 @@ export class WalletController extends BaseController {
keyringType
);
keyring = new keystoneKeyring({
bridge: getKeyringBridge(keyringType),
bridge: await getKeyringBridge(keyringType),
});
stashKeyringId = Object.values(stashKeyrings).length + 1;
stashKeyrings[stashKeyringId] = keyring;
Expand Down Expand Up @@ -3717,7 +3717,7 @@ export class WalletController extends BaseController {
return keyring.getEncryptionPublicKey(address, options);
};

requestKeyring = (
requestKeyring = async (
type: string,
methodName: string,
keyringId: number | null,
Expand All @@ -3732,7 +3732,9 @@ export class WalletController extends BaseController {
} catch {
const Keyring = keyringService.getKeyringClassForType(type);
keyring = new Keyring(
hasBridge(type) ? { bridge: getKeyringBridge(type) } : undefined
(await hasBridge(type))
? { bridge: await getKeyringBridge(type) }
: undefined
);
}
}
Expand Down Expand Up @@ -4379,7 +4381,7 @@ export class WalletController extends BaseController {
keyringType
);
keyring = new keystoneKeyring({
bridge: getKeyringBridge(keyringType),
bridge: await getKeyringBridge(keyringType),
});
stashKeyringId = this.addKeyringToStash(keyring);
}
Expand Down
16 changes: 8 additions & 8 deletions src/background/service/keyring/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ const BitBox02Bridge = isManifestV3
? require('./eth-bitbox02-keyring/bitbox02-offscreen-bridge')
: require('./eth-bitbox02-keyring/bitbox02-bridge');

export function getKeyringBridge(type: string) {
export const getKeyringBridge = async (type: string) => {
if (type === KEYRING_CLASS.HARDWARE.IMKEY) {
return new ImKeyBridge.default();
return new (await ImKeyBridge).default();
}

if (type === KEYRING_CLASS.HARDWARE.ONEKEY) {
return new OneKeyBridge.default();
return new (await OneKeyBridge).default();
}

if (type === KEYRING_CLASS.HARDWARE.TREZOR) {
return new TrezorBridge.default();
return new (await TrezorBridge).default();
}

if (type === KEYRING_CLASS.HARDWARE.BITBOX02) {
return new BitBox02Bridge.default();
return new (await BitBox02Bridge).default();
}

return;
}
};

export const hasBridge = (type: string) => {
return !!getKeyringBridge(type);
export const hasBridge = async (type: string) => {
return !!(await getKeyringBridge(type));
};
10 changes: 5 additions & 5 deletions src/background/service/keyring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,12 @@ export class KeyringService extends EventEmitter {
* @param {Object} opts - The constructor options for the keyring.
* @returns {Promise<Keyring>} The new keyring.
*/
addNewKeyring(type: string, opts?: any): Promise<any> {
async addNewKeyring(type: string, opts?: any): Promise<any> {
const Keyring = this.getKeyringClassForType(type);
const keyring = new Keyring(
hasBridge(type)
(await hasBridge(type))
? {
bridge: getKeyringBridge(type),
bridge: await getKeyringBridge(type),
...(opts ?? {}),
}
: opts
Expand Down Expand Up @@ -920,9 +920,9 @@ export class KeyringService extends EventEmitter {
Keyring?.type === KEYRING_CLASS.WALLETCONNECT
? new Keyring(GET_WALLETCONNECT_CONFIG())
: new Keyring(
hasBridge(type)
(await hasBridge(type))
? {
bridge: getKeyringBridge(type),
bridge: await getKeyringBridge(type),
}
: undefined
);
Expand Down
Loading