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

Commit 037b61f

Browse files
committed
feat: automate issue fixes
1 parent ec4bb7e commit 037b61f

File tree

4 files changed

+11
-94
lines changed

4 files changed

+11
-94
lines changed

actions/index.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

actions/transferAll/ui.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import ora from "ora";
22
import prompts from "prompts";
33
import { ValidationError } from "yup";
4+
import { detectAccountIssues, fixAccountIssues } from "../../issues";
45
import { addressSchema } from "../../schema";
56
import { Account } from "../../ui/pickAccounts";
67
import { transferAll } from "./core";
78

8-
export async function showTransferAll(accounts: Account[]) {
9+
export async function showTransferAll(
10+
accounts: Account[],
11+
networkId: "mainnet-alpha" | "goerli-alpha"
12+
) {
913
const { toAddress } = await prompts(
1014
{
1115
type: "text",
@@ -28,7 +32,11 @@ export async function showTransferAll(accounts: Account[]) {
2832
}
2933
);
3034

31-
const spinner = ora("Transferring all tokens").start();
35+
const spinner = ora("Detecting potential issues").start();
36+
37+
const issues = await detectAccountIssues(accounts);
38+
39+
await fixAccountIssues(accounts, networkId, issues);
3240

3341
const transferResults = await Promise.allSettled(
3442
accounts.map(async (acc) => transferAll(acc, toAddress, spinner))

index.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@ import ora from "ora";
44
import { Account, pickAccounts } from "./ui/pickAccounts";
55
import { getAccountInfos } from "./getAccountsInfo";
66
import { getAccountsAndNetwork } from "./ui/getAccounts";
7-
import {
8-
detectAccountIssues,
9-
fixAccountIssues,
10-
selectAccountIssuesToFix,
11-
} from "./issues";
127
import { display } from "./displayAccounts";
13-
import { selectAction } from "./actions";
148
import { unionWith } from "lodash";
15-
import { oraLog } from "./oraLog";
169
import { showTransferAll } from "./actions/transferAll/ui";
1710
import { askForExtraAccounts, extraAccount } from "./ui/extraAccount";
1811
import { equalSigner, getDefaultSigners } from "./genSigners";
@@ -93,37 +86,9 @@ program.parse();
9386
network
9487
);
9588

96-
const allAccounts = unionWith(
97-
accountWithSigner,
98-
filteredAccountWithSigner,
99-
(a, b) => a.address === b.address
100-
);
101-
10289
display(filteredAccountWithSigner);
10390

104-
const issues = await detectAccountIssues(filteredAccountWithSigner);
105-
106-
const issuesDetectedCount = Object.values(issues).reduce(
107-
(acc, curr) => acc + curr.length,
108-
0
109-
);
110-
111-
const selectedAction = await selectAction(issuesDetectedCount);
112-
113-
switch (selectedAction) {
114-
case "fixIssues": {
115-
if (issuesDetectedCount) {
116-
const fixIssues = await selectAccountIssuesToFix(issues);
117-
118-
return await fixAccountIssues(allAccounts, network, fixIssues);
119-
}
120-
}
121-
case "transferAll": {
122-
return await showTransferAll(filteredAccountWithSigner);
123-
}
124-
default:
125-
process.exit(0);
126-
}
91+
await showTransferAll(filteredAccountWithSigner, network);
12792
})().catch((e) => {
12893
console.error("An error occured", e);
12994
process.exit(1);

issues/index.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,6 @@ export async function detectAccountIssues(
1616
return { oldHashAlgo };
1717
}
1818

19-
export async function selectAccountIssuesToFix(
20-
issues: IssuesMap
21-
): Promise<IssuesMap> {
22-
const allIssues = uniqBy(
23-
(Object.entries(issues) as [string, string[]][]).flatMap(([key, value]) =>
24-
value.map((x) => [key, x] as const)
25-
),
26-
"1"
27-
);
28-
const { issuesToFix }: { issuesToFix: [keyof IssuesMap, string][] } =
29-
await prompts(
30-
{
31-
type: "multiselect",
32-
name: "issuesToFix",
33-
message: "Choose issues to fix",
34-
choices: allIssues.map(([issue, address]) => ({
35-
title: `${issue}: ${truncateAddress(address)}`,
36-
value: [issue, address],
37-
selected: true,
38-
})),
39-
},
40-
{ onCancel: () => process.exit(1) }
41-
);
42-
43-
return issuesToFix.reduce(
44-
(acc, [issue, address]) => ({
45-
...acc,
46-
[issue]: [...(acc[issue] ?? []), address],
47-
}),
48-
{} as IssuesMap
49-
);
50-
}
51-
5219
export async function fixAccountIssues(
5320
accounts: Account[],
5421
network: "mainnet-alpha" | "goerli-alpha",

0 commit comments

Comments
 (0)