Skip to content

Commit

Permalink
Update suggestions according to PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
Phanco committed Jul 5, 2024
1 parent a5c7435 commit 88d3d6c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 62 deletions.
8 changes: 5 additions & 3 deletions packages/claim-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
"oclif": {
"bin": "claim-cli",
"dirname": "claim-cli",
"commands": "./dist/commands",
"commands": {
"strategy": "single",
"target": "./dist/index.js"
},
"plugins": [
"@oclif/plugin-help"
],
"topicSeparator": " "
]
},
"dependencies": {
"@inquirer/prompts": "^5.0.4",
Expand Down
20 changes: 18 additions & 2 deletions packages/claim-cli/src/applications/submit-claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,29 @@ export default async function submitClaim(networkParams: NetworkParams): Promise

const result = await fetchCheckEligibility(lskAddress, networkParams);
if (!result.account && result.multisigAccounts.length === 0) {
console.log(`No Eligible Claim for Address: ${lskAddress}`);
console.log(`No Eligible Claim for Address: ${lskAddress}.`);
return process.exit(1);
}

const choices = await buildAccountList(result, networkParams);

if (
choices.reduce((numOfClaimed, choice) => numOfClaimed + (choice.claimed ? 1 : 0), 0) ==
choices.length
) {
for (const [index, choice] of choices.entries()) {
console.log(`${index + 1}: ${choice.value.lskAddress} ${choice.claimed}`);
}
console.log(`All accounts under ${lskAddress} have successfully been claimed.`);
return process.exit(1);
}

const claimAccount = await select({
message: 'Choose Claim Address',
choices: await buildAccountList(result, networkParams),
choices: choices.map(account => ({
...account,
disabled: !!account.claimed,
})),
});

if (claimAccount.numberOfSignatures === 0) {
Expand Down
51 changes: 0 additions & 51 deletions packages/claim-cli/src/commands/start/index.ts

This file was deleted.

52 changes: 51 additions & 1 deletion packages/claim-cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
export { run } from '@oclif/core';
import { Flags, Command } from '@oclif/core';
import { select } from '@inquirer/prompts';
import checkEligibility from './applications/check-eligibility';
import submitClaim from './applications/submit-claim';
import publishMultisigClaim from './applications/publish-multisig-claim';
import { Mainnet, Testnet } from './utils/';

enum Choice {
CHECK_ELIGIBILITY,
SUBMIT_CLAIM,
SUBMIT_MULTISIG_CLAIM,
}

export default class Start extends Command {
static flags = {
network: Flags.string({
description: 'Operating network for the tool to run.',
required: false,
default: 'mainnet',
options: ['mainnet', 'testnet'],
}),
};

static description = 'Start Lisk Claim CLI Tool.';

static examples = [`$ oex claim-cli`];

async run(): Promise<void> {
const { flags } = await this.parse(Start);
const { network } = flags;

console.log(`Welcome to Lisk Migration CLI (Running on "${network}" Network)`);
const answer = await select({
message: 'Please enter your choices',
choices: [
{ name: 'Check my Eligibility', value: Choice.CHECK_ELIGIBILITY },
{ name: 'Submit a Claim', value: Choice.SUBMIT_CLAIM },
{
name: 'Publish a Multisig claim with completed signatures onchain',
value: Choice.SUBMIT_MULTISIG_CLAIM,
},
],
});

const networkParams = {
mainnet: Mainnet,
testnet: Testnet,
}[network as 'mainnet' | 'testnet'];
await [checkEligibility, submitClaim, publishMultisigClaim][answer](networkParams);
}
}
2 changes: 1 addition & 1 deletion packages/claim-cli/src/utils/confirm-send-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function confirmSendTransaction(
console.log(
`Estimated Network Fee (${estimatedGas} * ${maxFeePerGas} wei) = ${ethers.formatUnits(estimatedFee)} ETH.`,
);
console.log(`Your Balance: ${ethers.formatUnits(ethBalance)} ETH`);
console.log(`Your Balance: ${ethers.formatUnits(ethBalance)} ETH.`);
if (estimatedFee > ethBalance) {
console.log('Insufficient Balance for the Transaction.');
return process.exit(1);
Expand Down
8 changes: 4 additions & 4 deletions packages/claim-cli/src/utils/get-private-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getSecretType = (wallet: string) =>
});

export async function getLSKPrivateKeyFromMnemonic(): Promise<Buffer> {
const mnemonic = await getInput({ message: 'Your Mnemonic' });
const mnemonic = await getPassword({ message: 'Your Mnemonic' });
if (!Mnemonic.isValidMnemonic(mnemonic)) {
console.log('Invalid Mnemonic, please check again.');
return process.exit(1);
Expand All @@ -32,7 +32,7 @@ export async function getLSKPrivateKeyFromMnemonic(): Promise<Buffer> {
}

export async function getLSKPrivateKeyFromString(): Promise<Buffer> {
const privKey = await getInput({
const privKey = await getPassword({
message: 'Your Private Key',
});

Expand Down Expand Up @@ -61,7 +61,7 @@ export async function getLSKPrivateKey() {
}

export async function getETHWalletFromMnemonic(): Promise<HDNodeWallet> {
const mnemonic = await getInput({ message: 'Your L2 Mnemonic' });
const mnemonic = await getPassword({ message: 'Your L2 Mnemonic' });
if (!Mnemonic.isValidMnemonic(mnemonic)) {
console.log('Invalid Mnemonic, please check again.');
return process.exit(1);
Expand All @@ -74,7 +74,7 @@ export async function getETHWalletFromMnemonic(): Promise<HDNodeWallet> {
}

export const getETHWalletKeyFromString = async (): Promise<Wallet> => {
const privKey = await getInput({
const privKey = await getPassword({
message: 'Your Private Key',
});

Expand Down

0 comments on commit 88d3d6c

Please sign in to comment.