wative 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.esm.js +1 -1
- package/lib/index.umd.js +1 -1
- package/package.json +8 -3
- package/src/account.ts +288 -218
- package/src/assets.ts +168 -19
- package/src/home_page.ts +2 -2
- package/src/index.ts +2 -1
- package/src/network.ts +224 -31
- package/src/tools.ts +59 -28
- package/src/utils.ts +236 -6
- package/src/web3.ts +102 -2
- package/rollup.config.js +0 -30
package/src/network.ts
CHANGED
|
@@ -13,14 +13,16 @@ import {
|
|
|
13
13
|
getSymbol,
|
|
14
14
|
getColor,
|
|
15
15
|
Result,
|
|
16
|
-
getAccountChainType
|
|
16
|
+
getAccountChainType,
|
|
17
|
+
formatAddr
|
|
17
18
|
} from "./utils";
|
|
18
19
|
import {
|
|
19
20
|
getAccountInfo,
|
|
20
21
|
saveAccountInfo
|
|
21
22
|
} from "./account";
|
|
22
|
-
import { getAccountBalanceInEvm, getAccountBalanceInSolana } from "./web3";
|
|
23
|
+
import { deleteTokenBalance, getAccountBalanceInEvm, getAccountBalanceInSolana } from "./web3";
|
|
23
24
|
import { getChainType, getNativeTokenDecimals } from "./chain";
|
|
25
|
+
import { addToken } from "./assets";
|
|
24
26
|
|
|
25
27
|
export const createNetwork = async (keystore_path: string) => {
|
|
26
28
|
const network_path = path.resolve(keystore_path, 'network.json');
|
|
@@ -39,28 +41,29 @@ export const createNetwork = async (keystore_path: string) => {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
export const selectOrEditNetwork = async (keystore_path: string, selected_network: any) => {
|
|
42
|
-
let options:
|
|
43
|
-
|
|
44
|
+
let options: any[] = [
|
|
45
|
+
'> Edit'
|
|
44
46
|
];
|
|
45
47
|
|
|
46
48
|
if (selected_network.name !== "Ethereum Mainnet" && selected_network.name !== "Solana Mainnet") {
|
|
47
|
-
options.push(
|
|
49
|
+
options.push('> Remove');
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
options.push(
|
|
52
|
+
options.push(new inquirer.Separator('----------------------------------'));
|
|
53
|
+
options.push('> Back');
|
|
51
54
|
|
|
52
55
|
const selected_network_info = await selectSomething(options);
|
|
53
56
|
|
|
54
57
|
switch (selected_network_info) {
|
|
55
|
-
case
|
|
58
|
+
case '> Edit': {
|
|
56
59
|
await updateNetwork(keystore_path, selected_network);
|
|
57
60
|
break;
|
|
58
61
|
}
|
|
59
|
-
case
|
|
62
|
+
case '> Remove': {
|
|
60
63
|
await removeNetwork(keystore_path, selected_network);
|
|
61
64
|
break;
|
|
62
65
|
}
|
|
63
|
-
case
|
|
66
|
+
case '> Back': {
|
|
64
67
|
break;
|
|
65
68
|
}
|
|
66
69
|
}
|
|
@@ -229,7 +232,11 @@ export const showAvailableNetworks = async (keystore_path: string) => {
|
|
|
229
232
|
}
|
|
230
233
|
}
|
|
231
234
|
|
|
232
|
-
let options: any = [
|
|
235
|
+
let options: any = [
|
|
236
|
+
'> Back',
|
|
237
|
+
'+ Add Network',
|
|
238
|
+
new inquirer.Separator(`----Networks(evm)----`)
|
|
239
|
+
];
|
|
233
240
|
|
|
234
241
|
for (let i = 0; i < evm_ids.length; i++) {
|
|
235
242
|
const evm_id = evm_ids[i];
|
|
@@ -257,41 +264,179 @@ export const showAvailableNetworks = async (keystore_path: string) => {
|
|
|
257
264
|
}
|
|
258
265
|
|
|
259
266
|
const selected_option = await selectSomething(options);
|
|
260
|
-
if (selected_option ===
|
|
267
|
+
if (selected_option === '> Back') {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (selected_option === '+ Add Network') {
|
|
272
|
+
await addNetwork(keystore_path);
|
|
261
273
|
return;
|
|
262
274
|
}
|
|
263
275
|
|
|
276
|
+
|
|
264
277
|
let option_id = options.indexOf(selected_option);
|
|
265
278
|
let select_network: any;
|
|
266
|
-
if (option_id < evm_ids.length +
|
|
267
|
-
select_network = networks.networks[evm_ids[option_id -
|
|
279
|
+
if (option_id < evm_ids.length + 3) {
|
|
280
|
+
select_network = networks.networks[evm_ids[option_id - 3]];
|
|
268
281
|
} else {
|
|
269
|
-
select_network = networks.networks[solana_ids[option_id - evm_ids.length -
|
|
282
|
+
select_network = networks.networks[solana_ids[option_id - evm_ids.length - 4]];
|
|
270
283
|
}
|
|
271
284
|
|
|
272
285
|
await selectOrEditNetwork(keystore_path, select_network);
|
|
273
286
|
await showAvailableNetworks(keystore_path);
|
|
274
287
|
}
|
|
275
288
|
|
|
289
|
+
export const showDataview = async (keystore_path: string) => {
|
|
290
|
+
let options: any = [
|
|
291
|
+
'> Enhanced Balance Display',
|
|
292
|
+
new inquirer.Separator('----------------------------------'),
|
|
293
|
+
'> Back',
|
|
294
|
+
];
|
|
295
|
+
|
|
296
|
+
const selected_option = await selectSomething(options);
|
|
297
|
+
switch (selected_option) {
|
|
298
|
+
case '> Enhanced Balance Display': {
|
|
299
|
+
await enhancedBalanceDisplay(keystore_path);
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
case '> Back': {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
await showDataview(keystore_path);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export const updateStatus = async (keystore_path: string) => {
|
|
311
|
+
const network_path = path.resolve(keystore_path, 'network.json');
|
|
312
|
+
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
313
|
+
|
|
314
|
+
if (!("status" in networks)) {
|
|
315
|
+
networks.status = {
|
|
316
|
+
fullAddr: false,
|
|
317
|
+
gasToken: false,
|
|
318
|
+
extendedToken: false
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
let options = [
|
|
323
|
+
`> Show Full Address [${networks.status.fullAddr ? "ON" : "OFF"}]`,
|
|
324
|
+
`> Show Gas Token [${networks.status.gasToken ? "ON" : "OFF"}]`,
|
|
325
|
+
`> Show Extended Token[${networks.status.extendedToken ? "ON" : "OFF"}]`,
|
|
326
|
+
new inquirer.Separator('----------------------------------'),
|
|
327
|
+
'> Back',
|
|
328
|
+
];
|
|
329
|
+
|
|
330
|
+
const selected_option = await selectSomething(options);
|
|
331
|
+
|
|
332
|
+
if (selected_option === '> Back') {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (selected_option.includes('Full Address')) {
|
|
337
|
+
networks.status.fullAddr = await selectFlag();
|
|
338
|
+
} else if (selected_option.includes('Gas Token')) {
|
|
339
|
+
networks.status.gasToken = await selectFlag();
|
|
340
|
+
} else if (selected_option.includes('Extended Token')) {
|
|
341
|
+
networks.status.extendedToken = await selectFlag();
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
fs.writeFileSync(network_path, JSON.stringify(networks, null, 2));
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export const selectFlag = async () => {
|
|
348
|
+
let options = [
|
|
349
|
+
'> On',
|
|
350
|
+
'> Off'
|
|
351
|
+
];
|
|
352
|
+
|
|
353
|
+
const selected_option = await selectSomething(options);
|
|
354
|
+
switch (selected_option) {
|
|
355
|
+
case '> On': {
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
case '> Off': {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export const showTokenList = async (keystore_path: string) => {
|
|
365
|
+
const network_path = path.resolve(keystore_path, 'network.json');
|
|
366
|
+
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
367
|
+
|
|
368
|
+
let network_settings_map: any = {};
|
|
369
|
+
for (let network_info of networks.networks) {
|
|
370
|
+
network_settings_map[network_info.chainId.toString()] = network_info.name;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const assets_path = path.resolve(keystore_path, 'assets.json');
|
|
374
|
+
const assets = JSON.parse(fs.readFileSync(assets_path, 'utf8'));
|
|
375
|
+
|
|
376
|
+
for (let chain_id in assets) {
|
|
377
|
+
console.log(`----- Networks (${network_settings_map[chain_id]}) -------`);
|
|
378
|
+
|
|
379
|
+
let token_list_len = assets[chain_id].length;
|
|
380
|
+
for (let i = 0; i < token_list_len; i++) {
|
|
381
|
+
let token_info = assets[chain_id][i];
|
|
382
|
+
console.log(`${i + 1}.${token_info.symbol} CA: ${chalk.green(`${formatAddr(token_info.address)}`)
|
|
383
|
+
} Decimals: ${token_info.display_decimals ? token_info.display_decimals : "4"}`);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export const enhancedBalanceDisplay = async (keystore_path: string) => {
|
|
389
|
+
const options = [
|
|
390
|
+
'> Status',
|
|
391
|
+
'> Token List',
|
|
392
|
+
'> Add Token',
|
|
393
|
+
new inquirer.Separator('----------------------------------'),
|
|
394
|
+
'> Back',
|
|
395
|
+
];
|
|
396
|
+
|
|
397
|
+
const selected_option = await selectSomething(options);
|
|
398
|
+
|
|
399
|
+
switch (selected_option) {
|
|
400
|
+
case '> Status': {
|
|
401
|
+
await updateStatus(keystore_path);
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
case '> Token List': {
|
|
405
|
+
await showTokenList(keystore_path);
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
case '> Add Token': {
|
|
409
|
+
await addToken(keystore_path);
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
case '> Back': {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
await enhancedBalanceDisplay(keystore_path);
|
|
418
|
+
}
|
|
419
|
+
|
|
276
420
|
export const showNetwork = async (keystore_path: string) => {
|
|
277
421
|
let network_info_list = [
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
422
|
+
'> Networks',
|
|
423
|
+
'> Dataview',
|
|
424
|
+
new inquirer.Separator('----------------------------------'),
|
|
425
|
+
'> Back'
|
|
281
426
|
];
|
|
282
427
|
|
|
283
428
|
const selected_network_info = await selectSomething(network_info_list);
|
|
284
429
|
|
|
285
430
|
switch (selected_network_info) {
|
|
286
|
-
case
|
|
431
|
+
case '> Networks': {
|
|
287
432
|
await showAvailableNetworks(keystore_path);
|
|
288
433
|
break;
|
|
289
434
|
}
|
|
290
|
-
case
|
|
291
|
-
await
|
|
435
|
+
case '> Dataview': {
|
|
436
|
+
await showDataview(keystore_path);
|
|
292
437
|
break;
|
|
293
438
|
}
|
|
294
|
-
case
|
|
439
|
+
case '> Back': {
|
|
295
440
|
return;
|
|
296
441
|
}
|
|
297
442
|
}
|
|
@@ -340,10 +485,11 @@ export const getNetworkInfoByName = (keystore_path: string, network_name: string
|
|
|
340
485
|
export const getAccountAddress = (keystore_path: string, account_label: string, account_id: number) => {
|
|
341
486
|
const account_info = getAccountInfo(keystore_path, account_label);
|
|
342
487
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
default_network = account_info.data[account_id].default_network;
|
|
488
|
+
if (account_info.account_type === "PK") {
|
|
489
|
+
return account_info.data[account_id].ciphertexts.address;
|
|
346
490
|
}
|
|
491
|
+
|
|
492
|
+
let default_network = account_info.default_network;
|
|
347
493
|
let network_type = getNetworkTypeByName(keystore_path, default_network);
|
|
348
494
|
|
|
349
495
|
if (network_type === "solana") {
|
|
@@ -368,7 +514,8 @@ export const switchPPNetwork = async (keystore_path: string, account_label: stri
|
|
|
368
514
|
|
|
369
515
|
let account_info = getAccountInfo(keystore_path, account_label);
|
|
370
516
|
let options_switch_network = [
|
|
371
|
-
|
|
517
|
+
'> Back',
|
|
518
|
+
new inquirer.Separator('----------------------------------')
|
|
372
519
|
];
|
|
373
520
|
|
|
374
521
|
let default_network = account_info.data[account_id].default_network;
|
|
@@ -396,15 +543,15 @@ export const switchPPNetwork = async (keystore_path: string, account_label: stri
|
|
|
396
543
|
|
|
397
544
|
const selected_network = await selectSomething(options_switch_network);
|
|
398
545
|
|
|
399
|
-
if (selected_network ===
|
|
546
|
+
if (selected_network === '> Back') {
|
|
400
547
|
return;
|
|
401
548
|
}
|
|
402
549
|
|
|
403
550
|
let selected_network_id = options_switch_network.indexOf(selected_network);
|
|
404
|
-
if (selected_network_id ===
|
|
551
|
+
if (selected_network_id === 2) {
|
|
405
552
|
delete account_info.data[account_id].default_network;
|
|
406
553
|
} else {
|
|
407
|
-
account_info.data[account_id].default_network = network_list[selected_network_id -
|
|
554
|
+
account_info.data[account_id].default_network = network_list[selected_network_id - 3].name;
|
|
408
555
|
}
|
|
409
556
|
|
|
410
557
|
saveAccountInfo(keystore_path, account_label, account_info);
|
|
@@ -420,6 +567,44 @@ export const switchPPNetwork = async (keystore_path: string, account_label: stri
|
|
|
420
567
|
);
|
|
421
568
|
}
|
|
422
569
|
|
|
570
|
+
export const showAllAccounts = async (keystore_path: string, account_label: string, account_index: number) => {
|
|
571
|
+
const network_path = path.resolve(keystore_path, 'network.json');
|
|
572
|
+
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
573
|
+
const network_list = networks.networks;
|
|
574
|
+
const network_len = network_list.length;
|
|
575
|
+
|
|
576
|
+
let account_info = getAccountInfo(keystore_path, account_label);
|
|
577
|
+
let default_network = account_info.default_network;
|
|
578
|
+
|
|
579
|
+
const network_type = getNetworkTypeByName(keystore_path, default_network);
|
|
580
|
+
|
|
581
|
+
for (let i = 0; i < network_len; i++) {
|
|
582
|
+
|
|
583
|
+
const network = network_list[i];
|
|
584
|
+
const this_network_type = getNetworkTypeByName(keystore_path, network.name);
|
|
585
|
+
if (account_info.account_type === "PK" && network_type !== this_network_type) {
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
let account_address: string;
|
|
590
|
+
if (account_info.account_type === "PK") {
|
|
591
|
+
account_address = account_info.data[account_index].ciphertexts.address;
|
|
592
|
+
} else {
|
|
593
|
+
if (this_network_type === "evm") {
|
|
594
|
+
account_address = account_info.data[account_index].ciphertexts.evm.address;
|
|
595
|
+
} else {
|
|
596
|
+
account_address = account_info.data[account_index].ciphertexts.solana.address;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if (network.name === default_network) {
|
|
601
|
+
console.log(`● ${account_address} [${network.name}]`);
|
|
602
|
+
} else {
|
|
603
|
+
console.log(`○ ${account_address} [${network.name}]`);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
423
608
|
export const switchNetworkByAccountLabel = async (keystore_path: string, account_label: string, is_account_label: boolean) => {
|
|
424
609
|
const network_path = path.resolve(keystore_path, 'network.json');
|
|
425
610
|
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
@@ -428,7 +613,8 @@ export const switchNetworkByAccountLabel = async (keystore_path: string, account
|
|
|
428
613
|
|
|
429
614
|
let account_info = getAccountInfo(keystore_path, account_label);
|
|
430
615
|
let options_switch_network = [
|
|
431
|
-
|
|
616
|
+
'> Back',
|
|
617
|
+
new inquirer.Separator('----------------------------------'),
|
|
432
618
|
];
|
|
433
619
|
|
|
434
620
|
let default_network = account_info.default_network;
|
|
@@ -464,12 +650,12 @@ export const switchNetworkByAccountLabel = async (keystore_path: string, account
|
|
|
464
650
|
}
|
|
465
651
|
|
|
466
652
|
const selected_network = await selectSomething(options_switch_network);
|
|
467
|
-
if (selected_network ===
|
|
653
|
+
if (selected_network === '> Back') {
|
|
468
654
|
return;
|
|
469
655
|
}
|
|
470
656
|
|
|
471
657
|
let selected_network_id = options_switch_network.indexOf(selected_network);
|
|
472
|
-
account_info.default_network = option_network_name_list[selected_network_id -
|
|
658
|
+
account_info.default_network = option_network_name_list[selected_network_id - 2];
|
|
473
659
|
saveAccountInfo(keystore_path, account_label, account_info);
|
|
474
660
|
|
|
475
661
|
if (!is_account_label) {
|
|
@@ -520,6 +706,8 @@ export const getAccountBalance = async (account: string, keystore_path: string,
|
|
|
520
706
|
let balance = new BigNumber(result.output.toString());
|
|
521
707
|
result.output = balance.dividedBy(Math.pow(10, decimals)).toFixed(4, BigNumber.ROUND_FLOOR);
|
|
522
708
|
}
|
|
709
|
+
|
|
710
|
+
deleteTokenBalance(network_info.chainId.toString(), account, "0");
|
|
523
711
|
return result;
|
|
524
712
|
}
|
|
525
713
|
|
|
@@ -557,3 +745,8 @@ export const getEvmNetworks = (keystore_path: string) => {
|
|
|
557
745
|
return result;
|
|
558
746
|
}
|
|
559
747
|
|
|
748
|
+
export const getStatus = (keystore_path: string) => {
|
|
749
|
+
const network_path = path.resolve(keystore_path, 'network.json');
|
|
750
|
+
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
751
|
+
return networks.status;
|
|
752
|
+
}
|
package/src/tools.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const chalk = require('chalk');
|
|
2
2
|
import { BigNumber } from 'bignumber.js';
|
|
3
3
|
import inquirer from 'inquirer';
|
|
4
|
-
import { chainAddressValidator, confirmSomething, editorSomething, getAccountChainType, hexValidator, inputSomething, numberValidator, selectSomething } from "./utils";
|
|
4
|
+
import { addrValidator, chainAddressValidator, confirmSomething, editorSomething, getAccountChainType, hexValidator, inputSomething, numberValidator, selectSomething } from "./utils";
|
|
5
5
|
import { loginIn } from './account';
|
|
6
6
|
import { getAccountBalance, getDefaultNetworkByAddress, getEvmNetworks, getNetworkInfoByName, getNetworkTypeByName } from './network';
|
|
7
7
|
import { GasUtil } from './tx_gas_utils';
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
|
|
17
17
|
const { WativeCore } = require("wative-core");
|
|
18
18
|
|
|
19
|
-
const confirmEvmRawTransaction = async (tx_params: any) => {
|
|
19
|
+
const confirmEvmRawTransaction = async (tx_params: any): Promise<any> => {
|
|
20
20
|
let option_send_evm_raw_transaction_list: any = [
|
|
21
21
|
new inquirer.Separator("————Tx Detail—————-"),
|
|
22
22
|
`from: ${tx_params.from}`,
|
|
@@ -59,7 +59,7 @@ const confirmEvmRawTransaction = async (tx_params: any) => {
|
|
|
59
59
|
return tx_params;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
await confirmEvmRawTransaction(tx_params);
|
|
62
|
+
return await confirmEvmRawTransaction(tx_params);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
const sendEvmRawTransaction = async (chain_rpc_url: string, chain_symbols: string, account_address: string, wative_core: typeof WativeCore) => {
|
|
@@ -99,7 +99,7 @@ const sendEvmRawTransaction = async (chain_rpc_url: string, chain_symbols: strin
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
let option_select_vaule_list: any = [
|
|
102
|
-
|
|
102
|
+
'> Input value',
|
|
103
103
|
`> Total Balance (${total_balance} ${chain_symbols})`
|
|
104
104
|
]
|
|
105
105
|
let selected_vaule = await selectSomething(option_select_vaule_list);
|
|
@@ -228,7 +228,7 @@ export const sendSolanaRawTransaction = async (chain_rpc_url: string, chain_symb
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
let option_select_vaule_list: any = [
|
|
231
|
-
|
|
231
|
+
'> Input value',
|
|
232
232
|
`> Total Balance (${total_balance} ${chain_symbols})`
|
|
233
233
|
]
|
|
234
234
|
let selected_vaule = await selectSomething(option_select_vaule_list);
|
|
@@ -283,15 +283,15 @@ export const sendSolanaRawTransaction = async (chain_rpc_url: string, chain_symb
|
|
|
283
283
|
|
|
284
284
|
const sendEvmTokenTransaction = async (keystore_path: string, chain_rpc_url: string, chain_id: string, account_address: string, wative_core: typeof WativeCore) => {
|
|
285
285
|
const option_token_address_list = [
|
|
286
|
-
|
|
287
|
-
|
|
286
|
+
'> Input token ticker',
|
|
287
|
+
'> Input token contract address'
|
|
288
288
|
];
|
|
289
289
|
let selected_token_address = await selectSomething(option_token_address_list);
|
|
290
290
|
|
|
291
291
|
let token_address: any;
|
|
292
292
|
let token_decimals: any;
|
|
293
293
|
switch (selected_token_address) {
|
|
294
|
-
case
|
|
294
|
+
case '> Input token ticker':
|
|
295
295
|
let token_name = await inputSomething("token ticker");
|
|
296
296
|
|
|
297
297
|
let token_address_list = await getAssetListByTokenName(keystore_path, chain_id, token_name);
|
|
@@ -329,7 +329,7 @@ const sendEvmTokenTransaction = async (keystore_path: string, chain_rpc_url: str
|
|
|
329
329
|
token_address = token_ticker_info.address;
|
|
330
330
|
token_decimals = Number(token_ticker_info.decimals);
|
|
331
331
|
break;
|
|
332
|
-
case
|
|
332
|
+
case '> Input token contract address':
|
|
333
333
|
token_address = await inputSomething("token contract address", chainAddressValidator);
|
|
334
334
|
let token_info: any = await getTokenInfoInEvm(token_address, chain_rpc_url);
|
|
335
335
|
if (!token_info.status) {
|
|
@@ -404,15 +404,15 @@ const sendEvmTokenTransaction = async (keystore_path: string, chain_rpc_url: str
|
|
|
404
404
|
|
|
405
405
|
const sendSolanaTokenTransaction = async (keystore_path: string, chain_rpc_url: string, chain_id: string, account_address: string, wative_core: typeof WativeCore) => {
|
|
406
406
|
const option_token_address_list = [
|
|
407
|
-
|
|
408
|
-
|
|
407
|
+
'> Input token ticker',
|
|
408
|
+
'> Input token contract address'
|
|
409
409
|
];
|
|
410
410
|
let selected_token_address = await selectSomething(option_token_address_list);
|
|
411
411
|
|
|
412
412
|
let token_address: any;
|
|
413
413
|
let token_decimals: any;
|
|
414
414
|
switch (selected_token_address) {
|
|
415
|
-
case
|
|
415
|
+
case '> Input token ticker':
|
|
416
416
|
let token_name = await inputSomething("token ticker");
|
|
417
417
|
|
|
418
418
|
let token_address_list = await getAssetListByTokenName(keystore_path, chain_id, token_name);
|
|
@@ -450,7 +450,7 @@ const sendSolanaTokenTransaction = async (keystore_path: string, chain_rpc_url:
|
|
|
450
450
|
token_address = token_ticker_info.address;
|
|
451
451
|
token_decimals = Number(token_ticker_info.decimals);
|
|
452
452
|
break;
|
|
453
|
-
case
|
|
453
|
+
case '> Input token contract address':
|
|
454
454
|
token_address = await inputSomething("token contract address", chainAddressValidator);
|
|
455
455
|
let token_info: any = await getTokenInfoInSolana(token_address, chain_rpc_url);
|
|
456
456
|
if (!token_info.status) {
|
|
@@ -638,15 +638,16 @@ const excuteTools = async (keystore_path: string, account_label: string, account
|
|
|
638
638
|
);
|
|
639
639
|
|
|
640
640
|
const option_send_tx = [
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
641
|
+
'> Send Raw Tx',
|
|
642
|
+
'> Send Token',
|
|
643
|
+
new inquirer.Separator('----------------------------------'),
|
|
644
|
+
'> Back',
|
|
644
645
|
];
|
|
645
646
|
|
|
646
647
|
const selected_send_tx = await selectSomething(option_send_tx);
|
|
647
648
|
|
|
648
649
|
switch (selected_send_tx) {
|
|
649
|
-
case
|
|
650
|
+
case '> Send Raw Tx': {
|
|
650
651
|
if (account_chain_type === "evm") {
|
|
651
652
|
await sendEvmRawTransaction(
|
|
652
653
|
network_info.rpcUrl,
|
|
@@ -666,7 +667,7 @@ const excuteTools = async (keystore_path: string, account_label: string, account
|
|
|
666
667
|
}
|
|
667
668
|
break;
|
|
668
669
|
}
|
|
669
|
-
case
|
|
670
|
+
case '> Send Token': {
|
|
670
671
|
if (account_chain_type === "evm") {
|
|
671
672
|
await sendEvmTokenTransaction(
|
|
672
673
|
keystore_path,
|
|
@@ -688,7 +689,7 @@ const excuteTools = async (keystore_path: string, account_label: string, account
|
|
|
688
689
|
}
|
|
689
690
|
break;
|
|
690
691
|
}
|
|
691
|
-
case
|
|
692
|
+
case '> Back': {
|
|
692
693
|
return;
|
|
693
694
|
}
|
|
694
695
|
}
|
|
@@ -696,18 +697,19 @@ const excuteTools = async (keystore_path: string, account_label: string, account
|
|
|
696
697
|
|
|
697
698
|
export const selectToolsOptions = async (keystore_path: string, account_label: string, account_address: string, wative_core: typeof WativeCore) => {
|
|
698
699
|
const tools_options = [
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
700
|
+
'> SendTx',
|
|
701
|
+
'> SignMessage',
|
|
702
|
+
new inquirer.Separator('----------------------------------'),
|
|
703
|
+
'> Back'
|
|
702
704
|
];
|
|
703
705
|
|
|
704
706
|
const selected_tools_option = await selectSomething(tools_options);
|
|
705
707
|
switch (selected_tools_option) {
|
|
706
|
-
case
|
|
708
|
+
case '> SendTx': {
|
|
707
709
|
await excuteTools(keystore_path, account_label, account_address, wative_core);
|
|
708
710
|
break;
|
|
709
711
|
}
|
|
710
|
-
case
|
|
712
|
+
case '> SignMessage': {
|
|
711
713
|
const message = await editorSomething("Input the message to sign");
|
|
712
714
|
const signed_message = wative_core.account.signMessage(account_address, message);
|
|
713
715
|
if (!signed_message.status) {
|
|
@@ -719,7 +721,7 @@ export const selectToolsOptions = async (keystore_path: string, account_label: s
|
|
|
719
721
|
);
|
|
720
722
|
break;
|
|
721
723
|
}
|
|
722
|
-
case
|
|
724
|
+
case '> Back': {
|
|
723
725
|
return;
|
|
724
726
|
}
|
|
725
727
|
}
|
|
@@ -727,15 +729,44 @@ export const selectToolsOptions = async (keystore_path: string, account_label: s
|
|
|
727
729
|
}
|
|
728
730
|
|
|
729
731
|
export const showTools = async (keystore_path: string, wative_core: typeof WativeCore) => {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
+
let options = [
|
|
733
|
+
"> Send Tx",
|
|
734
|
+
"> Search Accounts",
|
|
735
|
+
new inquirer.Separator('----------------------------------'),
|
|
736
|
+
"> Back"
|
|
737
|
+
];
|
|
738
|
+
|
|
739
|
+
let selected_option = await selectSomething(options);
|
|
740
|
+
|
|
741
|
+
if (selected_option === "> Back") {
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
let account_address: any;
|
|
746
|
+
if (selected_option === "> Send Tx") {
|
|
747
|
+
account_address = await inputSomething("Input address to send tx", chainAddressValidator);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
if (selected_option === "> Search Accounts") {
|
|
751
|
+
account_address = await inputSomething("Input part address to send tx", addrValidator);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
let account_label_info = wative_core.account.getAccountLabel(account_address);
|
|
755
|
+
if (account_label_info === null) {
|
|
756
|
+
console.log(chalk.red("Account not found"));
|
|
757
|
+
await showTools(keystore_path, wative_core);
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
let account_label = account_label_info.account_label;
|
|
762
|
+
account_address = account_label_info.account_address;
|
|
732
763
|
if (account_label === null) {
|
|
733
764
|
console.log(chalk.red("Account not found"));
|
|
734
765
|
await showTools(keystore_path, wative_core);
|
|
735
766
|
return;
|
|
736
767
|
}
|
|
737
768
|
let login_result = await loginIn(account_label, wative_core);
|
|
738
|
-
if (!login_result) {
|
|
769
|
+
if (!login_result.isLoginIn) {
|
|
739
770
|
await showTools(keystore_path, wative_core);
|
|
740
771
|
return;
|
|
741
772
|
}
|