wative 1.0.31 → 1.0.33

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/tools.ts CHANGED
@@ -28,6 +28,7 @@ const confirmEvmRawTransaction = async (tx_params: any): Promise<any> => {
28
28
  `gas: ${tx_params.gas}`,
29
29
  new inquirer.Separator("——————————————-"),
30
30
  "Send it now",
31
+ "Back",
31
32
  ];
32
33
 
33
34
  let selected_send_evm_raw_transaction = await selectSomething(option_send_evm_raw_transaction_list);
@@ -59,6 +60,10 @@ const confirmEvmRawTransaction = async (tx_params: any): Promise<any> => {
59
60
  return tx_params;
60
61
  }
61
62
 
63
+ if (option_id === 10) {
64
+ return null;
65
+ }
66
+
62
67
  return await confirmEvmRawTransaction(tx_params);
63
68
  }
64
69
 
@@ -138,6 +143,10 @@ const sendEvmRawTransaction = async (chain_id: string, chain_rpc_url: string, ch
138
143
  txParams.gasPrice = sendGasPrice;
139
144
  }
140
145
  txParams = await confirmEvmRawTransaction(txParams);
146
+ if (!txParams) {
147
+ return;
148
+ }
149
+
141
150
  const signed_message_result = await wative_core.account.signTransaction(
142
151
  account_address,
143
152
  txParams,
@@ -325,9 +334,10 @@ const sendEvmTokenTransaction = async (keystore_path: string, chain_rpc_url: str
325
334
 
326
335
  let token_address: any;
327
336
  let token_decimals: any;
337
+ let token_name: any;
328
338
  switch (selected_token_address) {
329
339
  case '> Input token ticker':
330
- let token_name = await inputSomething("token ticker");
340
+ token_name = await inputSomething("token ticker");
331
341
 
332
342
  let token_address_list = await getAssetListByTokenName(keystore_path, chain_id, token_name);
333
343
  if (token_address_list.length === 0) {
@@ -372,6 +382,7 @@ const sendEvmTokenTransaction = async (keystore_path: string, chain_rpc_url: str
372
382
  return;
373
383
  }
374
384
  token_decimals = Number(token_info.output.decimals);
385
+ token_name = token_info.output.name;
375
386
  break;
376
387
  }
377
388
 
@@ -381,19 +392,6 @@ const sendEvmTokenTransaction = async (keystore_path: string, chain_rpc_url: str
381
392
  console.log(chalk.red(token_balance_result.output));
382
393
  return;
383
394
  }
384
- let amount: any;
385
- for (let i = 0; i < 5; i++) {
386
- let input_amount = await inputSomething("Amount", numberValidator);
387
- if ((new BigNumber(input_amount).multipliedBy(Math.pow(10, Number(token_decimals)))).isLessThanOrEqualTo(new BigNumber(token_balance_result.output))) {
388
- amount = input_amount;
389
- break;
390
- }
391
- console.log(chalk.red("Not enough balance"));
392
- }
393
-
394
- if (!amount) {
395
- return;
396
- }
397
395
 
398
396
  const gasUtil = new GasUtil(chain_rpc_url);
399
397
  const estimateGasPrice = await gasUtil.getGasPrice();
@@ -402,8 +400,12 @@ const sendEvmTokenTransaction = async (keystore_path: string, chain_rpc_url: str
402
400
  const inputGasPrice = await inputSomething(`Gas price (${_estimateGasPrice}), agree or enter`, gasValidator);
403
401
  let gasPrice = inputGasPrice ? inputGasPrice : _estimateGasPrice;
404
402
  gasPrice = (new BigNumber(gasPrice)).multipliedBy(1e9).toFixed(0);
403
+ let transfer_amount = await getTransferTokenAmount(
404
+ token_balance_result.output,
405
+ token_name,
406
+ token_decimals
407
+ );
405
408
 
406
- let transfer_amount = new BigNumber(amount).multipliedBy(Math.pow(10, token_decimals)).toFixed(0);
407
409
  const data = await getTransferTokenData(receipt, transfer_amount, chain_rpc_url);
408
410
 
409
411
  const estimateNonce = await gasUtil.getTransactionCount(account_address);
@@ -436,6 +438,10 @@ const sendEvmTokenTransaction = async (keystore_path: string, chain_rpc_url: str
436
438
  }
437
439
 
438
440
  txParams = await confirmEvmRawTransaction(txParams);
441
+ if (!txParams) {
442
+ return;
443
+ }
444
+
439
445
  const signed_message_result = await wative_core.account.signTransaction(
440
446
  account_address,
441
447
  txParams,
@@ -472,9 +478,10 @@ const sendSolanaTokenTransaction = async (keystore_path: string, chain_rpc_url:
472
478
 
473
479
  let token_address: any;
474
480
  let token_decimals: any;
481
+ let token_name: any;
475
482
  switch (selected_token_address) {
476
483
  case '> Input token ticker':
477
- let token_name = await inputSomething("token ticker");
484
+ token_name = await inputSomething("token ticker");
478
485
 
479
486
  let token_address_list = await getAssetListByTokenName(keystore_path, chain_id, token_name);
480
487
  if (token_address_list.length === 0) {
@@ -519,30 +526,36 @@ const sendSolanaTokenTransaction = async (keystore_path: string, chain_rpc_url:
519
526
  return;
520
527
  }
521
528
  token_decimals = Number(token_info.output.decimals);
529
+ token_name = token_info.output.name;
522
530
  break;
523
531
  }
524
532
 
525
533
  const receipt = await inputSomething("Receipt", chainAddressValidator);
526
- const token_balance_result = await getTokenBalanceInEvm(account_address, token_address, chain_rpc_url);
534
+ const token_balance_result = await getTokenBalanceInSolana(account_address, token_address, chain_rpc_url);
527
535
  if (!token_balance_result.status) {
528
536
  console.log(chalk.red(token_balance_result.output));
529
537
  return;
530
538
  }
531
- let amount: any;
532
- for (let i = 0; i < 5; i++) {
533
- let input_amount = await inputSomething("Amount", numberValidator);
534
- if ((new BigNumber(input_amount).multipliedBy(Math.pow(10, Number(token_decimals)))).isLessThanOrEqualTo(new BigNumber(token_balance_result.output))) {
535
- amount = input_amount;
536
- break;
537
- }
538
- console.log(chalk.red("Not enough balance"));
539
- }
540
-
541
- if (!amount) {
542
- return;
543
- }
544
539
 
545
- let transfer_amount = new BigNumber(amount).multipliedBy(Math.pow(10, token_decimals)).toFixed(0);
540
+ // let amount: any;
541
+ // for (let i = 0; i < 5; i++) {
542
+ // let input_amount = await inputSomething("Amount", numberValidator);
543
+ // if ((new BigNumber(input_amount).multipliedBy(Math.pow(10, Number(token_decimals)))).isLessThanOrEqualTo(new BigNumber(token_balance_result.output))) {
544
+ // amount = input_amount;
545
+ // break;
546
+ // }
547
+ // console.log(chalk.red("Not enough balance"));
548
+ // }
549
+
550
+ // if (!amount) {
551
+ // return;
552
+ // }
553
+
554
+ let transfer_amount = await getTransferTokenAmount(
555
+ token_balance_result.output,
556
+ token_name,
557
+ token_decimals
558
+ );
546
559
  let from_token_account = getAssociatedTokenAddressSync(
547
560
  new PublicKey(token_address),
548
561
  new PublicKey(account_address),
@@ -696,6 +709,31 @@ const sendSolanaTokenTransaction = async (keystore_path: string, chain_rpc_url:
696
709
  }
697
710
 
698
711
 
712
+ const getTransferTokenAmount = async (max_value: string, token_symbols: string, decimals: number): Promise<string> => {
713
+ let total_balance = (new BigNumber(max_value)).dividedBy(10 ** decimals).toFixed(4, BigNumber.ROUND_FLOOR);
714
+
715
+ let option_select_value_list: any = [
716
+ '> Input value',
717
+ `> Total Balance (${total_balance} ${token_symbols})`
718
+ ]
719
+ let selected_value = await selectSomething(option_select_value_list);
720
+ let value_id = option_select_value_list.indexOf(selected_value);
721
+ let value = "0";
722
+ if (value_id === 0) {
723
+ let input_value = await inputSomething("value", numberValidator);
724
+ value = new BigNumber(input_value).multipliedBy(10 ** decimals).toFixed(0, BigNumber.ROUND_FLOOR);
725
+ } else if (value_id === 1) {
726
+ value = max_value;
727
+ }
728
+
729
+ if ((new BigNumber(value)).isLessThanOrEqualTo(new BigNumber(max_value))) {
730
+ return value;
731
+ }
732
+
733
+ console.log(chalk.red("Not enough balance"));
734
+ return getTransferTokenAmount(max_value, token_symbols, decimals);
735
+ }
736
+
699
737
  const excuteTools = async (keystore_path: string, account_label: string, account_address: string, wative_core: typeof WativeCore) => {
700
738
  let default_network = getDefaultNetworkByAddress(keystore_path, account_label, account_address);
701
739
  let network_type = getNetworkTypeByName(keystore_path, default_network);
package/src/utils.ts CHANGED
@@ -317,7 +317,7 @@ export const getSymbol = async (text: string) => {
317
317
  }
318
318
 
319
319
  export const getColor = async (text: string) => {
320
- let reg = /^#[0-9A_F]{6}$/g;
320
+ let reg = /^#[0-9A-Fa-f]{6}$/g;
321
321
  for (let i = 0; i < 5; i++) {
322
322
  let color = await inputSomething(text);
323
323
  if (color === "") {
@@ -332,7 +332,7 @@ export const getColor = async (text: string) => {
332
332
  }
333
333
 
334
334
  export const getAccountLabel = async (text: string, account_label_list: string[]) => {
335
- let reg = /^(?![-_]).*?[a-zA-Z0-9_-]{4,20}(?<![-_])$/g;
335
+ let reg = /^(?![-_])[a-zA-Z0-9_-]{4,20}(?<![-_])$/g;
336
336
  for (let i = 0; i < 5; i++) {
337
337
  let account_label = await inputSomething(text);
338
338
  account_label = account_label.trim();