Skip to content

Commit b801bf6

Browse files
authored
handles expert mode required error in ledger ui (#5661)
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
1 parent af0da1f commit b801bf6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

ironfish-cli/src/ledger/ledger.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const IronfishLedgerStatusCodes = {
2424
UNKNOWN_TRANSPORT_ERROR: 0xffff,
2525
INVALID_TX_HASH: 0xb025,
2626
PANIC: 0xe000,
27+
EXPERT_MODE_REQUIRED: 0x6984,
2728
}
2829

2930
export class Ledger {
@@ -71,6 +72,8 @@ export class Ledger {
7172
throw new LedgerPanicError()
7273
} else if (error.returnCode === IronfishLedgerStatusCodes.GP_AUTH_FAILED) {
7374
throw new LedgerGPAuthFailed()
75+
} else if (error.returnCode === IronfishLedgerStatusCodes.EXPERT_MODE_REQUIRED) {
76+
throw new LedgerExpertModeError()
7477
} else if (
7578
[
7679
IronfishLedgerStatusCodes.COMMAND_NOT_ALLOWED,
@@ -183,3 +186,4 @@ export class LedgerAppNotOpen extends LedgerError {}
183186
export class LedgerActionRejected extends LedgerError {}
184187
export class LedgerInvalidTxHash extends LedgerError {}
185188
export class LedgerPanicError extends LedgerError {}
189+
export class LedgerExpertModeError extends LedgerError {}

ironfish-cli/src/ui/ledger.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
LedgerClaNotSupportedError,
2020
LedgerConnectError,
2121
LedgerDeviceLockedError,
22+
LedgerExpertModeError,
2223
LedgerGPAuthFailed,
2324
LedgerPanicError,
2425
LedgerPortIsBusyError,
@@ -81,6 +82,24 @@ export async function ledger<TResult>({
8182
ux.exit(0)
8283
}
8384

85+
if (!wasRunning) {
86+
ux.action.start(message)
87+
}
88+
} else if (e instanceof LedgerExpertModeError) {
89+
// Polling the device may prevent the user from navigating to the
90+
// expert mode screen in the app and enabling expert mode.
91+
ux.action.stop('Expert mode required to send custom assets')
92+
93+
const confirmed = await ui.confirmList(
94+
'Enable expert mode and press enter to retry:',
95+
'Retry',
96+
)
97+
98+
if (!confirmed) {
99+
ux.stdout('Operation aborted.')
100+
ux.exit(0)
101+
}
102+
84103
if (!wasRunning) {
85104
ux.action.start(message)
86105
}

0 commit comments

Comments
 (0)