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/src/account.ts CHANGED
@@ -13,15 +13,24 @@ import {
13
13
  getAccountIndex,
14
14
  getAccountRange,
15
15
  confirmSomething,
16
+ numberValidator,
17
+ formatAddr,
18
+ listWithLazyBalanceLoading,
16
19
  } from "./utils";
17
- import { getAccountAddress, getAccountBalance, getNetworkInfoByName, getNetworkTypeByName, getPKAccountAddress, selectDefaultNetwork, switchNetworkByAccountLabel, switchPPNetwork } from "./network";
18
- import { showAssets } from './assets';
20
+ import { getAccountAddress, getAccountBalance, getNetworkInfoByName, getNetworkTypeByName, getStatus, selectDefaultNetwork, showAllAccounts, switchNetworkByAccountLabel } from "./network";
21
+ import { getAssetList, showAssets, showAssetsDetail } from './assets';
19
22
  import { selectToolsOptions } from './tools';
20
23
  import inquirer from "inquirer";
24
+ import { getChainType } from "./chain";
21
25
 
22
26
  const cliProgress = require('cli-progress');
23
27
  const { WativeCore } = require("wative-core");
24
28
 
29
+ const DEFAULT_ACCOUNT: any = {
30
+ account_label: '',
31
+ default_account_index: 0
32
+ };
33
+
25
34
  const preAccountImport = async (keystore_path: string) => {
26
35
  const networks = getNetworkInfo(keystore_path)
27
36
 
@@ -78,37 +87,112 @@ const importPassphrase = async (keystore_path: string, wative_core: typeof Wativ
78
87
  fs.writeFileSync(network_path, JSON.stringify(networks, null, 4));
79
88
  }
80
89
 
81
- const importPrivateKey = async (keystore_path: string, wative_core: typeof WativeCore) => {
90
+
91
+ const createPrivateKeyAccount = async (keystore_path: string, wative_core: typeof WativeCore) => {
82
92
  let pre_account_info = await preAccountImport(keystore_path);
83
93
  if (!pre_account_info) {
84
94
  return;
85
95
  }
86
96
 
87
97
  let private_key = await inputSomething('Please enter a private key');
88
- let network_info = await getNetworkInfoByName(keystore_path, pre_account_info.selected_default_network);
98
+ await _importAccount(
99
+ keystore_path,
100
+ pre_account_info.password,
101
+ pre_account_info.account_label,
102
+ private_key,
103
+ pre_account_info.selected_default_network,
104
+ wative_core,
105
+ true
106
+ );
107
+
108
+ const network_path = path.resolve(keystore_path, 'network.json');
109
+ const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
110
+ networks.accounts.push(pre_account_info.account_label);
111
+ fs.writeFileSync(network_path, JSON.stringify(networks, null, 4));
112
+ }
113
+
114
+ const importPrivateKeyAccount = async (
115
+ keystore_path: string,
116
+ password: string,
117
+ account_label: string,
118
+ wative_core: typeof WativeCore
119
+ ) => {
120
+ let private_key = await inputSomething('Please enter a private key');
121
+ let account_info_path = path.join(keystore_path, `accounts/${account_label}.json`);
122
+ let exist_account_info = JSON.parse(fs.readFileSync(account_info_path, 'utf8'));
89
123
 
90
- let privatekey_account = await wative_core.account.generatePKAccount(pre_account_info.account_label, private_key, pre_account_info.password, network_info.chainId);
124
+ await _importAccount(
125
+ keystore_path,
126
+ password,
127
+ account_label,
128
+ private_key,
129
+ exist_account_info.default_network,
130
+ wative_core,
131
+ false
132
+ );
133
+ }
134
+
135
+ const _importAccount = async (
136
+ keystore_path: string,
137
+ password: string,
138
+ account_label: string,
139
+ private_key: string,
140
+ default_network: string,
141
+ wative_core: typeof WativeCore,
142
+ generate_account_label: boolean
143
+ ) => {
144
+ let network_info = await getNetworkInfoByName(keystore_path, default_network);
145
+ let network_type = getChainType(network_info.chainId);
146
+ if (network_type === 'evm' && !private_key.startsWith('0x')) {
147
+ private_key = "0x" + private_key;
148
+ }
149
+
150
+ let privatekey_account = await wative_core.account.generatePKAccount(account_label, private_key, password, network_info.chainId, generate_account_label);
91
151
  if (!privatekey_account.status) {
92
152
  console.log(
93
153
  chalk.red(privatekey_account.output)
94
154
  );
95
155
  return;
96
156
  }
97
- let account_info_path = path.join(keystore_path, `accounts/${pre_account_info.account_label}.json`);
157
+ let account_info_path = path.join(keystore_path, `accounts/${account_label}.json`);
158
+
159
+ let result: any;
160
+ if (fs.existsSync(account_info_path)) {
161
+ let exist_account_info = JSON.parse(fs.readFileSync(account_info_path, 'utf8'));
162
+ if ("data" in exist_account_info) {
163
+ exist_account_info.data.push({
164
+ ciphertexts: privatekey_account.output.ciphertexts
165
+ });
166
+ result = exist_account_info;
167
+ } else {
168
+ exist_account_info.data = [
169
+ { ciphertexts: exist_account_info.ciphertexts }
170
+ ]
171
+ delete exist_account_info.ciphertexts;
172
+ exist_account_info.data.push({
173
+ ciphertexts: privatekey_account.output.ciphertexts
174
+ });
175
+ result = exist_account_info;
176
+ }
177
+ } else {
178
+ privatekey_account.output.data = [
179
+ { ciphertexts: privatekey_account.output.ciphertexts }
180
+ ];
181
+ delete privatekey_account.output.ciphertexts;
182
+ privatekey_account.output.default_network = default_network;
183
+ result = privatekey_account.output;
184
+ }
98
185
 
99
- privatekey_account.output.default_network = pre_account_info.selected_default_network;
100
- fs.writeFileSync(account_info_path, JSON.stringify(privatekey_account.output, null, 4));
186
+ fs.writeFileSync(account_info_path, JSON.stringify(result, null, 4));
101
187
 
102
- const network_path = path.resolve(keystore_path, 'network.json');
103
- const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
104
- networks.accounts.push(pre_account_info.account_label);
105
- fs.writeFileSync(network_path, JSON.stringify(networks, null, 4));
188
+ wative_core.account.reloadAccount();
106
189
  }
107
190
 
108
191
  const createAccount = async (keystore_path: string, wative_core: typeof WativeCore) => {
109
192
  const create_account_options = [
110
193
  '> Import Passphrase',
111
194
  '> Import Private Key',
195
+ new inquirer.Separator('----------------------------------'),
112
196
  '> Back'
113
197
  ];
114
198
 
@@ -120,13 +204,15 @@ const createAccount = async (keystore_path: string, wative_core: typeof WativeCo
120
204
  break;
121
205
  }
122
206
  case '> Import Private Key': {
123
- await importPrivateKey(keystore_path, wative_core);
207
+ await createPrivateKeyAccount(keystore_path, wative_core);
124
208
  break;
125
209
  }
126
210
  case '> Back': {
127
211
  return;
128
212
  }
129
213
  }
214
+
215
+ wative_core.account.reloadAccount();
130
216
  }
131
217
 
132
218
  const getNetworkInfo = (keystore_path: string) => {
@@ -149,18 +235,28 @@ export const saveAccountInfo = (keystore_path: string, account_label: string, ac
149
235
  export const loginIn = async (account_label: string, wative_core: typeof WativeCore) => {
150
236
  const is_login = wative_core.account.isLogin(account_label);
151
237
  if (is_login) {
152
- return true;
238
+ return { isLoginIn: true };
153
239
  }
154
- let password = await inputPassword(`Please input the password for Account [${account_label}]`);
155
- const login_result = await wative_core.account.login(account_label, password);
156
- if (login_result.status) {
157
- return true;
158
- } else {
159
- console.log(
160
- chalk.red(login_result.output)
161
- );
162
- return false;
240
+
241
+ for (let i = 0; i < 3; i++) {
242
+ const password = await inputPassword(`Please input the password for Account [${account_label}]`);
243
+ if (!password) {
244
+ console.log(
245
+ chalk.red("Password can't be empty")
246
+ );
247
+ return { isLoginIn: false };
248
+ }
249
+
250
+ const login_result = await wative_core.account.login(account_label, password);
251
+ if (login_result.status) {
252
+ return { isLoginIn: true, password };
253
+ } else {
254
+ console.log(
255
+ chalk.red(login_result.output)
256
+ );
257
+ }
163
258
  }
259
+ return { isLoginIn: false };
164
260
  }
165
261
 
166
262
  const selectAccount = async (keystore_path: string, wative_core: typeof WativeCore) => {
@@ -168,7 +264,8 @@ const selectAccount = async (keystore_path: string, wative_core: typeof WativeCo
168
264
  const account_label_list = networks.accounts;
169
265
 
170
266
  let select_account_options = [
171
- "> Back"
267
+ '> Back',
268
+ new inquirer.Separator('----------------------------------')
172
269
  ];
173
270
 
174
271
  const account_label_len = account_label_list.length;
@@ -182,7 +279,7 @@ const selectAccount = async (keystore_path: string, wative_core: typeof WativeCo
182
279
  for (let i = 0; i < account_label_len; i++) {
183
280
  const account_label = account_label_list[i];
184
281
  const account_info = getAccountInfo(keystore_path, account_label);
185
- if (account_info.account_type === "PP") {
282
+ if ("data" in account_info) {
186
283
  select_account_options.push(`${i + 1}) ${account_label} [${account_info.account_type}:${account_info.data.length}]`);
187
284
  } else {
188
285
  select_account_options.push(`${i + 1}) ${account_label} [${account_info.account_type}:1]`);
@@ -190,14 +287,14 @@ const selectAccount = async (keystore_path: string, wative_core: typeof WativeCo
190
287
  }
191
288
 
192
289
  const selected_account = await selectSomething(select_account_options, "Select an account");
193
- if (selected_account === "> Back") {
290
+ if (selected_account === '> Back') {
194
291
  return;
195
292
  }
196
293
 
197
- const selected_account_label = account_label_list[select_account_options.indexOf(selected_account) - 1];
294
+ const selected_account_label = account_label_list[select_account_options.indexOf(selected_account) - 2];
198
295
  let login_result = await loginIn(selected_account_label, wative_core);
199
- if (login_result) {
200
- await accountManager(keystore_path, selected_account_label, wative_core);
296
+ if (login_result.isLoginIn) {
297
+ await accountManager(keystore_path, selected_account_label, wative_core, login_result.password);
201
298
  }
202
299
 
203
300
  await selectAccount(keystore_path, wative_core);
@@ -207,18 +304,19 @@ const setDisableAddress = async (keystore_path: string, account_label: string, w
207
304
  const account_info = await getAccountInfo(keystore_path, account_label);
208
305
 
209
306
  let disable_address_options = [
210
- "> Back",
211
- "1.Disabled Slots",
212
- "2.Add Single",
213
- "3.Add Range"
307
+ "> Disabled Slots",
308
+ "> Add Single",
309
+ "> Add Range",
310
+ new inquirer.Separator('----------------------------------'),
311
+ '> Back'
214
312
  ];
215
313
 
216
314
  const selected_disable_address = await selectSomething(disable_address_options);
217
315
  switch (selected_disable_address) {
218
- case "> Back": {
316
+ case '> Back': {
219
317
  return;
220
318
  }
221
- case "1.Disabled Slots": {
319
+ case "> Disabled Slots": {
222
320
  let disabled_slots = account_info.disabled_slots;
223
321
  if (!disabled_slots || disabled_slots.length === 0) {
224
322
  console.log(
@@ -230,7 +328,8 @@ const setDisableAddress = async (keystore_path: string, account_label: string, w
230
328
  let account_data = account_info.data;
231
329
 
232
330
  let disabled_slots_options = [
233
- "> Back",
331
+ '> Back',
332
+ new inquirer.Separator('----------------------------------'),
234
333
  ];
235
334
 
236
335
  let default_network = account_info.default_network;
@@ -284,7 +383,7 @@ const setDisableAddress = async (keystore_path: string, account_label: string, w
284
383
 
285
384
  let selected_disabled_slots = await selectSomething(disabled_slots_options);
286
385
 
287
- if (selected_disabled_slots === "> Back") {
386
+ if (selected_disabled_slots === '> Back') {
288
387
  break;
289
388
  }
290
389
 
@@ -292,14 +391,14 @@ const setDisableAddress = async (keystore_path: string, account_label: string, w
292
391
  if (!confirm) {
293
392
  break;
294
393
  }
295
- let selected_disabled_slots_index = disabled_slots_options.indexOf(selected_disabled_slots) - 1;
394
+ let selected_disabled_slots_index = disabled_slots_options.indexOf(selected_disabled_slots) - 2;
296
395
 
297
396
  account_info.disabled_slots.splice(selected_disabled_slots_index, 1);
298
397
  saveAccountInfo(keystore_path, account_label, account_info);
299
398
 
300
399
  break;
301
400
  }
302
- case "2.Add Single": {
401
+ case "> Add Single": {
303
402
  let account_index_or_address = await getAccountIndex(account_info, "Input address or index");
304
403
  if (account_index_or_address === null) {
305
404
  console.log(chalk.red("Invalid account index"));
@@ -321,7 +420,7 @@ const setDisableAddress = async (keystore_path: string, account_label: string, w
321
420
  saveAccountInfo(keystore_path, account_label, account_info);
322
421
  break;
323
422
  }
324
- case "3.Add Range": {
423
+ case "> Add Range": {
325
424
  let account_range = await getAccountRange(account_info);
326
425
  if (!account_range) {
327
426
  console.log(chalk.red("Invalid account range"));
@@ -343,41 +442,43 @@ const setDisableAddress = async (keystore_path: string, account_label: string, w
343
442
  }
344
443
 
345
444
 
346
- const accountManager = async (keystore_path: string, account_label: string, wative_core: typeof WativeCore) => {
445
+ const accountManager = async (keystore_path: string, account_label: string, wative_core: typeof WativeCore, password: string) => {
347
446
  let account_info = await getAccountInfo(keystore_path, account_label);
348
447
 
349
- let account_manager_options: string[];
448
+ let account_manager_options: any[];
350
449
 
351
450
  if (account_info.account_type === "PP") {
352
451
  account_manager_options = [
353
- '1.Address List',
354
- '2.Expand Address',
355
- '3.Slice Address',
356
- '4.Disable Address',
357
- '5.Reset Account Password',
358
- `6.Switch Networks [${account_info.default_network}]`,
452
+ '> Address List',
453
+ '> Expand Address',
454
+ '> Slice Address',
455
+ '> Disable Address',
456
+ '> Reset Account Password',
457
+ `> Switch Networks [${account_info.default_network}]`,
458
+ '> Remove',
459
+ new inquirer.Separator('----------------------------------'),
359
460
  '> Back'
360
461
  ];
361
462
  } else {
362
463
  account_manager_options = [
363
- '1.Address List',
364
- '2.Reset Account Password',
365
- `3.Switch Networks [${account_info.default_network}]`,
464
+ '> Address List',
465
+ '> Import Private Key',
466
+ '> Remove Address',
467
+ '> Reset Account Password',
468
+ `> Switch Networks [${account_info.default_network}]`,
469
+ '> Remove',
470
+ new inquirer.Separator('----------------------------------'),
366
471
  '> Back'
367
472
  ];
368
473
  }
369
474
 
370
475
  const selected_account_manager = await selectSomething(account_manager_options);
371
476
  switch (selected_account_manager) {
372
- case '1.Address List': {
373
- if (account_info.account_type === "PP") {
374
- await showPPAccounts(keystore_path, account_label, wative_core);
375
- } else {
376
- await showPKAccounts(keystore_path, account_label, wative_core);
377
- }
477
+ case '> Address List': {
478
+ await showAccounts(keystore_path, account_label, wative_core);
378
479
  break;
379
480
  }
380
- case '2.Expand Address': {
481
+ case '> Expand Address': {
381
482
  const count = await inputSomething('Expand accounts count', expandAmountValidator);
382
483
  if (Number(count) > 2000) {
383
484
  console.log(
@@ -389,20 +490,28 @@ const accountManager = async (keystore_path: string, account_label: string, wati
389
490
  await expandAddress(keystore_path, account_label, Number(count), wative_core);
390
491
  break;
391
492
  }
392
- case '3.Slice Address': {
493
+ case '> Import Private Key': {
494
+ await importPrivateKeyAccount(keystore_path, password, account_label, wative_core);
495
+ break;
496
+ }
497
+ case '> Slice Address': {
393
498
  const last_account_no = await inputSomething('Please input last account number', lastAccountNoValidator);
394
499
  await sliceAddress(keystore_path, account_label, Number(last_account_no), wative_core);
395
500
  break;
396
501
  }
397
- case '4.Disable Address': {
502
+ case '> Remove Address': {
503
+ await removeAddress(keystore_path, account_label, wative_core);
504
+ break;
505
+ }
506
+ case '> Disable Address': {
398
507
  await setDisableAddress(keystore_path, account_label, wative_core);
399
508
  break;
400
509
  }
401
- case '5.Reset Account Password': {
510
+ case '> Reset Account Password': {
402
511
  const password1 = await inputPassword(`Please input new password for Account [${account_label}]`);
403
512
  const password2 = await inputPassword(`Please confirm new password for Account [${account_label}]`);
404
513
 
405
- if (password1 !== password2) {
514
+ if (!password1 || !password2 || password1 !== password2) {
406
515
  console.log(
407
516
  chalk.red("Passwords do not match")
408
517
  );
@@ -412,105 +521,98 @@ const accountManager = async (keystore_path: string, account_label: string, wati
412
521
  await wative_core.account.resetPassword(account_label, password1);
413
522
  return;
414
523
  }
415
- case `3.Switch Networks [${account_info.default_network}]`: {
524
+ case `> Switch Networks [${account_info.default_network}]`: {
416
525
  await switchNetworkByAccountLabel(keystore_path, account_label, true);
417
526
  break;
418
527
  }
419
- case `6.Switch Networks [${account_info.default_network}]`: {
420
- await switchNetworkByAccountLabel(keystore_path, account_label, true);
528
+ case '> Remove': {
529
+ await removeAccountLabel(keystore_path, account_label);
421
530
  break;
422
531
  }
423
- case '2.Reset Account Password': {
424
- const password1 = await inputPassword(`Please input new password for Account [${account_label}]`);
425
- const password2 = await inputPassword(`Please confirm new password for Account [${account_label}]`);
426
-
427
- if (password1 !== password2) {
428
- console.log(
429
- chalk.red("Passwords do not match")
430
- );
431
- break;
432
- }
433
-
434
- await wative_core.account.resetPassword(account_label, password1);
435
- return;
436
- }
437
532
  case '> Back': {
438
533
  return;
439
534
  }
440
535
  }
441
536
 
442
- await accountManager(keystore_path, account_label, wative_core);
537
+ await accountManager(keystore_path, account_label, wative_core, password);
443
538
  }
444
539
 
445
- const showPPAccounts = async (keystore_path: string, account_label: string, wative_core: typeof WativeCore) => {
540
+ const showAccounts = async (keystore_path: string, account_label: string, wative_core: typeof WativeCore) => {
446
541
  const account_info = await getAccountInfo(keystore_path, account_label);
542
+
447
543
  let option_accounts: any = [
448
- '> Back'
544
+ '> Back',
545
+ new inquirer.Separator('----------------------------------'),
449
546
  ];
450
-
451
547
  let disabled_slots = account_info.disabled_slots;
452
- for (let i = 0; i < account_info.data.length; i++) {
453
-
454
- let default_network = account_info.default_network;
455
- if ("default_network" in account_info.data[i]) {
456
- default_network = account_info.data[i].default_network;
457
- }
458
-
459
- let network_type = getNetworkTypeByName(keystore_path, default_network);
548
+ let status = getStatus(keystore_path);
460
549
 
461
- let tag = "";
462
- if ("tag" in account_info.data[i]) {
463
- tag = `(${account_info.data[i].tag})`;
464
- }
550
+ let default_network = account_info.default_network;
551
+ let network_info = getNetworkInfoByName(keystore_path, default_network);
552
+ let network_type = getChainType(network_info.chainId.toString());
465
553
 
554
+ for (let i = 0; i < account_info.data.length; i++) {
555
+ let tag = account_info.data[i].tag ? `(${account_info.data[i].tag})` : "";
466
556
  let is_disable_address = wative_core.account.checkIsDisableAddress(disabled_slots, i);
467
- if (network_type === "evm") {
468
- if (is_disable_address) {
469
- option_accounts.push(new inquirer.Separator(
470
- chalk.yellow(`#${i} ${account_info.data[i].ciphertexts.evm.address} ${tag} [${default_network}]`)
471
- ))
472
- } else {
473
- option_accounts.push(`#${i} ${account_info.data[i].ciphertexts.evm.address} ${tag} [${default_network}]`);
474
- }
475
557
 
476
- } else if (network_type === "solana") {
477
- if (is_disable_address) {
478
- option_accounts.push(new inquirer.Separator(
479
- chalk.yellow(`#${i} ${account_info.data[i].ciphertexts.solana.address} ${tag} [${default_network}]`)
480
- ))
558
+ let account_address: string;
559
+ if (account_info.account_type === "PP") {
560
+ if (network_type === "evm") {
561
+ account_address = account_info.data[i].ciphertexts.evm.address;
481
562
  } else {
482
- option_accounts.push(`#${i} ${account_info.data[i].ciphertexts.solana.address} ${tag} [${default_network}]`);
563
+ account_address = account_info.data[i].ciphertexts.solana.address;
483
564
  }
565
+ } else {
566
+ account_address = account_info.data[i].ciphertexts.address;
567
+ }
568
+
569
+ if (is_disable_address) {
570
+ option_accounts.push(
571
+ new inquirer.Separator(chalk.yellow(`#${i} ${formatAddr(account_address, status.fullAddr)} ${tag}`))
572
+ )
573
+ } else {
574
+ option_accounts.push(`#${i} ${formatAddr(account_address, status.fullAddr)} ${tag}`);
484
575
  }
485
576
  }
486
577
 
487
- let selected_account = await selectSomething(option_accounts, "Select an account");
488
- if (selected_account === "> Back") {
578
+ let selected_default_account = DEFAULT_ACCOUNT.account_label === account_label ? option_accounts[DEFAULT_ACCOUNT.account_index] : option_accounts[0];
579
+
580
+ let asset_info_list = await getAssetList(keystore_path, network_info.chainId);
581
+ let selected_account = await listWithLazyBalanceLoading(
582
+ option_accounts,
583
+ network_type === "evm",
584
+ keystore_path,
585
+ asset_info_list,
586
+ network_info,
587
+ status.gasToken,
588
+ status.extendedToken,
589
+ "Select an account",
590
+ selected_default_account
591
+ );
592
+
593
+ if (selected_account === '> Back') {
489
594
  return;
490
595
  }
491
596
 
492
- let selected_account_id = option_accounts.indexOf(selected_account) - 1;
597
+ DEFAULT_ACCOUNT.account_label = account_label;
598
+ DEFAULT_ACCOUNT.account_index = option_accounts.indexOf(selected_account);
493
599
 
494
- await showPPAccountDetail(keystore_path, account_label, selected_account_id, wative_core);
495
- await showPPAccounts(keystore_path, account_label, wative_core);
600
+ await showAccountDetail(keystore_path, account_label, option_accounts.indexOf(selected_account) - 2, wative_core);
601
+ await showAccounts(keystore_path, account_label, wative_core);
496
602
  }
497
603
 
498
- const showPPAccountDetail = async (keystore_path: string, account_label: string, selected_account_id: number, wative_core: typeof WativeCore) => {
604
+ const showAccountDetail = async (keystore_path: string, account_label: string, selected_account_id: number, wative_core: typeof WativeCore) => {
499
605
  const account_info = await getAccountInfo(keystore_path, account_label);
500
606
 
501
607
  let default_network = account_info.default_network;
502
- if ("default_network" in account_info.data[selected_account_id]) {
503
- default_network = account_info.data[selected_account_id].default_network;
504
- }
608
+ let account_address = getAccountAddress(keystore_path, account_label, selected_account_id);
505
609
 
506
610
  const network = await getNetworkInfoByName(keystore_path, default_network);
507
- let account_address = getAccountAddress(keystore_path, account_label, selected_account_id);
508
611
  const balance_result = await getAccountBalance(
509
612
  account_address,
510
613
  keystore_path,
511
614
  default_network
512
615
  );
513
-
514
616
  if (balance_result.status) {
515
617
  console.log(
516
618
  chalk.green(` Address No: #${selected_account_id}\n Network: ${default_network}\n ${network.nativeCurrency.symbol} Balance: ${balance_result.output}`)
@@ -521,17 +623,21 @@ const showPPAccountDetail = async (keystore_path: string, account_label: string,
521
623
  );
522
624
  }
523
625
 
524
- let tag = "> Tag()";
525
- if ("tag" in account_info.data[selected_account_id] && account_info.data[selected_account_id].tag !== "") {
626
+ let tag = '> Tag';
627
+ if (
628
+ "tag" in account_info.data[selected_account_id] &&
629
+ account_info.data[selected_account_id].tag !== ""
630
+ ) {
526
631
  tag = `> Tag(${account_info.data[selected_account_id].tag})`;
527
632
  }
528
633
 
529
634
  let options_account_detail = [
530
635
  tag,
531
- '> Switch network',
636
+ '> Show address',
532
637
  '> Assets',
533
638
  '> Tools',
534
639
  '> Dump private key',
640
+ new inquirer.Separator('----------------------------------'),
535
641
  '> Back'
536
642
  ];
537
643
 
@@ -539,7 +645,7 @@ const showPPAccountDetail = async (keystore_path: string, account_label: string,
539
645
 
540
646
  switch (selected_account_detail) {
541
647
  case tag: {
542
- let cureent_tag = 'Current tag ()';
648
+ let cureent_tag = 'Current tag';
543
649
  if ("tag" in account_info.data[selected_account_id] && account_info.data[selected_account_id].tag !== "") {
544
650
  cureent_tag = `Current tag (${account_info.data[selected_account_id].tag})`;
545
651
  }
@@ -549,12 +655,13 @@ const showPPAccountDetail = async (keystore_path: string, account_label: string,
549
655
  saveAccountInfo(keystore_path, account_label, account_info);
550
656
  break;
551
657
  }
552
- case '> Switch network': {
553
- await switchPPNetwork(keystore_path, account_label, selected_account_id);
658
+ case '> Show address': {
659
+ await showAllAccounts(keystore_path, account_label, selected_account_id);
554
660
  break;
555
661
  }
556
662
  case '> Assets': {
557
- await showAssets(keystore_path, account_address, default_network);
663
+ await showAssetsDetail(keystore_path, default_network, account_address);
664
+ // await showAssets(keystore_path, account_address, default_network);
558
665
  break;
559
666
  }
560
667
  case '> Tools': {
@@ -574,92 +681,6 @@ const showPPAccountDetail = async (keystore_path: string, account_label: string,
574
681
  }
575
682
  }
576
683
 
577
- const showPKAccounts = async (keystore_path: string, account_label: string, wative_core: typeof WativeCore) => {
578
- const account_info = await getAccountInfo(keystore_path, account_label);
579
- let option_accounts = [
580
- '> Back'
581
- ];
582
-
583
- let tag = "";
584
- if ("tag" in account_info && account_info.tag !== "") {
585
- tag = `(${account_info.tag})`;
586
- }
587
-
588
- option_accounts.push(`#0 ${account_info.ciphertexts.address} ${tag} [${account_info.default_network}]`);
589
- let selected_account = await selectSomething(option_accounts, "Select an account");
590
- if (selected_account === "> Back") {
591
- return;
592
- }
593
-
594
- let default_network = account_info.default_network;
595
- const network = await getNetworkInfoByName(keystore_path, default_network);
596
- console.log(
597
- chalk.green(` Address No: #0\n Network: ${default_network}\n ${network.nativeCurrency.symbol} Balance: 0`)
598
- );
599
-
600
- await showPKAccountDetail(keystore_path, account_label, wative_core);
601
- await showPKAccounts(keystore_path, account_label, wative_core);
602
- }
603
-
604
-
605
- const showPKAccountDetail = async (keystore_path: string, account_label: string, wative_core: typeof WativeCore) => {
606
- const account_info = await getAccountInfo(keystore_path, account_label);
607
- let tag = "> Tag()";
608
- if ("tag" in account_info && account_info.tag !== "") {
609
- tag = `> Tag(${account_info.tag})`;
610
- }
611
-
612
- let options_account_detail = [
613
- tag,
614
- '> Switch network',
615
- '> Assets',
616
- '> Tools',
617
- '> Dump private key',
618
- '> Back'
619
- ];
620
-
621
- let selected_account_detail = await selectSomething(options_account_detail);
622
-
623
- switch (selected_account_detail) {
624
- case tag: {
625
- let cureent_tag = 'Current tag ()';
626
- if ("tag" in account_info && account_info.tag !== "") {
627
- cureent_tag = `Current tag (${account_info.tag})`;
628
- }
629
- let tag = await inputSomething(cureent_tag, tagValidator);
630
- account_info.tag = tag.replace(/\s+/g, " ").trim().toLocaleLowerCase();
631
- saveAccountInfo(keystore_path, account_label, account_info);
632
- break;
633
- }
634
- case '> Switch network': {
635
- await switchNetworkByAccountLabel(keystore_path, account_label, false);
636
- break;
637
- }
638
- case '> Assets': {
639
- let account_address = getPKAccountAddress(keystore_path, account_label);
640
- await showAssets(keystore_path, account_address, account_info.default_network);
641
- break;
642
- }
643
- case '> Tools': {
644
- let account_address = getPKAccountAddress(keystore_path, account_label);
645
- await selectToolsOptions(keystore_path, account_label, account_address, wative_core);
646
- break;
647
- }
648
- case '> Dump private key': {
649
- let account_address = getPKAccountAddress(keystore_path, account_label);
650
- let private_key = await wative_core.account.showPrivateKey(account_address);
651
- console.log("account: ", account_address);
652
- console.log("private key: ", private_key);
653
- break;
654
- }
655
- case '> Back': {
656
- return;
657
- }
658
- }
659
-
660
- await showPKAccountDetail(keystore_path, account_label, wative_core);
661
- }
662
-
663
684
  const expandAddress = async (keystore_path: string, account_label: string, expand_amount: number, wative_core: typeof WativeCore) => {
664
685
  const account_info = await getAccountInfo(keystore_path, account_label);
665
686
  const account_len = account_info.data.length;
@@ -681,6 +702,7 @@ const expandAddress = async (keystore_path: string, account_label: string, expan
681
702
  bar1.stop();
682
703
 
683
704
  saveAccountInfo(keystore_path, account_label, account_info);
705
+ wative_core.account.reloadAccount();
684
706
  }
685
707
 
686
708
  const sliceAddress = async (keystore_path: string, account_label: string, last_account_no: number, wative_core: typeof WativeCore) => {
@@ -690,17 +712,65 @@ const sliceAddress = async (keystore_path: string, account_label: string, last_a
690
712
  wative_core.account.reloadAccount();
691
713
  }
692
714
 
715
+ const removeAddress = async (keystore_path: string, account_label: string, wative_core: typeof WativeCore) => {
716
+ let account_index = await inputSomething('Please input the accountIndex to remove this account', numberValidator);
717
+ if (account_index === "0") {
718
+ console.log(chalk.red("Can't remove the first account"));
719
+ return;
720
+ }
721
+
722
+ let account_info = await getAccountInfo(keystore_path, account_label);
723
+ let isConfirm = await confirmSomething(`Are you sure you want to remove this account(${account_info.data[account_index].ciphertexts.address})`);
724
+ if (!isConfirm) {
725
+ return;
726
+ }
727
+
728
+ account_info.data.splice(Number(account_index), 1);
729
+ saveAccountInfo(keystore_path, account_label, account_info);
730
+ wative_core.account.reloadAccount();
731
+ }
732
+
733
+ const removeAccountLabel = async (keystore_path: string, account_label: string) => {
734
+ let _accountLabel = await inputSomething('Please input the accountLabel to remove this account');
735
+ if (_accountLabel !== account_label) {
736
+ console.log(chalk.red("Can't remove this account"));
737
+ return;
738
+ }
739
+
740
+ const isConfirm = await confirmSomething(`Are you sure you want to remove this account(${account_label})`);
741
+ if (!isConfirm) {
742
+ return;
743
+ }
744
+
745
+ let account_label_path = path.join(keystore_path, `accounts/${account_label}.json`);
746
+ fs.rmSync(account_label_path);
747
+ }
748
+
749
+
693
750
  export const accountSetting = async (keystore_path: string, wative_core: typeof WativeCore) => {
694
751
  const account_path = path.resolve(keystore_path, 'accounts');
695
752
  if (!fs.existsSync(account_path)) {
696
753
  fs.mkdirSync(account_path);
697
754
  }
698
755
 
699
- const account_setting_options = [
700
- '> Select an account',
701
- '> Create a new account',
702
- '> Back'
703
- ];
756
+ const networks = getNetworkInfo(keystore_path);
757
+ const account_label_list = networks.accounts;
758
+
759
+ let account_setting_options: any[];
760
+ if (account_label_list.length === 0) {
761
+ account_setting_options = [
762
+ '> Create a new account',
763
+ new inquirer.Separator('----------------------------------'),
764
+ '> Back'
765
+ ];
766
+ } else {
767
+ account_setting_options = [
768
+ '> Select an account',
769
+ '> Create a new account',
770
+ new inquirer.Separator('----------------------------------'),
771
+ '> Back'
772
+ ];
773
+ }
704
774
 
705
775
  let selected_account_setting = await selectSomething(account_setting_options);
706
776