Skip to content

Commit

Permalink
Change wallet:delete to use new confirmInput (#5320)
Browse files Browse the repository at this point in the history
This makes the user type in the account name they are trying to delete
  • Loading branch information
NullSoldier committed Aug 20, 2024
1 parent dd8f936 commit 704d0ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
13 changes: 6 additions & 7 deletions ironfish-cli/src/commands/wallet/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { Args, Flags, ux } from '@oclif/core'
import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'
import { inputPrompt } from '../../ui'
import * as ui from '../../ui'

export class DeleteCommand extends IronfishCommand {
static description = `delete an account`
Expand Down Expand Up @@ -40,12 +40,11 @@ export class DeleteCommand extends IronfishCommand {
ux.action.stop()

if (response.content.needsConfirm) {
const value = await inputPrompt(`Are you sure? Type ${account} to confirm`)

if (value !== account) {
this.log(`Aborting: ${value} did not match ${account}`)
this.exit(1)
}
await ui.confirmInputOrQuit(
account,
`Are you sure you want to delete "${account}"?\nType ${account} to confirm`,
flags.confirm,
)

ux.action.start(`Deleting account '${account}'`)
await client.wallet.removeAccount({ account, confirm: true, wait })
Expand Down
21 changes: 21 additions & 0 deletions ironfish-cli/src/ui/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ export async function inputPrompt(message: string, required: boolean = false): P
return userInput
}

export async function confirmInputOrQuit(
input: string,
message?: string,
confirm?: boolean,
): Promise<void> {
if (confirm) {
return
}

if (!message) {
message = `Are you sure? Type ${input} to confirm.`
}

const entered = await inputPrompt(message, true)

if (entered !== input) {
ux.stdout('Operation aborted.')
ux.exit(0)
}
}

export async function confirmPrompt(message: string): Promise<boolean> {
const result: { prompt: boolean } = await inquirer.prompt({
type: 'confirm',
Expand Down

0 comments on commit 704d0ec

Please sign in to comment.