wative 1.0.34 → 1.0.36

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/network.ts CHANGED
@@ -541,8 +541,8 @@ export const getNetworkInfoByName = (keystore_path: string, network_name: string
541
541
  return null;
542
542
  }
543
543
 
544
- export const getAccountAddress = (keystore_path: string, account_label: string, account_id: number) => {
545
- const account_info = getAccountInfo(keystore_path, account_label);
544
+ export const getAccountAddress = (keystore_path: string, keystore_slug: string, account_id: number) => {
545
+ const account_info = getAccountInfo(keystore_path, keystore_slug);
546
546
 
547
547
  if (account_info.account_type === "PK") {
548
548
  return account_info.data[account_id].ciphertexts.address;
@@ -560,18 +560,18 @@ export const getAccountAddress = (keystore_path: string, account_label: string,
560
560
  return null;
561
561
  }
562
562
 
563
- export const getPKAccountAddress = (keystore_path: string, account_label: string) => {
564
- const account_info = getAccountInfo(keystore_path, account_label);
563
+ export const getPKAccountAddress = (keystore_path: string, keystore_slug: string) => {
564
+ const account_info = getAccountInfo(keystore_path, keystore_slug);
565
565
  return account_info.ciphertexts.address;
566
566
  }
567
567
 
568
- export const switchPPNetwork = async (keystore_path: string, account_label: string, account_id: number) => {
568
+ export const switchPPNetwork = async (keystore_path: string, keystore_slug: string, account_id: number) => {
569
569
  const network_path = path.resolve(keystore_path, 'network.json');
570
570
  const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
571
571
  const network_list = networks.networks;
572
572
  const network_len = network_list.length;
573
573
 
574
- let account_info = getAccountInfo(keystore_path, account_label);
574
+ let account_info = getAccountInfo(keystore_path, keystore_slug);
575
575
  let options_switch_network = [
576
576
  '> Back',
577
577
  new inquirer.Separator('----------------------------------')
@@ -613,7 +613,7 @@ export const switchPPNetwork = async (keystore_path: string, account_label: stri
613
613
  account_info.data[account_id].default_network = network_list[selected_network_id - 3].name;
614
614
  }
615
615
 
616
- saveAccountInfo(keystore_path, account_label, account_info);
616
+ saveAccountInfo(keystore_path, keystore_slug, account_info);
617
617
 
618
618
  let new_default_network = account_info.default_network;
619
619
  if ("default_network" in account_info.data[account_id] && account_info.data[account_id].default_network !== "") {
@@ -626,13 +626,13 @@ export const switchPPNetwork = async (keystore_path: string, account_label: stri
626
626
  );
627
627
  }
628
628
 
629
- export const showAllAccounts = async (keystore_path: string, account_label: string, account_index: number) => {
629
+ export const showAllAccounts = async (keystore_path: string, keystore_slug: string, account_index: number) => {
630
630
  const network_path = path.resolve(keystore_path, 'network.json');
631
631
  const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
632
632
  const network_list = networks.networks;
633
633
  const network_len = network_list.length;
634
634
 
635
- let account_info = getAccountInfo(keystore_path, account_label);
635
+ let account_info = getAccountInfo(keystore_path, keystore_slug);
636
636
  let default_network = account_info.default_network;
637
637
 
638
638
  const network_type = getNetworkTypeByName(keystore_path, default_network);
@@ -664,13 +664,13 @@ export const showAllAccounts = async (keystore_path: string, account_label: stri
664
664
  }
665
665
  }
666
666
 
667
- export const switchNetworkByAccountLabel = async (keystore_path: string, account_label: string, is_account_label: boolean) => {
667
+ export const switchNetworkByAccountName = async (keystore_path: string, keystore_slug: string, is_keystore_slug: boolean) => {
668
668
  const network_path = path.resolve(keystore_path, 'network.json');
669
669
  const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
670
670
  const network_list = networks.networks;
671
671
  const network_len = network_list.length;
672
672
 
673
- let account_info = getAccountInfo(keystore_path, account_label);
673
+ let account_info = getAccountInfo(keystore_path, keystore_slug);
674
674
  let options_switch_network = [
675
675
  '> Back',
676
676
  new inquirer.Separator('----------------------------------'),
@@ -679,7 +679,7 @@ export const switchNetworkByAccountLabel = async (keystore_path: string, account
679
679
  let default_network = account_info.default_network;
680
680
 
681
681
  let account_address = "";
682
- if (!is_account_label) {
682
+ if (!is_keystore_slug) {
683
683
  account_address = account_info.ciphertexts.address;
684
684
  }
685
685
  let option_network_name_list: string[] = [];
@@ -693,13 +693,13 @@ export const switchNetworkByAccountLabel = async (keystore_path: string, account
693
693
  continue;
694
694
  }
695
695
  if (network.name === default_network) {
696
- if (is_account_label) {
696
+ if (is_keystore_slug) {
697
697
  options_switch_network.push(`● ${network.name}`);
698
698
  } else {
699
699
  options_switch_network.push(`● ${account_address} [${network.name}]`);
700
700
  }
701
701
  } else {
702
- if (is_account_label) {
702
+ if (is_keystore_slug) {
703
703
  options_switch_network.push(`○ ${network.name}`);
704
704
  } else {
705
705
  options_switch_network.push(`○ ${account_address} [${network.name}]`);
@@ -715,9 +715,9 @@ export const switchNetworkByAccountLabel = async (keystore_path: string, account
715
715
 
716
716
  let selected_network_id = options_switch_network.indexOf(selected_network);
717
717
  account_info.default_network = option_network_name_list[selected_network_id - 2];
718
- saveAccountInfo(keystore_path, account_label, account_info);
718
+ saveAccountInfo(keystore_path, keystore_slug, account_info);
719
719
 
720
- if (!is_account_label) {
720
+ if (!is_keystore_slug) {
721
721
  let new_default_network = account_info.default_network;
722
722
  let new_network = getNetworkInfoByName(keystore_path, new_default_network);
723
723
  console.log(
@@ -726,14 +726,14 @@ export const switchNetworkByAccountLabel = async (keystore_path: string, account
726
726
  }
727
727
  }
728
728
 
729
- export const accountBalanceLog = async (account_label: string, account_id: number, keystore_path: string, default_network: string) => {
730
- const account_info = getAccountInfo(keystore_path, account_label);
729
+ export const accountBalanceLog = async (keystore_slug: string, account_id: number, keystore_path: string, default_network: string) => {
730
+ const account_info = getAccountInfo(keystore_path, keystore_slug);
731
731
 
732
732
  let account_address: string;
733
733
  if (account_info.account_type === "PK") {
734
- account_address = getAccountAddress(keystore_path, account_label, account_id);
734
+ account_address = getAccountAddress(keystore_path, keystore_slug, account_id);
735
735
  } else {
736
- account_address = getPKAccountAddress(keystore_path, account_label);
736
+ account_address = getPKAccountAddress(keystore_path, keystore_slug);
737
737
  }
738
738
 
739
739
  const balance_result = await getAccountBalance(account_address, keystore_path, default_network);
@@ -778,8 +778,8 @@ export const getAccountBalance = async (account: string, keystore_path: string,
778
778
  return result;
779
779
  }
780
780
 
781
- export const getDefaultNetworkByAddress = (keystore_path: string, account_label: string, account_address: string) => {
782
- const account_info = getAccountInfo(keystore_path, account_label);
781
+ export const getDefaultNetworkByAddress = (keystore_path: string, keystore_slug: string, account_address: string) => {
782
+ const account_info = getAccountInfo(keystore_path, keystore_slug);
783
783
  if (account_info.account_type === "PK") {
784
784
  return account_info.default_network;
785
785
  }
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 { addrValidator, chainAddressValidator, confirmSomething, editorSomething, gasValidator, getAccountChainType, hexValidator, inputSomething, numberValidator, selectSomething, un_format_account_label } from "./utils";
4
+ import { addrValidator, chainAddressValidator, confirmSomething, editorSomething, gasValidator, getAccountChainType, hexValidator, inputSomething, numberValidator, selectSomething, getAccountNameByKeystoreSlug } 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';
@@ -720,8 +720,8 @@ const getTransferTokenAmount = async (max_value: string, token_symbols: string,
720
720
  return getTransferTokenAmount(max_value, token_symbols, decimals);
721
721
  }
722
722
 
723
- const excuteTools = async (keystore_path: string, account_label: string, account_address: string, wative_core: typeof WativeCore) => {
724
- let default_network = getDefaultNetworkByAddress(keystore_path, account_label, account_address);
723
+ const excuteTools = async (keystore_path: string, keystore_slug: string, account_address: string, wative_core: typeof WativeCore) => {
724
+ let default_network = getDefaultNetworkByAddress(keystore_path, keystore_slug, account_address);
725
725
  let network_type = getNetworkTypeByName(keystore_path, default_network);
726
726
  let account_chain_type = getAccountChainType(account_address);
727
727
 
@@ -817,7 +817,7 @@ const excuteTools = async (keystore_path: string, account_label: string, account
817
817
  }
818
818
  }
819
819
 
820
- export const selectToolsOptions = async (keystore_path: string, account_label: string, account_address: string, wative_core: typeof WativeCore) => {
820
+ export const selectToolsOptions = async (keystore_path: string, keystore_slug: string, account_address: string, wative_core: typeof WativeCore) => {
821
821
  const tools_options = [
822
822
  '> SendTx',
823
823
  '> SignMessage',
@@ -828,7 +828,7 @@ export const selectToolsOptions = async (keystore_path: string, account_label: s
828
828
  const selected_tools_option = await selectSomething(tools_options);
829
829
  switch (selected_tools_option) {
830
830
  case '> SendTx': {
831
- await excuteTools(keystore_path, account_label, account_address, wative_core);
831
+ await excuteTools(keystore_path, keystore_slug, account_address, wative_core);
832
832
  break;
833
833
  }
834
834
  case '> SignMessage': {
@@ -847,7 +847,7 @@ export const selectToolsOptions = async (keystore_path: string, account_label: s
847
847
  return;
848
848
  }
849
849
  }
850
- await selectToolsOptions(keystore_path, account_label, account_address, wative_core);
850
+ await selectToolsOptions(keystore_path, keystore_slug, account_address, wative_core);
851
851
  }
852
852
 
853
853
  export const showTools = async (keystore_path: string, wative_core: typeof WativeCore) => {
@@ -873,28 +873,28 @@ export const showTools = async (keystore_path: string, wative_core: typeof Wativ
873
873
  account_address = await inputSomething("Input part address to send tx", addrValidator);
874
874
  }
875
875
 
876
- let account_label_info = wative_core.account.getAccountLabel(account_address);
877
- if (account_label_info === null) {
876
+ let keystore_slug_info = wative_core.account.getAccountLabel(account_address);
877
+ if (keystore_slug_info === null) {
878
878
  console.log(chalk.red("Account not found"));
879
879
  await showTools(keystore_path, wative_core);
880
880
  return;
881
881
  }
882
882
 
883
- let account_label = account_label_info.account_label;
884
- let show_account_label = un_format_account_label(keystore_path, account_label);
885
- console.log(chalk.green(`Found account label: [${show_account_label}]`));
883
+ let keystore_slug = keystore_slug_info.account_label;
884
+ let account_name = getAccountNameByKeystoreSlug(keystore_path, keystore_slug);
885
+ console.log(chalk.green(`Found account name: [${account_name}]`));
886
886
 
887
- account_address = account_label_info.account_address;
888
- if (account_label === null) {
887
+ account_address = keystore_slug_info.account_address;
888
+ if (keystore_slug === null) {
889
889
  console.log(chalk.red("Account not found"));
890
890
  await showTools(keystore_path, wative_core);
891
891
  return;
892
892
  }
893
- let login_result = await loginIn(account_label, wative_core);
893
+ let login_result = await loginIn(keystore_path, keystore_slug, wative_core);
894
894
  if (!login_result.isLoginIn) {
895
895
  await showTools(keystore_path, wative_core);
896
896
  return;
897
897
  }
898
- await selectToolsOptions(keystore_path, account_label, account_address, wative_core);
898
+ await selectToolsOptions(keystore_path, keystore_slug, account_address, wative_core);
899
899
  await showTools(keystore_path, wative_core);
900
900
  }
package/src/utils.ts CHANGED
@@ -332,52 +332,50 @@ export const getColor = async (text: string) => {
332
332
  return null;
333
333
  }
334
334
 
335
- export const un_format_account_label = (keystore_path: string, account_label: string) => {
335
+ export const getAccountNameByKeystoreSlug = (keystore_path: string, keystore_slug: string) => {
336
336
  const networks = getNetworkInfo(keystore_path);
337
-
338
- const account_label_list = networks.accounts;
339
- const formatted_account_label_list = batch_format_account_label(account_label_list);
340
-
341
- const index = formatted_account_label_list.indexOf(account_label);
337
+ const account_name_list = networks.accounts;
338
+ const keystore_slug_list = batchGetKeystoreSlugByAccountName(account_name_list);
339
+ const index = keystore_slug_list.indexOf(keystore_slug);
342
340
  if (index !== -1) {
343
- return account_label_list[index];
341
+ return account_name_list[index];
344
342
  }
345
- return account_label;
343
+ return keystore_slug;
346
344
  }
347
345
 
348
- export const format_account_label = (account_label: string) => {
349
- account_label = account_label.trim();
350
- account_label = account_label.toLocaleLowerCase();
351
- account_label = account_label.replace(/\s+/g, "-").trim();
352
- return account_label;
346
+ export const getKeystoreSlugByAccountName = (account_name: string) => {
347
+ account_name = account_name.trim();
348
+ account_name = account_name.toLocaleLowerCase();
349
+ account_name = account_name.replace(/\s+/g, "-").trim();
350
+ account_name = account_name.replace(/\-+/g, "-").trim();
351
+ return account_name;
353
352
  }
354
353
 
355
-
356
- export const batch_format_account_label = (account_label_list: string[]) => {
357
- let formatted_account_label_list: string[] = [];
358
- for (let i = 0; i < account_label_list.length; i++) {
359
- formatted_account_label_list.push(
360
- format_account_label(account_label_list[i])
354
+ export const batchGetKeystoreSlugByAccountName = (account_name_list: string[]) => {
355
+ let keystore_slug_list: string[] = [];
356
+ for (let i = 0; i < account_name_list.length; i++) {
357
+ keystore_slug_list.push(
358
+ getKeystoreSlugByAccountName(account_name_list[i])
361
359
  );
362
360
  }
363
- return formatted_account_label_list;
361
+ return keystore_slug_list;
364
362
  }
365
363
 
366
364
 
367
- export const getAccountLabel = async (text: string, account_label_list: string[]) => {
368
- let formatted_account_label_list = batch_format_account_label(account_label_list);
365
+ export const getAccountName = async (text: string, account_name_list: string[]) => {
366
+ let keystore_slug_list = batchGetKeystoreSlugByAccountName(account_name_list);
369
367
  let reg = /^(?![-_])[a-zA-Z0-9_-]{4,20}(?<![-_])$/g;
370
368
  for (let i = 0; i < 5; i++) {
371
- let account_label = await inputSomething(text);
372
- account_label = account_label.trim();
373
- let formatted_account_label = format_account_label(account_label);
369
+ let account_name = await inputSomething(text);
370
+ account_name = account_name.trim();
371
+ let keystore_slug = getKeystoreSlugByAccountName(account_name);
374
372
 
375
- if (reg.test(formatted_account_label)) {
376
- if (formatted_account_label_list.includes(formatted_account_label)) {
377
- console.log(chalk.red("Keystore name already exists"));
373
+ if (reg.test(keystore_slug)) {
374
+ if (keystore_slug_list.includes(keystore_slug)) {
375
+ console.log(chalk.red("Account name already exists"));
378
376
  continue;
379
377
  } else {
380
- return account_label;
378
+ return account_name;
381
379
  }
382
380
  }
383
381
  }
@@ -750,22 +748,22 @@ export const updateStorage = (keystore_path: string) => {
750
748
 
751
749
  let account_list_len = networks.accounts.length;
752
750
  for (let i = 0; i < account_list_len; i++) {
753
- let account_label = networks.accounts[account_list_len - 1 - i];
754
- let formatted_account_label = format_account_label(account_label);
755
- let account_label_path = path.resolve(keystore_path, `accounts/${formatted_account_label}.json`);
751
+ let account_name = networks.accounts[account_list_len - 1 - i];
752
+ let keystore_slug = getKeystoreSlugByAccountName(account_name);
753
+ let keystore_slug_path = path.resolve(keystore_path, `accounts/${keystore_slug}.json`);
756
754
 
757
- if (!fs.existsSync(account_label_path)) {
755
+ if (!fs.existsSync(keystore_slug_path)) {
758
756
  networks.accounts.splice(account_list_len - 1 - i, 1);
759
757
  }
760
758
  }
761
759
 
762
760
  fs.writeFileSync(network_path, JSON.stringify(networks, null, 4));
763
- let account_label_list = networks.accounts;
764
- account_label_list = batch_format_account_label(account_label_list);
761
+ let account_name_list = networks.accounts;
762
+ let keystore_slug_list = batchGetKeystoreSlugByAccountName(account_name_list);
765
763
 
766
- for (let i = 0; i < account_label_list.length; i++) {
767
- let account_label_path = path.resolve(keystore_path, `accounts/${account_label_list[i]}.json`);
768
- let account_info = JSON.parse(fs.readFileSync(account_label_path, 'utf8'));
764
+ for (let i = 0; i < keystore_slug_list.length; i++) {
765
+ let keystore_slug_path = path.resolve(keystore_path, `accounts/${keystore_slug_list[i]}.json`);
766
+ let account_info = JSON.parse(fs.readFileSync(keystore_slug_path, 'utf8'));
769
767
  if (account_info.account_type === "PP") {
770
768
  continue;
771
769
  }
@@ -778,6 +776,6 @@ export const updateStorage = (keystore_path: string) => {
778
776
  }
779
777
  ];
780
778
  delete account_info.ciphertexts;
781
- fs.writeFileSync(account_label_path, JSON.stringify(account_info, null, 4));
779
+ fs.writeFileSync(keystore_slug_path, JSON.stringify(account_info, null, 4));
782
780
  }
783
781
  }