Skip to content

Commit

Permalink
handles expert mode required error in ledger ui (#5661)
Browse files Browse the repository at this point in the history
as of v1.1.0 of the Ironfish Ledger app expert mode must be required to review a
transaction that sends custom assets

defines the error code for the new export mode error

stops polling the Ledger app when an expert mode error is thrown so that the
user can navigate to the expert mode screen and enable expert mode before
continuing
  • Loading branch information
hughy authored Nov 19, 2024
1 parent af0da1f commit b801bf6
Show file tree
Hide file tree
Showing 2 changed files with 23 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 @@ -24,6 +24,7 @@ export const IronfishLedgerStatusCodes = {
UNKNOWN_TRANSPORT_ERROR: 0xffff,
INVALID_TX_HASH: 0xb025,
PANIC: 0xe000,
EXPERT_MODE_REQUIRED: 0x6984,
}

export class Ledger {
Expand Down Expand Up @@ -71,6 +72,8 @@ export class Ledger {
throw new LedgerPanicError()
} else if (error.returnCode === IronfishLedgerStatusCodes.GP_AUTH_FAILED) {
throw new LedgerGPAuthFailed()
} else if (error.returnCode === IronfishLedgerStatusCodes.EXPERT_MODE_REQUIRED) {
throw new LedgerExpertModeError()
} else if (
[
IronfishLedgerStatusCodes.COMMAND_NOT_ALLOWED,
Expand Down Expand Up @@ -183,3 +186,4 @@ export class LedgerAppNotOpen extends LedgerError {}
export class LedgerActionRejected extends LedgerError {}
export class LedgerInvalidTxHash extends LedgerError {}
export class LedgerPanicError extends LedgerError {}
export class LedgerExpertModeError extends LedgerError {}
19 changes: 19 additions & 0 deletions ironfish-cli/src/ui/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
LedgerClaNotSupportedError,
LedgerConnectError,
LedgerDeviceLockedError,
LedgerExpertModeError,
LedgerGPAuthFailed,
LedgerPanicError,
LedgerPortIsBusyError,
Expand Down Expand Up @@ -81,6 +82,24 @@ export async function ledger<TResult>({
ux.exit(0)
}

if (!wasRunning) {
ux.action.start(message)
}
} else if (e instanceof LedgerExpertModeError) {
// Polling the device may prevent the user from navigating to the
// expert mode screen in the app and enabling expert mode.
ux.action.stop('Expert mode required to send custom assets')

const confirmed = await ui.confirmList(
'Enable expert mode and press enter to retry:',
'Retry',
)

if (!confirmed) {
ux.stdout('Operation aborted.')
ux.exit(0)
}

if (!wasRunning) {
ux.action.start(message)
}
Expand Down

0 comments on commit b801bf6

Please sign in to comment.