Skip to content

Commit b9bb244

Browse files
authored
optionally retries in cli commands if user rejects Ledger request (#5672)
* 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
1 parent 2fd301d commit b9bb244

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

ironfish-cli/src/ui/ledger.ts

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -72,47 +72,24 @@ export async function ledger<TResult>({
7272
// is trying to enter their pin. When we run into this error, we
7373
// cannot send any commands to the Ledger in the app's CLA.
7474
ux.action.stop('Ledger Locked')
75-
76-
const confirmed = await ui.confirmList(
75+
await confirmRetryAction(
7776
'Ledger Locked. Unlock and press enter to retry:',
78-
'Retry',
77+
wasRunning,
7978
)
80-
81-
if (!confirmed) {
82-
ux.stdout('Operation aborted.')
83-
ux.exit(0)
84-
}
85-
86-
if (!wasRunning) {
87-
ux.action.start(message)
88-
}
8979
} else if (e instanceof LedgerExpertModeError) {
9080
// Polling the device may prevent the user from navigating to the
9181
// expert mode screen in the app and enabling expert mode.
9282
ux.action.stop('Expert mode required to send custom assets')
93-
94-
const confirmed = await ui.confirmList(
95-
'Enable expert mode and press enter to retry:',
96-
'Retry',
97-
)
98-
99-
if (!confirmed) {
100-
ux.stdout('Operation aborted.')
101-
ux.exit(0)
102-
}
103-
104-
if (!wasRunning) {
105-
ux.action.start(message)
106-
}
83+
await confirmRetryAction('Enable expert mode and press enter to retry:', wasRunning)
84+
} else if (e instanceof LedgerActionRejected) {
85+
ux.action.stop('User Rejected Ledger Request!')
86+
await confirmRetryAction('Request rejected. Retry?', wasRunning)
10787
} else if (e instanceof LedgerInvalidDkgStatusError) {
10888
ux.action.stop('Ironfish DKG Ledger App does not have any multisig keys!')
10989
ux.stdout(
11090
'Use `wallet:multisig:ledger:restore` to restore an encrypted backup to your Ledger',
11191
)
11292
ux.exit(1)
113-
} else if (e instanceof LedgerActionRejected) {
114-
ux.action.status = 'User Rejected Ledger Request!'
115-
ux.stdout('User Rejected Ledger Request!')
11693
} else if (e instanceof LedgerConnectError) {
11794
ux.action.status = 'Connect and unlock your Ledger'
11895
} else if (e instanceof LedgerAppNotOpen) {
@@ -145,6 +122,19 @@ export async function ledger<TResult>({
145122
}
146123
}
147124

125+
async function confirmRetryAction(message: string, actionRunning: boolean): Promise<void> {
126+
const confirmed = await ui.confirmList(message, 'Retry')
127+
128+
if (!confirmed) {
129+
ux.stdout('Operation aborted.')
130+
ux.exit(0)
131+
}
132+
133+
if (!actionRunning) {
134+
ux.action.start(message)
135+
}
136+
}
137+
148138
export async function sendTransactionWithLedger(
149139
client: RpcClient,
150140
raw: RawTransaction,

0 commit comments

Comments
 (0)