diff --git a/package.json b/package.json index a00df6f..eb7c1f2 100644 --- a/package.json +++ b/package.json @@ -16,5 +16,6 @@ "frontend": "yarn workspace frontend", "contract": "yarn workspace contract", "cli": "yarn workspace cli" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/pkgs/cli/src/commands/wallet.ts b/pkgs/cli/src/commands/wallet.ts index 6da93ab..1699e19 100644 --- a/pkgs/cli/src/commands/wallet.ts +++ b/pkgs/cli/src/commands/wallet.ts @@ -1,6 +1,6 @@ import { Command } from "commander"; import { getEthAddress, sendEth } from "../modules/viem"; -import { listProfiles, saveProfile } from "../services/wallet"; +import { listProfiles, saveProfile, deleteProfile } from "../services/wallet"; export const walletCommands = new Command(); @@ -33,6 +33,17 @@ walletCommands saveProfile({ name, privateKey }); }); +/** + * ウォレットを削除 + */ +walletCommands + .command("remove") + .description("remove a wallet") + .requiredOption("--name ", "Wallet name") + .action(({ name }) => { + deleteProfile({ name }); + }); + /** * ETHを送信 */ diff --git a/pkgs/cli/src/services/wallet.ts b/pkgs/cli/src/services/wallet.ts index 537db27..3ed470f 100644 --- a/pkgs/cli/src/services/wallet.ts +++ b/pkgs/cli/src/services/wallet.ts @@ -49,6 +49,18 @@ export const saveProfile = (params: Profile) => { console.log(`Profile ${params.name} with private key has been saved.`); }; +export const deleteProfile = (params: { name: string }) => { + const profiles = getProfiles(); + const index = profiles.findIndex((p) => p.name === params.name); + + if (index === -1) throw "Profile not found."; + + profiles.splice(index, 1); + + writeFileSync(profilesPath, JSON.stringify(profiles, null, 2)); + console.log(`Profile "${params.name}" with private key has been deleted.`); +} + export const listProfiles = () => { const profiles = getProfiles(); for (const profile of profiles) {