Skip to content

Commit 704d0ec

Browse files
authored
Change wallet:delete to use new confirmInput (#5320)
This makes the user type in the account name they are trying to delete
1 parent dd8f936 commit 704d0ec

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

ironfish-cli/src/commands/wallet/delete.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { Args, Flags, ux } from '@oclif/core'
66
import { IronfishCommand } from '../../command'
77
import { RemoteFlags } from '../../flags'
8-
import { inputPrompt } from '../../ui'
8+
import * as ui from '../../ui'
99

1010
export class DeleteCommand extends IronfishCommand {
1111
static description = `delete an account`
@@ -40,12 +40,11 @@ export class DeleteCommand extends IronfishCommand {
4040
ux.action.stop()
4141

4242
if (response.content.needsConfirm) {
43-
const value = await inputPrompt(`Are you sure? Type ${account} to confirm`)
44-
45-
if (value !== account) {
46-
this.log(`Aborting: ${value} did not match ${account}`)
47-
this.exit(1)
48-
}
43+
await ui.confirmInputOrQuit(
44+
account,
45+
`Are you sure you want to delete "${account}"?\nType ${account} to confirm`,
46+
flags.confirm,
47+
)
4948

5049
ux.action.start(`Deleting account '${account}'`)
5150
await client.wallet.removeAccount({ account, confirm: true, wait })

ironfish-cli/src/ui/prompt.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ export async function inputPrompt(message: string, required: boolean = false): P
2828
return userInput
2929
}
3030

31+
export async function confirmInputOrQuit(
32+
input: string,
33+
message?: string,
34+
confirm?: boolean,
35+
): Promise<void> {
36+
if (confirm) {
37+
return
38+
}
39+
40+
if (!message) {
41+
message = `Are you sure? Type ${input} to confirm.`
42+
}
43+
44+
const entered = await inputPrompt(message, true)
45+
46+
if (entered !== input) {
47+
ux.stdout('Operation aborted.')
48+
ux.exit(0)
49+
}
50+
}
51+
3152
export async function confirmPrompt(message: string): Promise<boolean> {
3253
const result: { prompt: boolean } = await inquirer.prompt({
3354
type: 'confirm',

0 commit comments

Comments
 (0)