Skip to content

Commit

Permalink
Merge pull request #121 from hackdays-io/issue/117
Browse files Browse the repository at this point in the history
issue#117への対応
  • Loading branch information
yu23ki14 authored Sep 30, 2024
2 parents b1e27ab + 8187832 commit 4660c71
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"frontend": "yarn workspace frontend",
"contract": "yarn workspace contract",
"cli": "yarn workspace cli"
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
13 changes: 12 additions & 1 deletion pkgs/cli/src/commands/wallet.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -33,6 +33,17 @@ walletCommands
saveProfile({ name, privateKey });
});

/**
* ウォレットを削除
*/
walletCommands
.command("remove")
.description("remove a wallet")
.requiredOption("--name <name>", "Wallet name")
.action(({ name }) => {
deleteProfile({ name });
});

/**
* ETHを送信
*/
Expand Down
12 changes: 12 additions & 0 deletions pkgs/cli/src/services/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4660c71

Please sign in to comment.