Skip to content

Commit

Permalink
Handle ledger app panics
Browse files Browse the repository at this point in the history
  • Loading branch information
NullSoldier committed Oct 8, 2024
1 parent 5e2b6ba commit 25a4f75
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ironfish-cli/src/ledger/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const IronfishLedgerStatusCodes = {
APP_NOT_OPEN: 0x6e01,
UNKNOWN_TRANSPORT_ERROR: 0xffff,
INVALID_TX_HASH: 0xb025,
PANIC: 0xe000,
}

export class Ledger {
Expand Down Expand Up @@ -59,6 +60,8 @@ export class Ledger {
throw new LedgerAppLocked()
} else if (error.returnCode === IronfishLedgerStatusCodes.CLA_NOT_SUPPORTED) {
throw new LedgerClaNotSupportedError()
} else if (error.returnCode === IronfishLedgerStatusCodes.PANIC) {
throw new LedgerPanicError()
} else if (error.returnCode === IronfishLedgerStatusCodes.GP_AUTH_FAILED) {
throw new LedgerGPAuthFailed()
} else if (
Expand Down Expand Up @@ -165,3 +168,4 @@ export class LedgerClaNotSupportedError extends LedgerError {}
export class LedgerAppNotOpen extends LedgerError {}
export class LedgerActionRejected extends LedgerError {}
export class LedgerInvalidTxHash extends LedgerError {}
export class LedgerPanicError extends LedgerError {}
4 changes: 4 additions & 0 deletions ironfish-cli/src/ui/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
LedgerConnectError,
LedgerDeviceLockedError,
LedgerGPAuthFailed,
LedgerPanicError,
LedgerPortIsBusyError,
LedgerSingleSigner,
} from '../ledger'
Expand Down Expand Up @@ -94,6 +95,9 @@ export async function ledger<TResult>({
ux.action.status = `Open Ledger App ${appName}`
} else if (e instanceof LedgerDeviceLockedError) {
ux.action.status = 'Unlock Ledger'
} else if (e instanceof LedgerPanicError) {
ux.action.status = 'Ledger App Crashed'
ux.stdout('Ledger App Crashed! ⚠️')
} else if (e instanceof LedgerPortIsBusyError) {
ux.action.status = 'Ledger is busy, retrying'
} else if (e instanceof LedgerGPAuthFailed) {
Expand Down

0 comments on commit 25a4f75

Please sign in to comment.