Skip to content

Commit

Permalink
optionally retries in cli commands if user rejects Ledger request (#5672
Browse files Browse the repository at this point in the history
)

* exits cli commands if user rejects Ledger request

if a user rejects an action on their Ledger, the command will now exit instead
of retrying and prompting the user again to approve the action

* optionally retry if user rejects request

providers users a way to retry if they rejected by accident because starting
over in that case is a very bad experience

refactors retry prompt into reusable function
  • Loading branch information
hughy authored Nov 27, 2024
1 parent 2fd301d commit b9bb244
Showing 1 changed file with 19 additions and 29 deletions.
48 changes: 19 additions & 29 deletions ironfish-cli/src/ui/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,47 +72,24 @@ export async function ledger<TResult>({
// is trying to enter their pin. When we run into this error, we
// cannot send any commands to the Ledger in the app's CLA.
ux.action.stop('Ledger Locked')

const confirmed = await ui.confirmList(
await confirmRetryAction(
'Ledger Locked. Unlock and press enter to retry:',
'Retry',
wasRunning,
)

if (!confirmed) {
ux.stdout('Operation aborted.')
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)
}
await confirmRetryAction('Enable expert mode and press enter to retry:', wasRunning)
} else if (e instanceof LedgerActionRejected) {
ux.action.stop('User Rejected Ledger Request!')
await confirmRetryAction('Request rejected. Retry?', wasRunning)
} else if (e instanceof LedgerInvalidDkgStatusError) {
ux.action.stop('Ironfish DKG Ledger App does not have any multisig keys!')
ux.stdout(
'Use `wallet:multisig:ledger:restore` to restore an encrypted backup to your Ledger',
)
ux.exit(1)
} else if (e instanceof LedgerActionRejected) {
ux.action.status = 'User Rejected Ledger Request!'
ux.stdout('User Rejected Ledger Request!')
} else if (e instanceof LedgerConnectError) {
ux.action.status = 'Connect and unlock your Ledger'
} else if (e instanceof LedgerAppNotOpen) {
Expand Down Expand Up @@ -145,6 +122,19 @@ export async function ledger<TResult>({
}
}

async function confirmRetryAction(message: string, actionRunning: boolean): Promise<void> {
const confirmed = await ui.confirmList(message, 'Retry')

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

if (!actionRunning) {
ux.action.start(message)
}
}

export async function sendTransactionWithLedger(
client: RpcClient,
raw: RawTransaction,
Expand Down

0 comments on commit b9bb244

Please sign in to comment.