wative 1.0.35 → 1.0.37

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
@@ -2,7 +2,7 @@ const chalk = require('chalk');
2
2
  import * as fs from "fs";
3
3
  import * as path from "path";
4
4
  import {
5
- getAccountLabel,
5
+ getAccountName,
6
6
  selectSomething,
7
7
  inputPassword,
8
8
  inputSomething,
@@ -17,9 +17,10 @@ import {
17
17
  formatAddr,
18
18
  listWithLazyBalanceLoading,
19
19
  inputPasswordWithoutValidator,
20
- format_account_label,
20
+ getKeystoreSlugByAccountName,
21
+ getAccountNameByKeystoreSlug,
21
22
  } from "./utils";
22
- import { getAccountAddress, getAccountBalance, getNetworkInfoByName, getNetworkTypeByName, getStatus, selectDefaultNetwork, showAllAccounts, switchNetworkByAccountLabel } from "./network";
23
+ import { getAccountAddress, getAccountBalance, getNetworkInfoByName, getNetworkTypeByName, getStatus, selectDefaultNetwork, showAllAccounts, switchNetworkByAccountName } from "./network";
23
24
  import { getAssetList, showAssetsDetail } from './assets';
24
25
  import { selectToolsOptions } from './tools';
25
26
  import inquirer from "inquirer";
@@ -30,28 +31,28 @@ const cliProgress = require('cli-progress');
30
31
  const { WativeCore } = require("wative-core");
31
32
 
32
33
  const DEFAULT_ACCOUNT: any = {
33
- account_label: '',
34
+ keystore_slug: '',
34
35
  default_account_index: 0
35
36
  };
36
37
 
37
38
  const preAccountImport = async (keystore_path: string) => {
38
39
  const networks = getNetworkInfo(keystore_path)
39
40
 
40
- let account_label_list: string[] = [];
41
+ let account_name_list: string[] = [];
41
42
  if (networks.accounts) {
42
- account_label_list = networks.accounts;
43
+ account_name_list = networks.accounts;
43
44
  }
44
45
 
45
- let account_label = await getAccountLabel('Account Label', account_label_list);
46
- if (account_label === null) {
46
+ let account_name = await getAccountName('Account Name', account_name_list);
47
+ if (account_name === null) {
47
48
  return null;
48
49
  }
49
50
 
50
- let password = await inputPassword(`Please set a password for Account [${account_label}]`);
51
+ let password = await inputPassword(`Please set a password for Account [${account_name}]`);
51
52
  let selected_default_network = await selectDefaultNetwork(keystore_path);
52
53
 
53
54
  let pre_account_info = {
54
- account_label,
55
+ account_name,
55
56
  password,
56
57
  selected_default_network
57
58
  };
@@ -72,22 +73,22 @@ const importPassphrase = async (keystore_path: string, wative_core: typeof Wativ
72
73
  let passphrase = await inputSomething('Please enter a mnemonic [split by space]', passphraseValidator);
73
74
  passphrase = passphrase.replace(/\s+/g, " ");
74
75
 
75
- let formatted_account_label = format_account_label(pre_account_info.account_label);
76
- const passphrase_account = wative_core.account.generatePPAccount(formatted_account_label, passphrase, pre_account_info.password);
76
+ let keystore_slug = getKeystoreSlugByAccountName(pre_account_info.account_name);
77
+ const passphrase_account = wative_core.account.generatePPAccount(keystore_slug, passphrase, pre_account_info.password);
77
78
  if (!passphrase_account.status) {
78
79
  console.log(
79
80
  chalk.red(passphrase_account.output)
80
81
  );
81
82
  return;
82
83
  }
83
- let account_info_path = path.join(keystore_path, `accounts/${formatted_account_label}.json`);
84
+ let account_info_path = path.join(keystore_path, `accounts/${keystore_slug}.json`);
84
85
 
85
86
  passphrase_account.output.default_network = pre_account_info.selected_default_network;
86
87
  fs.writeFileSync(account_info_path, JSON.stringify(passphrase_account.output, null, 4));
87
88
 
88
89
  const network_path = path.resolve(keystore_path, 'network.json');
89
90
  const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
90
- networks.accounts.push(pre_account_info.account_label);
91
+ networks.accounts.push(pre_account_info.account_name);
91
92
  fs.writeFileSync(network_path, JSON.stringify(networks, null, 4));
92
93
  }
93
94
 
@@ -99,11 +100,11 @@ const createPrivateKeyAccount = async (keystore_path: string, wative_core: typeo
99
100
  }
100
101
 
101
102
  let private_key = await inputSomething('Please enter a private key');
102
- let formatted_account_label = format_account_label(pre_account_info.account_label);
103
+ let keystore_slug = getKeystoreSlugByAccountName(pre_account_info.account_name);
103
104
  await _importAccount(
104
105
  keystore_path,
105
106
  pre_account_info.password,
106
- formatted_account_label,
107
+ keystore_slug,
107
108
  private_key,
108
109
  pre_account_info.selected_default_network,
109
110
  wative_core,
@@ -112,7 +113,7 @@ const createPrivateKeyAccount = async (keystore_path: string, wative_core: typeo
112
113
 
113
114
  const network_path = path.resolve(keystore_path, 'network.json');
114
115
  const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
115
- networks.accounts.push(pre_account_info.account_label);
116
+ networks.accounts.push(pre_account_info.account_name);
116
117
 
117
118
  fs.writeFileSync(network_path, JSON.stringify(networks, null, 4));
118
119
  }
@@ -120,17 +121,17 @@ const createPrivateKeyAccount = async (keystore_path: string, wative_core: typeo
120
121
  const importPrivateKeyAccount = async (
121
122
  keystore_path: string,
122
123
  password: string,
123
- account_label: string,
124
+ keystore_slug: string,
124
125
  wative_core: typeof WativeCore
125
126
  ) => {
126
127
  let private_key = await inputSomething('Please enter a private key');
127
- let account_info_path = path.join(keystore_path, `accounts/${account_label}.json`);
128
+ let account_info_path = path.join(keystore_path, `accounts/${keystore_slug}.json`);
128
129
  let exist_account_info = JSON.parse(fs.readFileSync(account_info_path, 'utf8'));
129
130
 
130
131
  await _importAccount(
131
132
  keystore_path,
132
133
  password,
133
- account_label,
134
+ keystore_slug,
134
135
  private_key,
135
136
  exist_account_info.default_network,
136
137
  wative_core,
@@ -141,11 +142,11 @@ const importPrivateKeyAccount = async (
141
142
  const _importAccount = async (
142
143
  keystore_path: string,
143
144
  password: string,
144
- account_label: string,
145
+ keystore_slug: string,
145
146
  private_key: string,
146
147
  default_network: string,
147
148
  wative_core: typeof WativeCore,
148
- generate_account_label: boolean
149
+ generate_keystore_slug: boolean
149
150
  ) => {
150
151
  let network_info = await getNetworkInfoByName(keystore_path, default_network);
151
152
 
@@ -154,14 +155,14 @@ const _importAccount = async (
154
155
  private_key = "0x" + private_key;
155
156
  }
156
157
 
157
- let privatekey_account = await wative_core.account.generatePKAccount(account_label, private_key, password, network_info.chainId.toString(), generate_account_label);
158
+ let privatekey_account = await wative_core.account.generatePKAccount(keystore_slug, private_key, password, network_info.chainId.toString(), generate_keystore_slug);
158
159
  if (!privatekey_account.status) {
159
160
  console.log(
160
161
  chalk.red(privatekey_account.output)
161
162
  );
162
163
  return;
163
164
  }
164
- let account_info_path = path.join(keystore_path, `accounts/${account_label}.json`);
165
+ let account_info_path = path.join(keystore_path, `accounts/${keystore_slug}.json`);
165
166
 
166
167
  let result: any;
167
168
  if (fs.existsSync(account_info_path)) {
@@ -228,29 +229,31 @@ export const getNetworkInfo = (keystore_path: string) => {
228
229
  return networks;
229
230
  }
230
231
 
231
- export const getAccountInfo = (keystore_path: string, account_label: string) => {
232
- const account_info_path = path.join(keystore_path, `accounts/${account_label}.json`);
232
+ export const getAccountInfo = (keystore_path: string, keystore_slug: string) => {
233
+ const account_info_path = path.join(keystore_path, `accounts/${keystore_slug}.json`);
233
234
  const account_info = JSON.parse(fs.readFileSync(account_info_path, 'utf8'));
234
235
  return account_info;
235
236
  }
236
237
 
237
- export const saveAccountInfo = (keystore_path: string, account_label: string, account_info: any) => {
238
- const account_info_path = path.join(keystore_path, `accounts/${account_label}.json`);
238
+ export const saveAccountInfo = (keystore_path: string, keystore_slug: string, account_info: any) => {
239
+ const account_info_path = path.join(keystore_path, `accounts/${keystore_slug}.json`);
239
240
  fs.writeFileSync(account_info_path, JSON.stringify(account_info, null, 4));
240
241
  }
241
242
 
242
- export const loginIn = async (account_label: string, wative_core: typeof WativeCore) => {
243
- const is_login = wative_core.account.isLogin(account_label);
243
+ export const loginIn = async (keystore_path: string, keystore_slug: string, wative_core: typeof WativeCore) => {
244
+ const is_login = wative_core.account.isLogin(keystore_slug);
244
245
  if (is_login) {
245
246
  return { isLoginIn: true };
246
247
  }
247
248
 
248
249
  for (let i = 0; i < 3; i++) {
250
+ let account_name = getAccountNameByKeystoreSlug(keystore_path, keystore_slug);
251
+
249
252
  let password: any;
250
253
  if (process.env.WativePassword && process.env.WativePassword !== '') {
251
254
  password = process.env.WativePassword;
252
255
  } else {
253
- password = await inputPasswordWithoutValidator(`Please input the password for Account [${account_label}]`);
256
+ password = await inputPasswordWithoutValidator(`Please input the password for Account [${account_name}]`);
254
257
  }
255
258
  if (!password) {
256
259
  console.log(
@@ -259,7 +262,7 @@ export const loginIn = async (account_label: string, wative_core: typeof WativeC
259
262
  return { isLoginIn: false };
260
263
  }
261
264
 
262
- const login_result = await wative_core.account.login(account_label, password);
265
+ const login_result = await wative_core.account.login(keystore_slug, password);
263
266
  if (login_result.status) {
264
267
  return { isLoginIn: true, password };
265
268
  }
@@ -280,29 +283,29 @@ export const loginIn = async (account_label: string, wative_core: typeof WativeC
280
283
 
281
284
  const selectAccount = async (keystore_path: string, wative_core: typeof WativeCore) => {
282
285
  const networks = getNetworkInfo(keystore_path);
283
- const account_label_list = networks.accounts;
286
+ const account_name_list = networks.accounts;
284
287
 
285
288
  let select_account_options = [
286
289
  '> Back',
287
290
  new inquirer.Separator('----------------------------------')
288
291
  ];
289
292
 
290
- const account_label_len = account_label_list.length;
291
- if (account_label_len === 0) {
293
+ const account_name_len = account_name_list.length;
294
+ if (account_name_len === 0) {
292
295
  console.log(
293
296
  chalk.red("No address here yet")
294
297
  );
295
298
  return;
296
299
  }
297
300
 
298
- for (let i = 0; i < account_label_len; i++) {
299
- const account_label = account_label_list[i];
300
- const formatted_account_label = format_account_label(account_label);
301
- const account_info = getAccountInfo(keystore_path, formatted_account_label);
301
+ for (let i = 0; i < account_name_len; i++) {
302
+ const account_name = account_name_list[i];
303
+ const keystore_slug = getKeystoreSlugByAccountName(account_name);
304
+ const account_info = getAccountInfo(keystore_path, keystore_slug);
302
305
  if ("data" in account_info) {
303
- select_account_options.push(`${i + 1}) ${account_label} [${account_info.account_type}:${account_info.data.length}]`);
306
+ select_account_options.push(`${i + 1}) ${account_name} [${account_info.account_type}:${account_info.data.length}]`);
304
307
  } else {
305
- select_account_options.push(`${i + 1}) ${account_label} [${account_info.account_type}:1]`);
308
+ select_account_options.push(`${i + 1}) ${account_name} [${account_info.account_type}:1]`);
306
309
  }
307
310
  }
308
311
 
@@ -311,19 +314,19 @@ const selectAccount = async (keystore_path: string, wative_core: typeof WativeCo
311
314
  return;
312
315
  }
313
316
 
314
- const selected_account_label = account_label_list[select_account_options.indexOf(selected_account) - 2];
315
- const formatted_account_label = format_account_label(selected_account_label);
317
+ const selected_account_name = account_name_list[select_account_options.indexOf(selected_account) - 2];
318
+ const keystore_slug = getKeystoreSlugByAccountName(selected_account_name);
316
319
 
317
- let login_result = await loginIn(formatted_account_label, wative_core);
320
+ let login_result = await loginIn(keystore_path, keystore_slug, wative_core);
318
321
  if (login_result.isLoginIn) {
319
- await accountManager(keystore_path, formatted_account_label, wative_core, login_result.password);
322
+ await accountManager(keystore_path, keystore_slug, wative_core, login_result.password);
320
323
  }
321
324
 
322
325
  await selectAccount(keystore_path, wative_core);
323
326
  }
324
327
 
325
- const setDisableAddress = async (keystore_path: string, account_label: string, wative_core: typeof WativeCore) => {
326
- const account_info = await getAccountInfo(keystore_path, account_label);
328
+ const setDisableAddress = async (keystore_path: string, keystore_slug: string, wative_core: typeof WativeCore) => {
329
+ const account_info = await getAccountInfo(keystore_path, keystore_slug);
327
330
 
328
331
  let disable_address_options = [
329
332
  "> Disabled Slots",
@@ -416,7 +419,7 @@ const setDisableAddress = async (keystore_path: string, account_label: string, w
416
419
  let selected_disabled_slots_index = disabled_slots_options.indexOf(selected_disabled_slots) - 2;
417
420
 
418
421
  account_info.disabled_slots.splice(selected_disabled_slots_index, 1);
419
- saveAccountInfo(keystore_path, account_label, account_info);
422
+ saveAccountInfo(keystore_path, keystore_slug, account_info);
420
423
 
421
424
  break;
422
425
  }
@@ -439,7 +442,7 @@ const setDisableAddress = async (keystore_path: string, account_label: string, w
439
442
  }];
440
443
  }
441
444
 
442
- saveAccountInfo(keystore_path, account_label, account_info);
445
+ saveAccountInfo(keystore_path, keystore_slug, account_info);
443
446
  break;
444
447
  }
445
448
  case "> Add Range": {
@@ -455,17 +458,17 @@ const setDisableAddress = async (keystore_path: string, account_label: string, w
455
458
  account_info.disabled_slots = [account_range];
456
459
  }
457
460
 
458
- saveAccountInfo(keystore_path, account_label, account_info);
461
+ saveAccountInfo(keystore_path, keystore_slug, account_info);
459
462
  break;
460
463
  }
461
464
  }
462
465
 
463
- await setDisableAddress(keystore_path, account_label, wative_core);
466
+ await setDisableAddress(keystore_path, keystore_slug, wative_core);
464
467
  }
465
468
 
466
469
 
467
- const accountManager = async (keystore_path: string, account_label: string, wative_core: typeof WativeCore, password: string) => {
468
- let account_info = await getAccountInfo(keystore_path, account_label);
470
+ const accountManager = async (keystore_path: string, keystore_slug: string, wative_core: typeof WativeCore, password: string) => {
471
+ let account_info = await getAccountInfo(keystore_path, keystore_slug);
469
472
 
470
473
  let account_manager_options: any[];
471
474
 
@@ -497,7 +500,7 @@ const accountManager = async (keystore_path: string, account_label: string, wati
497
500
  const selected_account_manager = await selectSomething(account_manager_options);
498
501
  switch (selected_account_manager) {
499
502
  case '> Address List': {
500
- await showAccounts(keystore_path, account_label, wative_core);
503
+ await showAccounts(keystore_path, keystore_slug, wative_core);
501
504
  break;
502
505
  }
503
506
  case '> Expand Address': {
@@ -509,29 +512,30 @@ const accountManager = async (keystore_path: string, account_label: string, wati
509
512
  break;
510
513
  }
511
514
 
512
- await expandAddress(keystore_path, account_label, Number(count), wative_core);
515
+ await expandAddress(keystore_path, keystore_slug, Number(count), wative_core);
513
516
  break;
514
517
  }
515
518
  case '> Import Private Key': {
516
- await importPrivateKeyAccount(keystore_path, password, account_label, wative_core);
519
+ await importPrivateKeyAccount(keystore_path, password, keystore_slug, wative_core);
517
520
  break;
518
521
  }
519
522
  case '> Slice Address': {
520
523
  const last_account_no = await inputSomething('Please input last account number', lastAccountNoValidator);
521
- await sliceAddress(keystore_path, account_label, Number(last_account_no), wative_core);
524
+ await sliceAddress(keystore_path, keystore_slug, Number(last_account_no), wative_core);
522
525
  break;
523
526
  }
524
527
  case '> Remove Address': {
525
- await removeAddress(keystore_path, account_label, wative_core);
528
+ await removeAddress(keystore_path, keystore_slug, wative_core);
526
529
  break;
527
530
  }
528
531
  case '> Disable Address': {
529
- await setDisableAddress(keystore_path, account_label, wative_core);
532
+ await setDisableAddress(keystore_path, keystore_slug, wative_core);
530
533
  break;
531
534
  }
532
535
  case '> Reset Account Password': {
533
- const password1 = await inputPassword(`Please input new password for Account [${account_label}]`);
534
- const password2 = await inputPassword(`Please confirm new password for Account [${account_label}]`);
536
+ let account_name = getAccountNameByKeystoreSlug(keystore_path, keystore_slug);
537
+ const password1 = await inputPassword(`Please input new password for Account [${account_name}]`);
538
+ const password2 = await inputPassword(`Please confirm new password for Account [${account_name}]`);
535
539
 
536
540
  if (!password1 || !password2 || password1 !== password2) {
537
541
  console.log(
@@ -540,15 +544,15 @@ const accountManager = async (keystore_path: string, account_label: string, wati
540
544
  break;
541
545
  }
542
546
 
543
- await wative_core.account.resetPassword(account_label, password1);
547
+ await wative_core.account.resetPassword(keystore_slug, password1);
544
548
  return;
545
549
  }
546
550
  case `> Switch Networks [${account_info.default_network}]`: {
547
- await switchNetworkByAccountLabel(keystore_path, account_label, true);
551
+ await switchNetworkByAccountName(keystore_path, keystore_slug, true);
548
552
  break;
549
553
  }
550
554
  case '> Remove': {
551
- await removeAccountLabel(keystore_path, account_label);
555
+ await removeAccountName(keystore_path, keystore_slug);
552
556
  return;
553
557
  }
554
558
  case '> Back': {
@@ -556,11 +560,11 @@ const accountManager = async (keystore_path: string, account_label: string, wati
556
560
  }
557
561
  }
558
562
 
559
- await accountManager(keystore_path, account_label, wative_core, password);
563
+ await accountManager(keystore_path, keystore_slug, wative_core, password);
560
564
  }
561
565
 
562
- const showAccounts = async (keystore_path: string, account_label: string, wative_core: typeof WativeCore) => {
563
- const account_info = await getAccountInfo(keystore_path, account_label);
566
+ const showAccounts = async (keystore_path: string, keystore_slug: string, wative_core: typeof WativeCore) => {
567
+ const account_info = await getAccountInfo(keystore_path, keystore_slug);
564
568
 
565
569
  let option_accounts: any = [
566
570
  '> Back',
@@ -598,7 +602,7 @@ const showAccounts = async (keystore_path: string, account_label: string, wative
598
602
  }
599
603
  }
600
604
 
601
- let selected_default_account = DEFAULT_ACCOUNT.account_label === account_label ? option_accounts[DEFAULT_ACCOUNT.account_index] : option_accounts[0];
605
+ let selected_default_account = DEFAULT_ACCOUNT.keystore_slug === keystore_slug ? option_accounts[DEFAULT_ACCOUNT.account_index] : option_accounts[0];
602
606
 
603
607
  let asset_info_list = await getAssetList(keystore_path, network_info.chainId.toString());
604
608
  let selected_account = await listWithLazyBalanceLoading(
@@ -617,18 +621,18 @@ const showAccounts = async (keystore_path: string, account_label: string, wative
617
621
  return;
618
622
  }
619
623
 
620
- DEFAULT_ACCOUNT.account_label = account_label;
624
+ DEFAULT_ACCOUNT.keystore_slug = keystore_slug;
621
625
  DEFAULT_ACCOUNT.account_index = option_accounts.indexOf(selected_account);
622
626
 
623
- await showAccountDetail(keystore_path, account_label, option_accounts.indexOf(selected_account) - 2, wative_core);
624
- await showAccounts(keystore_path, account_label, wative_core);
627
+ await showAccountDetail(keystore_path, keystore_slug, option_accounts.indexOf(selected_account) - 2, wative_core);
628
+ await showAccounts(keystore_path, keystore_slug, wative_core);
625
629
  }
626
630
 
627
- const showAccountDetail = async (keystore_path: string, account_label: string, selected_account_id: number, wative_core: typeof WativeCore) => {
628
- const account_info = await getAccountInfo(keystore_path, account_label);
631
+ const showAccountDetail = async (keystore_path: string, keystore_slug: string, selected_account_id: number, wative_core: typeof WativeCore) => {
632
+ const account_info = await getAccountInfo(keystore_path, keystore_slug);
629
633
 
630
634
  let default_network = account_info.default_network;
631
- let account_address = getAccountAddress(keystore_path, account_label, selected_account_id);
635
+ let account_address = getAccountAddress(keystore_path, keystore_slug, selected_account_id);
632
636
 
633
637
  const network = await getNetworkInfoByName(keystore_path, default_network);
634
638
  const balance_result = await getAccountBalance(
@@ -674,11 +678,11 @@ const showAccountDetail = async (keystore_path: string, account_label: string, s
674
678
  }
675
679
  let tag = await inputSomething(current_tag, tagValidator);
676
680
  account_info.data[selected_account_id].tag = tag.replace(/\s+/g, " ").trim();
677
- saveAccountInfo(keystore_path, account_label, account_info);
681
+ saveAccountInfo(keystore_path, keystore_slug, account_info);
678
682
  break;
679
683
  }
680
684
  case '> Show address': {
681
- await showAllAccounts(keystore_path, account_label, selected_account_id);
685
+ await showAllAccounts(keystore_path, keystore_slug, selected_account_id);
682
686
  break;
683
687
  }
684
688
  case '> Assets': {
@@ -687,11 +691,11 @@ const showAccountDetail = async (keystore_path: string, account_label: string, s
687
691
  break;
688
692
  }
689
693
  case '> Tools': {
690
- await selectToolsOptions(keystore_path, account_label, account_address, wative_core);
694
+ await selectToolsOptions(keystore_path, keystore_slug, account_address, wative_core);
691
695
  break;
692
696
  }
693
697
  case '> Dump private key': {
694
- let account_address = getAccountAddress(keystore_path, account_label, selected_account_id);
698
+ let account_address = getAccountAddress(keystore_path, keystore_slug, selected_account_id);
695
699
  let private_key = await wative_core.account.showPrivateKey(account_address);
696
700
  console.log("account: ", account_address);
697
701
  console.log("private key: ", private_key);
@@ -703,13 +707,13 @@ const showAccountDetail = async (keystore_path: string, account_label: string, s
703
707
  }
704
708
  }
705
709
 
706
- const expandAddress = async (keystore_path: string, account_label: string, expand_amount: number, wative_core: typeof WativeCore) => {
707
- const account_info = await getAccountInfo(keystore_path, account_label);
710
+ const expandAddress = async (keystore_path: string, keystore_slug: string, expand_amount: number, wative_core: typeof WativeCore) => {
711
+ const account_info = await getAccountInfo(keystore_path, keystore_slug);
708
712
  const account_len = account_info.data.length;
709
713
  const bar1 = new cliProgress.SingleBar({}, cliProgress.Presets.legacy);
710
714
  bar1.start(expand_amount, 0);
711
715
  for (let i = account_len; i < account_len + expand_amount; i++) {
712
- let sub_account = await wative_core.account.generateSubAccount(account_label, i);
716
+ let sub_account = await wative_core.account.generateSubAccount(keystore_slug, i);
713
717
  if (!sub_account.status) {
714
718
  console.log(
715
719
  chalk.red(sub_account.output)
@@ -723,49 +727,50 @@ const expandAddress = async (keystore_path: string, account_label: string, expan
723
727
  }
724
728
  bar1.stop();
725
729
 
726
- saveAccountInfo(keystore_path, account_label, account_info);
730
+ saveAccountInfo(keystore_path, keystore_slug, account_info);
727
731
  wative_core.account.reloadAccount();
728
732
  }
729
733
 
730
- const sliceAddress = async (keystore_path: string, account_label: string, last_account_no: number, wative_core: typeof WativeCore) => {
731
- const account_info = await getAccountInfo(keystore_path, account_label);
734
+ const sliceAddress = async (keystore_path: string, keystore_slug: string, last_account_no: number, wative_core: typeof WativeCore) => {
735
+ const account_info = await getAccountInfo(keystore_path, keystore_slug);
732
736
  account_info.data = account_info.data.slice(0, last_account_no + 1);
733
- saveAccountInfo(keystore_path, account_label, account_info);
737
+ saveAccountInfo(keystore_path, keystore_slug, account_info);
734
738
  wative_core.account.reloadAccount();
735
739
  }
736
740
 
737
- const removeAddress = async (keystore_path: string, account_label: string, wative_core: typeof WativeCore) => {
741
+ const removeAddress = async (keystore_path: string, keystore_slug: string, wative_core: typeof WativeCore) => {
738
742
  let account_index = await inputSomething('Please input the accountIndex to remove this account', numberValidator);
739
743
  if (account_index === "0") {
740
744
  console.log(chalk.red("Can't remove the first account"));
741
745
  return;
742
746
  }
743
747
 
744
- let account_info = await getAccountInfo(keystore_path, account_label);
748
+ let account_info = await getAccountInfo(keystore_path, keystore_slug);
745
749
  let isConfirm = await confirmSomething(`Are you sure you want to remove this account(${account_info.data[account_index].ciphertexts.address})`, true);
746
750
  if (!isConfirm) {
747
751
  return;
748
752
  }
749
753
 
750
754
  account_info.data.splice(Number(account_index), 1);
751
- saveAccountInfo(keystore_path, account_label, account_info);
755
+ saveAccountInfo(keystore_path, keystore_slug, account_info);
752
756
  wative_core.account.reloadAccount();
753
757
  }
754
758
 
755
- const removeAccountLabel = async (keystore_path: string, account_label: string) => {
756
- let _accountLabel = await inputSomething('Please input the accountLabel to remove this account');
757
- if (_accountLabel !== account_label) {
759
+ const removeAccountName = async (keystore_path: string, keystore_slug: string) => {
760
+ let _account_name = await inputSomething('Please input the account name to remove this account');
761
+ let account_name = getAccountNameByKeystoreSlug(keystore_path, keystore_slug);
762
+ if (_account_name !== account_name) {
758
763
  console.log(chalk.red("Can't remove this account"));
759
764
  return;
760
765
  }
761
766
 
762
- const isConfirm = await confirmSomething(`Are you sure you want to remove this account(${account_label})`, true);
767
+ const isConfirm = await confirmSomething(`Are you sure you want to remove this account(${account_name})`, true);
763
768
  if (!isConfirm) {
764
769
  return;
765
770
  }
766
771
 
767
- let account_label_path = path.join(keystore_path, `accounts/${account_label}.json`);
768
- fs.rmSync(account_label_path);
772
+ let keystore_slug_path = path.join(keystore_path, `accounts/${keystore_slug}.json`);
773
+ fs.rmSync(keystore_slug_path);
769
774
 
770
775
  const network_path = path.resolve(keystore_path, 'network.json');
771
776
  if (!fs.existsSync(network_path)) {
@@ -773,8 +778,8 @@ const removeAccountLabel = async (keystore_path: string, account_label: string)
773
778
  }
774
779
 
775
780
  const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
776
- let account_label_index = networks.accounts.indexOf(account_label);
777
- networks.accounts.splice(account_label_index, 1);
781
+ let account_name_index = networks.accounts.indexOf(account_name);
782
+ networks.accounts.splice(account_name_index, 1);
778
783
  fs.writeFileSync(network_path, JSON.stringify(networks, null, 2));
779
784
  }
780
785
 
@@ -785,10 +790,10 @@ export const accountSetting = async (keystore_path: string, wative_core: typeof
785
790
  }
786
791
 
787
792
  const networks = getNetworkInfo(keystore_path);
788
- const account_label_list = networks.accounts;
793
+ const account_name_list = networks.accounts;
789
794
 
790
795
  let account_setting_options: any[];
791
- if (account_label_list.length === 0) {
796
+ if (account_name_list.length === 0) {
792
797
  account_setting_options = [
793
798
  '> Create a new account',
794
799
  new inquirer.Separator('----------------------------------'),
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as fs from "fs";
2
2
  import * as path from "path";
3
- import { showIntroduction, getKeystorePath, updateStorage, batch_format_account_label } from "./utils";
3
+ import { showIntroduction, getKeystorePath, updateStorage, batchGetKeystoreSlugByAccountName } from "./utils";
4
4
  import { createNetwork } from "./network";
5
5
  import { showHomePage } from "./home_page";
6
6
 
@@ -20,8 +20,8 @@ const main = async () => {
20
20
 
21
21
  const network_path = path.resolve(keystore_path, 'network.json');
22
22
  const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
23
- let format_account_label_list = batch_format_account_label(networks.accounts);
24
- const wative_core = new WativeCore(keystore_path, format_account_label_list, null, true);
23
+ let getKeystoreSlugByAccountName_list = batchGetKeystoreSlugByAccountName(networks.accounts);
24
+ const wative_core = new WativeCore(keystore_path, getKeystoreSlugByAccountName_list, null, true);
25
25
  await showHomePage(keystore_path, wative_core);
26
26
  }
27
27