Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit 48b6c2e

Browse files
committed
fix: allow custom user address
1 parent e30d81e commit 48b6c2e

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { selectAction } from "./actions";
1414
import { unionWith } from "lodash";
1515
import { oraLog } from "./oraLog";
1616
import { showTransferAll } from "./actions/transferAll/ui";
17+
import { extraAccount } from "./ui/extraAccount";
1718

1819
program
1920
.name("Argent X CLI")
@@ -36,16 +37,21 @@ program.parse();
3637
(async () => {
3738
const spinner = ora();
3839

39-
const { accounts, network, defaultPrivateKey } = await getAccountsAndNetwork(
40+
let { accounts, network, defaultPrivateKey } = await getAccountsAndNetwork(
4041
spinner
4142
);
4243

44+
spinner.succeed("Found " + accounts.length + " wallets");
45+
46+
if (accounts.length === 0) {
47+
accounts = await extraAccount(network, defaultPrivateKey);
48+
}
49+
4350
const accountInfos = await getAccountInfos(
4451
accounts.map((x) => x.address),
4552
network,
4653
spinner
4754
);
48-
spinner.succeed("Found " + accounts.length + " wallets");
4955

5056
const accountWithSigner: Account[] = accounts.map((account, i) => ({
5157
...account,

ui/extraAccount.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { isString } from "lodash";
2+
import prompts from "prompts";
3+
import { ValidationError } from "yup";
4+
import { addressSchema } from "../schema";
5+
6+
export async function extraAccount(
7+
network: "mainnet-alpha" | "goerli-alpha",
8+
privateKey: string
9+
): Promise<
10+
{
11+
address: string;
12+
networkId: string;
13+
privateKey: string;
14+
}[]
15+
> {
16+
const { extraWalletAddress } = await prompts(
17+
[
18+
{
19+
type: "text",
20+
name: "extraWalletAddress",
21+
message: "Enter wallet address you want to use",
22+
validate: async (value: string, prev) => {
23+
try {
24+
const address = value.replace(" ", "");
25+
if (!address.length) {
26+
return "You must select one account";
27+
}
28+
try {
29+
await addressSchema.validate(address);
30+
} catch (e) {
31+
return `Invalid address '${address}'.${
32+
e instanceof ValidationError ? ` Reason: ${e.message}` : ""
33+
}`;
34+
}
35+
} catch (e) {
36+
return "Invalid address";
37+
}
38+
return true;
39+
},
40+
},
41+
],
42+
{ onCancel: () => process.exit(1) }
43+
);
44+
45+
if (!isString(extraWalletAddress)) {
46+
throw new Error("Invalid address");
47+
}
48+
49+
return [
50+
{
51+
address: extraWalletAddress,
52+
networkId: network,
53+
privateKey,
54+
},
55+
];
56+
}

0 commit comments

Comments
 (0)