Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions src/cli/commands/wallet/remove.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { repositories as repos } from '../../../persistence/repository.mjs';
import { printer } from '../../output/index.mjs';
import { ensureCliLevelSecretInitialized } from '../../../env/index.mjs';
import { CliError } from '../../../error/cli-error.mjs';
import { withErrorHandler } from '../../utils/error-handler.mjs';

export const walletRemoveCommand = new Command()
.name('remove')
Expand All @@ -12,29 +13,23 @@ export const walletRemoveCommand = new Command()
.argument('<wallet-alias>', 'Wallet alias')
.option('-y --yes', 'Skip confirmation')

.action(async (walletAlias, opts, cmd) => {
try {
await ensureCliLevelSecretInitialized()
const walletData = await repos.wallet.getWallet(walletAlias)
if (walletData === undefined) {
printer.error(`Wallet with alias '${walletAlias}' not found`);
return;
}

if (!opts.yes) {
const answer = await prompts({
type: 'confirm',
name: 'value',
message: `Are you sure you want to remove wallet '${walletAlias}' [${walletData.accounts.map(a => a.alias).join(', ')}]?`
});
if (!answer.value) return;
}
.action(withErrorHandler(async (walletAlias, opts, cmd) => {
await ensureCliLevelSecretInitialized()
const walletData = await repos.wallet.getWallet(walletAlias)
if (walletData === undefined) {
printer.error(`Wallet with alias '${walletAlias}' not found`);
return;
}

await repos.wallet.remove(walletAlias);
printer.info(`Wallet '${walletAlias}' removed`);
} catch (e: unknown) {
if (e instanceof CliError) {
printer.error(e.message)
}
if (!opts.yes) {
const answer = await prompts({
type: 'confirm',
name: 'value',
message: `Are you sure you want to remove wallet '${walletAlias}' [${walletData.accounts.map(a => a.alias).join(', ')}]?`
});
if (!answer.value) return;
}
})

await repos.wallet.remove(walletAlias);
printer.info(`Wallet '${walletAlias}' removed`);
}))