wative 1.0.36 → 1.0.38
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 +5 -5
- package/src/account.ts +10 -4
- package/src/tools.ts +14 -3
- package/src/utils.ts +14 -0
package/src/account.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
inputPasswordWithoutValidator,
|
|
20
20
|
getKeystoreSlugByAccountName,
|
|
21
21
|
getAccountNameByKeystoreSlug,
|
|
22
|
+
inputMaskedPassword,
|
|
22
23
|
} from "./utils";
|
|
23
24
|
import { getAccountAddress, getAccountBalance, getNetworkInfoByName, getNetworkTypeByName, getStatus, selectDefaultNetwork, showAllAccounts, switchNetworkByAccountName } from "./network";
|
|
24
25
|
import { getAssetList, showAssetsDetail } from './assets';
|
|
@@ -70,7 +71,7 @@ const importPassphrase = async (keystore_path: string, wative_core: typeof Wativ
|
|
|
70
71
|
return;
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
let passphrase = await
|
|
74
|
+
let passphrase = await inputMaskedPassword('Please enter a mnemonic [split by space]', passphraseValidator);
|
|
74
75
|
passphrase = passphrase.replace(/\s+/g, " ");
|
|
75
76
|
|
|
76
77
|
let keystore_slug = getKeystoreSlugByAccountName(pre_account_info.account_name);
|
|
@@ -99,7 +100,7 @@ const createPrivateKeyAccount = async (keystore_path: string, wative_core: typeo
|
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
let private_key = await
|
|
103
|
+
let private_key = await inputMaskedPassword('Please enter a private key');
|
|
103
104
|
let keystore_slug = getKeystoreSlugByAccountName(pre_account_info.account_name);
|
|
104
105
|
await _importAccount(
|
|
105
106
|
keystore_path,
|
|
@@ -248,9 +249,11 @@ export const loginIn = async (keystore_path: string, keystore_slug: string, wati
|
|
|
248
249
|
|
|
249
250
|
for (let i = 0; i < 3; i++) {
|
|
250
251
|
let account_name = getAccountNameByKeystoreSlug(keystore_path, keystore_slug);
|
|
251
|
-
|
|
252
|
+
let password_name = 'WATIVE_PASSWD_' + keystore_slug;
|
|
252
253
|
let password: any;
|
|
253
|
-
if (process.env
|
|
254
|
+
if (process.env[password_name] && process.env[password_name] !== '') {
|
|
255
|
+
password = process.env[password_name];
|
|
256
|
+
} else if (process.env.WativePassword && process.env.WativePassword !== '') {
|
|
254
257
|
password = process.env.WativePassword;
|
|
255
258
|
} else {
|
|
256
259
|
password = await inputPasswordWithoutValidator(`Please input the password for Account [${account_name}]`);
|
|
@@ -317,6 +320,9 @@ const selectAccount = async (keystore_path: string, wative_core: typeof WativeCo
|
|
|
317
320
|
const selected_account_name = account_name_list[select_account_options.indexOf(selected_account) - 2];
|
|
318
321
|
const keystore_slug = getKeystoreSlugByAccountName(selected_account_name);
|
|
319
322
|
|
|
323
|
+
console.log(
|
|
324
|
+
chalk.green(`Keystore slug: [${keystore_slug}]`)
|
|
325
|
+
);
|
|
320
326
|
let login_result = await loginIn(keystore_path, keystore_slug, wative_core);
|
|
321
327
|
if (login_result.isLoginIn) {
|
|
322
328
|
await accountManager(keystore_path, keystore_slug, wative_core, login_result.password);
|
package/src/tools.ts
CHANGED
|
@@ -83,6 +83,13 @@ const sendEvmRawTransaction = async (chain_id: string, chain_rpc_url: string, ch
|
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
let transfer_gas_limit: string;
|
|
87
|
+
if (chain_id === "42161" || chain_id === "421614") {
|
|
88
|
+
transfer_gas_limit = "1700000";
|
|
89
|
+
} else {
|
|
90
|
+
transfer_gas_limit = "21000";
|
|
91
|
+
}
|
|
92
|
+
|
|
86
93
|
let data: string;
|
|
87
94
|
let value: any;
|
|
88
95
|
if (code_result.output === "0x") {
|
|
@@ -95,7 +102,7 @@ const sendEvmRawTransaction = async (chain_id: string, chain_rpc_url: string, ch
|
|
|
95
102
|
}
|
|
96
103
|
let account_balance = new BigNumber(account_balance_result.output);
|
|
97
104
|
let tx_gas_price = new BigNumber(gasPrice);
|
|
98
|
-
let max_value = account_balance.minus(tx_gas_price.multipliedBy(
|
|
105
|
+
let max_value = account_balance.minus(tx_gas_price.multipliedBy(Number(transfer_gas_limit))).toFixed(0, BigNumber.ROUND_FLOOR);
|
|
99
106
|
let total_balance = (new BigNumber(max_value)).dividedBy(1e18).toFixed(4, BigNumber.ROUND_FLOOR);
|
|
100
107
|
|
|
101
108
|
if (new BigNumber(total_balance) < new BigNumber(0)) {
|
|
@@ -127,7 +134,7 @@ const sendEvmRawTransaction = async (chain_id: string, chain_rpc_url: string, ch
|
|
|
127
134
|
};
|
|
128
135
|
|
|
129
136
|
if (data === '0x') {
|
|
130
|
-
txParams['gas'] =
|
|
137
|
+
txParams['gas'] = transfer_gas_limit;
|
|
131
138
|
} else {
|
|
132
139
|
let sendGasPrice = txParams.gasPrice;
|
|
133
140
|
delete txParams.gasPrice;
|
|
@@ -421,7 +428,11 @@ const sendEvmTokenTransaction = async (keystore_path: string, chain_rpc_url: str
|
|
|
421
428
|
};
|
|
422
429
|
|
|
423
430
|
if (data === '0x') {
|
|
424
|
-
|
|
431
|
+
if (chain_id === "42161" || chain_id === "421614") {
|
|
432
|
+
txParams['gas'] = "1700000";
|
|
433
|
+
} else {
|
|
434
|
+
txParams['gas'] = "21000";
|
|
435
|
+
}
|
|
425
436
|
} else {
|
|
426
437
|
let sendGasPrice = txParams.gasPrice;
|
|
427
438
|
delete txParams.gasPrice;
|
package/src/utils.ts
CHANGED
|
@@ -428,6 +428,20 @@ const passwordValidator = function (value: string) {
|
|
|
428
428
|
}
|
|
429
429
|
};
|
|
430
430
|
|
|
431
|
+
export const inputMaskedPassword = async (text: string, validate_func?: Function) => {
|
|
432
|
+
const questions = [
|
|
433
|
+
{
|
|
434
|
+
name: 'inputText',
|
|
435
|
+
type: 'password',
|
|
436
|
+
mask: '#',
|
|
437
|
+
message: `${text}:`,
|
|
438
|
+
validate: validate_func
|
|
439
|
+
},
|
|
440
|
+
]
|
|
441
|
+
const { inputText } = await inquirer.prompt(questions)
|
|
442
|
+
return inputText.trim().toString()
|
|
443
|
+
}
|
|
444
|
+
|
|
431
445
|
export const inputPasswordWithoutValidator = async (text: string) => {
|
|
432
446
|
const questions = [
|
|
433
447
|
{
|