Skip to content

Commit 75c13e8

Browse files
overcatpiyalbasu
authored andcommitted
fix: close existing HID connections before opening new ones
1 parent 45154f8 commit 75c13e8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/components/SignIn/SignInLedgerForm.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ export const SignInLedgerForm = ({ onClose }: ModalPageProps) => {
126126
const handleConnect = async () => {
127127
setErrorMessage("");
128128
try {
129+
// Close existing connections to avoid "device already open" error
130+
const existingTransports = await TransportWebHID.list();
131+
await Promise.all(
132+
existingTransports.map((existingTransport) =>
133+
existingTransport.close().catch(() => {
134+
// Ignore close errors - device might already be closed
135+
}),
136+
),
137+
);
138+
129139
const transport = await TransportWebHID.request();
130140
dispatch(fetchLedgerStellarAddressAction({ ledgerBipPath, transport }));
131141
} catch (e) {

src/helpers/signLedgerTransaction.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ export const signLedgerTransaction = async (
77
publicKey: string,
88
bipPath: string,
99
) => {
10+
// Close existing connections to avoid "device already open" error
11+
const existingTransports = await TransportWebHID.list();
12+
await Promise.all(
13+
existingTransports.map((existingTransport) =>
14+
existingTransport.close().catch(() => {
15+
// Ignore close errors - device might already be closed
16+
}),
17+
),
18+
);
19+
1020
const transport = await TransportWebHID.create();
1121
const ledgerApi = new LedgerApi(transport);
1222
const result = await ledgerApi.signTransaction(

0 commit comments

Comments
 (0)