From e3426422e535601d5ae7d38d49b1e8c6f58cc4f5 Mon Sep 17 00:00:00 2001 From: Edgar Khanzadian Date: Tue, 9 Jan 2024 19:15:57 +0400 Subject: [PATCH] refactor: check instance of error before passing it to checkLockedDeviceError --- .../bitcoin-tx-signing/ledger-bitcoin-sign-tx-container.tsx | 2 +- .../ledger/flows/jwt-signing/ledger-sign-jwt-container.tsx | 2 +- .../stacks-message-signing/ledger-stacks-sign-msg-container.tsx | 2 +- .../flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx | 2 +- .../generic-flows/request-keys/use-request-ledger-keys.ts | 2 +- src/app/features/ledger/utils/generic-ledger-utils.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/features/ledger/flows/bitcoin-tx-signing/ledger-bitcoin-sign-tx-container.tsx b/src/app/features/ledger/flows/bitcoin-tx-signing/ledger-bitcoin-sign-tx-container.tsx index 6fbea7663ec..d6203b39eff 100644 --- a/src/app/features/ledger/flows/bitcoin-tx-signing/ledger-bitcoin-sign-tx-container.tsx +++ b/src/app/features/ledger/flows/bitcoin-tx-signing/ledger-bitcoin-sign-tx-container.tsx @@ -115,7 +115,7 @@ function LedgerSignBitcoinTxContainer() { void bitcoinApp.transport.close(); } } catch (e) { - if (checkLockedDeviceError(e)) { + if (e instanceof Error && checkLockedDeviceError(e)) { setLatestDeviceResponse({ deviceLocked: true } as any); return; } diff --git a/src/app/features/ledger/flows/jwt-signing/ledger-sign-jwt-container.tsx b/src/app/features/ledger/flows/jwt-signing/ledger-sign-jwt-container.tsx index bcf6c280c70..d7bcccf80eb 100644 --- a/src/app/features/ledger/flows/jwt-signing/ledger-sign-jwt-container.tsx +++ b/src/app/features/ledger/flows/jwt-signing/ledger-sign-jwt-container.tsx @@ -92,7 +92,7 @@ export function LedgerSignJwtContainer() { const stacks = await prepareLedgerDeviceStacksAppConnection({ setLoadingState: setAwaitingDeviceConnection, onError(e) { - if (checkLockedDeviceError(e)) { + if (e instanceof Error && checkLockedDeviceError(e)) { setLatestDeviceResponse({ deviceLocked: true } as any); return; } diff --git a/src/app/features/ledger/flows/stacks-message-signing/ledger-stacks-sign-msg-container.tsx b/src/app/features/ledger/flows/stacks-message-signing/ledger-stacks-sign-msg-container.tsx index d2cf6a4097b..855814cc58c 100644 --- a/src/app/features/ledger/flows/stacks-message-signing/ledger-stacks-sign-msg-container.tsx +++ b/src/app/features/ledger/flows/stacks-message-signing/ledger-stacks-sign-msg-container.tsx @@ -67,7 +67,7 @@ function LedgerSignStacksMsg({ account, unsignedMessage }: LedgerSignMsgProps) { const stacksApp = await prepareLedgerDeviceStacksAppConnection({ setLoadingState: setAwaitingDeviceConnection, onError(e) { - if (checkLockedDeviceError(e)) { + if (e instanceof Error && checkLockedDeviceError(e)) { setLatestDeviceResponse({ deviceLocked: true } as any); return; } diff --git a/src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx b/src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx index 33131eefd60..a4809554c99 100644 --- a/src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx +++ b/src/app/features/ledger/flows/stacks-tx-signing/ledger-sign-stacks-tx-container.tsx @@ -71,7 +71,7 @@ function LedgerSignStacksTxContainer() { const stacksApp = await prepareLedgerDeviceStacksAppConnection({ setLoadingState: setAwaitingDeviceConnection, onError(e) { - if (checkLockedDeviceError(e)) { + if (e instanceof Error && checkLockedDeviceError(e)) { setLatestDeviceResponse({ deviceLocked: true } as any); return; } diff --git a/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts b/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts index dedbe0fc317..36a007db0bd 100644 --- a/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts +++ b/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts @@ -73,7 +73,7 @@ export function useRequestLedgerKeys({ onSuccess?.(); } catch (e) { setAwaitingDeviceConnection(false); - if (checkLockedDeviceError(e)) { + if (e instanceof Error && checkLockedDeviceError(e)) { setLatestDeviceResponse({ deviceLocked: true } as any); return; } diff --git a/src/app/features/ledger/utils/generic-ledger-utils.ts b/src/app/features/ledger/utils/generic-ledger-utils.ts index f7ca22a0b70..0e27ad286b2 100644 --- a/src/app/features/ledger/utils/generic-ledger-utils.ts +++ b/src/app/features/ledger/utils/generic-ledger-utils.ts @@ -104,7 +104,7 @@ export async function promptOpenAppOnDevice(appName: string) { await delay(500); } -export function checkLockedDeviceError(e: any) { +export function checkLockedDeviceError(e: Error) { return !!( e?.name === 'LockedDeviceError' || e?.message?.includes('LockedDeviceError') ||