-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdelete.ts
40 lines (35 loc) · 1.09 KB
/
delete.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Command } from "@oclif/command";
import chalk from "chalk";
import { cli } from "cli-ux";
import { ethers } from "ethers";
import * as emoji from "node-emoji";
import { displayDescription, getConfig, updateConfig } from "../../lib/utils";
import { requireKeytar } from "../../lib/wallet";
export default class AccountDelete extends Command {
public static description = "delete the current ethereum account";
public async run() {
displayDescription(this, AccountDelete.description);
const { key } = await getConfig(this);
if (key) {
const wallet = new ethers.Wallet(String(key));
this.log(`Private Key: ${key}`);
this.log(`Address: ${wallet.address}\n`);
if (
await cli.confirm(
"Are you sure you want to delete this private key? (yes/no)",
)
) {
await updateConfig(this, {
key: undefined,
});
this.log(
`\n${emoji.get("white_check_mark")} The account has been deleted.\n`,
);
} else {
this.log(chalk.yellow("\nThe account was not deleted.\n"));
}
} else {
this.log("There is no ethereum account stored.\n");
}
}
}