Skip to content

Commit 12c0e62

Browse files
committed
Add CLI management tool (WIP)
1 parent 00c94ba commit 12c0e62

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

scripts/prompt.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ import {showData} from "./util";
44
import {submenuRouteToRecipient} from "./submenu/routeToRecipient";
55
import {submenuAllocateYield} from "./submenu/allocateYield";
66
import {submenuUpdateProportions} from "./submenu/updateProportions";
7+
import {submenuUpdateDestinationAddress} from "./submenu/updateDestinationAddress";
78

89
export const showMenu = async () => {
910
console.log(chalk.magentaBright('\nChoose an option:'));
1011
console.log(chalk.cyanBright('1) Refresh'));
1112
console.log(chalk.cyanBright('2) Allocate Yield'));
1213
console.log(chalk.cyanBright('3) Route Funds to Recipient'));
1314
console.log(chalk.cyanBright('4) Update Proportions'));
14-
console.log(chalk.cyanBright('5) Add Recipient'));
15-
console.log(chalk.cyanBright('6) Remove Recipient'));
16-
console.log(chalk.cyanBright('7) Quit'));
15+
console.log(chalk.cyanBright('5) Update Recipient Address'));
16+
console.log(chalk.cyanBright('6) Add Recipient'));
17+
console.log(chalk.cyanBright('7) Remove Recipient'));
18+
console.log(chalk.cyanBright('8) Quit'));
1719

18-
const choice = readlineSync.keyIn(chalk.yellow('\nEnter your choice: '), { limit: '$<1-7>' });
20+
const choice = readlineSync.keyIn(chalk.yellow('\nEnter your choice: '), { limit: '$<1-8>' });
1921

2022
switch (choice) {
2123
case '1':
@@ -32,12 +34,16 @@ export const showMenu = async () => {
3234
await submenuUpdateProportions();
3335
break;
3436
case '5':
35-
console.log(chalk.green('Adding recipient...'));
37+
38+
await submenuUpdateDestinationAddress();
3639
break;
3740
case '6':
38-
console.log(chalk.green('Removing recipient...'));
41+
console.log(chalk.green('Adding recipient...'));
3942
break;
4043
case '7':
44+
console.log(chalk.green('Removing recipient...'));
45+
break;
46+
case '8':
4147
console.log(chalk.green('Exiting...'));
4248
process.exit(0);
4349
break;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import chalk from "chalk";
2+
import {fundSenderClients, fundSenderDestinations, getFundSenderAvailableAmount, selectAmount} from "../util";
3+
import readlineSync from "readline-sync";
4+
import BN from "bn.js";
5+
import {PublicKey} from "@solana/web3.js";
6+
7+
export const submenuUpdateDestinationAddress = async () => {
8+
console.log(chalk.magentaBright('\nChoose a recipient:'));
9+
fundSenderDestinations.forEach((destinationName, index) => {
10+
console.log(chalk.cyanBright(`${index + 1}) ${destinationName}`));
11+
});
12+
console.log(chalk.cyanBright(`${fundSenderDestinations.length + 1}) Cancel`));
13+
14+
const choice = readlineSync.keyIn(chalk.yellow('\nEnter your choice: '), { limit: `$<1-${fundSenderDestinations.length}>` });
15+
16+
if (choice === `${fundSenderDestinations.length + 1}`) {
17+
return;
18+
}
19+
20+
const destinationName = fundSenderDestinations[parseInt(choice) - 1];
21+
const client = fundSenderClients.find(c => c.config.destinationName === destinationName);
22+
23+
if (!client) throw new Error('Client not found - trigger a refresh');
24+
25+
// ask for address
26+
const newDestinationAddress = readlineSync.question(chalk.yellow('Enter the new destination address: '));
27+
28+
// verify it is a valid Solana address
29+
let newDestinationAddressKey: PublicKey;
30+
try {
31+
newDestinationAddressKey = new PublicKey(newDestinationAddress);
32+
} catch (e) {
33+
console.log(chalk.red('Invalid address'));
34+
return;
35+
}
36+
37+
// ask for confirmation:
38+
console.log(chalk.yellow(`New destination address: ${newDestinationAddressKey.toBase58()}`));
39+
const confirm = readlineSync.question(chalk.yellow('Confirm (y/n): '));
40+
41+
if (confirm === 'y') {
42+
await client.updateDestinationAccount(newDestinationAddressKey, client.config.spendThreshold);
43+
console.log(chalk.green(`Done`));
44+
} else {
45+
console.log(chalk.red('Update cancelled'));
46+
}
47+
}

0 commit comments

Comments
 (0)