Skip to content

Commit b988048

Browse files
authored
Merge pull request #1107 from input-output-hk/fix/trezor-bundler-compatibility
fix: trezor bundler compatibility
2 parents 93a3294 + 1cd4582 commit b988048

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/hardware-ledger/src/LedgerKeyAgent.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ const LedgerConnection = (_LedgerConnection as any).default
4040
: _LedgerConnection;
4141
type LedgerConnection = _LedgerConnection;
4242

43+
const isDeviceAlreadyOpenError = (error: unknown) => {
44+
if (typeof error !== 'object') return false;
45+
const innerError = (error as any).innerError;
46+
if (typeof innerError !== 'object') return false;
47+
return (
48+
innerError.code === 11 ||
49+
(typeof innerError.message === 'string' && innerError.message.includes('cannot open device with path'))
50+
);
51+
};
52+
4353
export interface LedgerKeyAgentProps extends Omit<SerializableLedgerKeyAgentData, '__typename'> {
4454
deviceConnection?: LedgerConnection;
4555
}
@@ -223,7 +233,7 @@ export class LedgerKeyAgent extends KeyAgentBase {
223233
});
224234
return newConnection;
225235
} catch (error: any) {
226-
if (error.innerError.message.includes('cannot open device with path')) {
236+
if (isDeviceAlreadyOpenError(error)) {
227237
throw new errors.TransportError('Connection already established', error);
228238
}
229239
// If transport is established we need to close it so we can recover device from previous session

packages/hardware-trezor/src/TrezorKeyAgent.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ import {
1616
util
1717
} from '@cardano-sdk/key-management';
1818
import { txToTrezor } from './transformers/tx';
19-
import TrezorConnectWeb from '@trezor/connect-web';
19+
import _TrezorConnectWeb from '@trezor/connect-web';
2020

2121
const TrezorConnectNode = Trezor.default;
22+
const TrezorConnectWeb = (_TrezorConnectWeb as any).default
23+
? ((_TrezorConnectWeb as any).default as typeof _TrezorConnectWeb)
24+
: _TrezorConnectWeb;
2225

2326
const transportTypedError = (error?: any) =>
2427
new errors.AuthenticationError(

0 commit comments

Comments
 (0)