Skip to content

Commit 49550e3

Browse files
committed
fix: [lw-12138] handle disconnected ledger wallet error
1 parent ad1b404 commit 49550e3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/hardware-ledger/src/LedgerKeyAgent.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,18 @@ export class LedgerKeyAgent extends KeyAgentBase {
377377
}
378378

379379
private static attachDisconnectionCleanupHandler(transport: LedgerTransportType) {
380-
const onDisconnect = () => {
380+
const onDisconnect = async () => {
381381
transport.off('disconnect', onDisconnect);
382382
this.deviceConnections = this.deviceConnections.filter(
383383
({ deviceConnection }) => deviceConnection.transport !== transport
384384
);
385-
void transport.close();
385+
386+
try {
387+
await transport.close();
388+
} catch {
389+
// hw-transport-webusb also adds a disconnect event listener while creating a Ledger transport,
390+
// so calling close() method will throw an error, since the device is already disconnected
391+
}
386392
};
387393
transport.on('disconnect', onDisconnect);
388394
}

0 commit comments

Comments
 (0)