Skip to content

Commit

Permalink
refactor: check instance of error before passing it to checkLockedDev…
Browse files Browse the repository at this point in the history
…iceError
  • Loading branch information
edgarkhanzadian committed Jan 10, 2024
1 parent 3fff31d commit e342642
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function useRequestLedgerKeys<App extends AppClient | StacksApp>({
onSuccess?.();
} catch (e) {
setAwaitingDeviceConnection(false);
if (checkLockedDeviceError(e)) {
if (e instanceof Error && checkLockedDeviceError(e)) {
setLatestDeviceResponse({ deviceLocked: true } as any);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/ledger/utils/generic-ledger-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') ||
Expand Down

0 comments on commit e342642

Please sign in to comment.