-
Notifications
You must be signed in to change notification settings - Fork 12
/
chain.ts
47 lines (40 loc) · 1.2 KB
/
chain.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { ChainIds, chainNames } from "@airswap/utils";
import { Command } from "@oclif/command";
import chalk from "chalk";
import { get } from "../lib/prompt";
import * as utils from "../lib/utils";
export default class Network extends Command {
public static description = "set the active chain";
public async run() {
utils.displayDescription(this, Network.description);
let chainId: string;
try {
chainId = await utils.getChainId(this);
this.log(`Current chain: ${chainId} (${chainNames[chainId]})\n`);
} catch (e) {
this.log("Current chain not supported. Set a new one below.\n");
}
this.log("Available chains ids:\n");
for (const chainId in ChainIds) {
if (!Number.isNaN(Number(chainId)))
this.log(`· ${chainId} (${chainNames[chainId]})`);
}
this.log();
const { newChainId }: any = await get({
newChainId: {
description: "New chain id",
default: chainId,
},
});
if (!(newChainId in chainNames)) {
this.log(chalk.yellow(`\n${newChainId} is not a supported chain.\n`));
} else {
await utils.updateConfig(this, {
chainId: Number(newChainId),
});
this.log(
chalk.green(`\nSet active chain to ${chainNames[newChainId]}.\n`),
);
}
}
}