wative 1.0.9 → 1.0.11
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 +8 -3
- package/src/account.ts +255 -213
- package/src/assets.ts +163 -16
- package/src/home_page.ts +2 -2
- package/src/index.ts +2 -1
- package/src/network.ts +207 -17
- package/src/tools.ts +39 -10
- package/src/utils.ts +235 -5
- package/src/web3.ts +102 -2
- package/rollup.config.js +0 -30
package/src/assets.ts
CHANGED
|
@@ -2,10 +2,10 @@ const chalk = require('chalk');
|
|
|
2
2
|
import * as path from "path";
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import { BigNumber } from 'bignumber.js';
|
|
5
|
-
import { isEvmAddress, isSolanaAddress } from "./chain";
|
|
5
|
+
import { getChainType, isEvmAddress, isSolanaAddress } from "./chain";
|
|
6
6
|
import { getNetworkInfoByName, getNetworkTypeByName } from "./network";
|
|
7
|
-
import { chainAddressValidator, checkFileExistence, inputSomething, selectSomething } from "./utils";
|
|
8
|
-
import { getTokenBalanceInEvm, getTokenBalanceInSolana, getTokenInfoInEvm, getTokenInfoInSolana } from './web3';
|
|
7
|
+
import { chainAddressValidator, checkFileExistence, inputSomething, numberValidator, selectSomething } from "./utils";
|
|
8
|
+
import { deleteTokenBalance, getTokenBalance, getTokenBalanceInEvm, getTokenBalanceInSolana, getTokenInfoInEvm, getTokenInfoInSolana, updateBalance } from './web3';
|
|
9
9
|
import inquirer from "inquirer";
|
|
10
10
|
|
|
11
11
|
|
|
@@ -48,8 +48,8 @@ export const showAssetsDetail = async (
|
|
|
48
48
|
default_network: string,
|
|
49
49
|
account_address: string
|
|
50
50
|
) => {
|
|
51
|
-
const network_type = getNetworkTypeByName(keystore_path, default_network);
|
|
52
51
|
const network_info = getNetworkInfoByName(keystore_path, default_network);
|
|
52
|
+
const network_type = getChainType(network_info.chainId);
|
|
53
53
|
const asset_list = await getAssetList(keystore_path, network_info.chainId.toString());
|
|
54
54
|
if (!asset_list) {
|
|
55
55
|
console.log(chalk.red("No asset found"));
|
|
@@ -60,7 +60,8 @@ export const showAssetsDetail = async (
|
|
|
60
60
|
account_address,
|
|
61
61
|
asset_list,
|
|
62
62
|
network_info.rpcUrl,
|
|
63
|
-
network_type
|
|
63
|
+
network_type,
|
|
64
|
+
network_info.chainId
|
|
64
65
|
);
|
|
65
66
|
|
|
66
67
|
let asset_id = 1;
|
|
@@ -87,7 +88,8 @@ export const saveAsset = async (
|
|
|
87
88
|
asset_address: string,
|
|
88
89
|
symbol: string,
|
|
89
90
|
name: string,
|
|
90
|
-
decimals: number
|
|
91
|
+
decimals: number,
|
|
92
|
+
display_decimals: number
|
|
91
93
|
) => {
|
|
92
94
|
let json_data_path = path.join(keystore_path, `assets.json`);
|
|
93
95
|
let assets_mapping: any = {};
|
|
@@ -98,23 +100,103 @@ export const saveAsset = async (
|
|
|
98
100
|
if (assets_mapping[chain_id] === undefined) {
|
|
99
101
|
assets_mapping[chain_id] = [];
|
|
100
102
|
}
|
|
103
|
+
|
|
104
|
+
for (let i = 0; i < assets_mapping[chain_id].length; i++) {
|
|
105
|
+
if (assets_mapping[chain_id][i].address === asset_address) {
|
|
106
|
+
assets_mapping[chain_id][i] = {
|
|
107
|
+
address: asset_address,
|
|
108
|
+
symbol,
|
|
109
|
+
name,
|
|
110
|
+
decimals,
|
|
111
|
+
display_decimals
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
fs.writeFileSync(json_data_path, JSON.stringify(assets_mapping, null, 4));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
101
119
|
assets_mapping[chain_id].push({
|
|
102
120
|
address: asset_address,
|
|
103
121
|
symbol,
|
|
104
122
|
name,
|
|
105
|
-
decimals
|
|
123
|
+
decimals,
|
|
124
|
+
display_decimals
|
|
106
125
|
});
|
|
107
126
|
fs.writeFileSync(json_data_path, JSON.stringify(assets_mapping, null, 4));
|
|
108
127
|
}
|
|
109
128
|
|
|
129
|
+
export const addToken = async (
|
|
130
|
+
keystore_path: string,
|
|
131
|
+
) => {
|
|
132
|
+
const network_path = path.resolve(keystore_path, 'network.json');
|
|
133
|
+
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
134
|
+
|
|
135
|
+
let options: any = [];
|
|
136
|
+
let network_list = networks.networks;
|
|
137
|
+
for (let i = 0; i < network_list.length; i++) {
|
|
138
|
+
options.push(`${i + 1}. ${network_list[i].name}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
let selected_option = await selectSomething(options);
|
|
142
|
+
let network_name = selected_option.split(".")[1].trim();
|
|
143
|
+
const network_type = getNetworkTypeByName(keystore_path, network_name);
|
|
144
|
+
const network_info = getNetworkInfoByName(keystore_path, network_name);
|
|
145
|
+
|
|
146
|
+
const token_address = await inputSomething("Enter contract address", chainAddressValidator);
|
|
147
|
+
|
|
148
|
+
let token_info_result: any;
|
|
149
|
+
if (network_type === "evm") {
|
|
150
|
+
if (!isEvmAddress(token_address)) {
|
|
151
|
+
console.log(chalk.red("evm address format error"));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
token_info_result = await getTokenInfoInEvm(token_address, network_info.rpcUrl);
|
|
155
|
+
} else {
|
|
156
|
+
if (!isSolanaAddress(token_address)) {
|
|
157
|
+
console.log(chalk.red("solana address format error"));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
token_info_result = await getTokenInfoInSolana(token_address, network_info.rpcUrl);
|
|
161
|
+
}
|
|
162
|
+
if (!token_info_result.status) {
|
|
163
|
+
console.log(chalk.red(token_info_result.output));
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (!token_info_result.output.name) {
|
|
168
|
+
token_info_result.output.name = await inputSomething("Please input token name");
|
|
169
|
+
}
|
|
170
|
+
if (!token_info_result.output.symbol) {
|
|
171
|
+
token_info_result.output.symbol = await inputSomething("Please input token symbol");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
console.log(
|
|
175
|
+
chalk.green(`Token ${token_info_result.output.name} loaded successfully.`)
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
let display_decimals = await inputSomething("Enter decimals for display", numberValidator);
|
|
179
|
+
display_decimals = parseInt(display_decimals);
|
|
180
|
+
await saveAsset(
|
|
181
|
+
keystore_path,
|
|
182
|
+
network_info.chainId.toString(),
|
|
183
|
+
token_address,
|
|
184
|
+
token_info_result.output.symbol,
|
|
185
|
+
token_info_result.output.name,
|
|
186
|
+
token_info_result.output.decimals,
|
|
187
|
+
display_decimals
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
110
191
|
export const addAsset = async (
|
|
111
192
|
keystore_path: string,
|
|
112
193
|
default_network: string
|
|
113
194
|
) => {
|
|
114
|
-
const token_address = await inputSomething("Please input Token address", chainAddressValidator);
|
|
115
195
|
const network_type = getNetworkTypeByName(keystore_path, default_network);
|
|
116
196
|
const network_info = getNetworkInfoByName(keystore_path, default_network);
|
|
117
197
|
|
|
198
|
+
const token_address = await inputSomething("Enter contract address", chainAddressValidator);
|
|
199
|
+
|
|
118
200
|
let token_info_result: any;
|
|
119
201
|
if (network_type === "evm") {
|
|
120
202
|
if (!isEvmAddress(token_address)) {
|
|
@@ -133,22 +215,28 @@ export const addAsset = async (
|
|
|
133
215
|
console.log(chalk.red(token_info_result.output));
|
|
134
216
|
return;
|
|
135
217
|
}
|
|
218
|
+
|
|
136
219
|
if (!token_info_result.output.name) {
|
|
137
220
|
token_info_result.output.name = await inputSomething("Please input token name");
|
|
138
221
|
}
|
|
139
222
|
if (!token_info_result.output.symbol) {
|
|
140
223
|
token_info_result.output.symbol = await inputSomething("Please input token symbol");
|
|
141
224
|
}
|
|
225
|
+
|
|
226
|
+
console.log(
|
|
227
|
+
chalk.green(`Token ${token_info_result.output.name} loaded successfully.`)
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
let display_decimals = await inputSomething("Enter decimals for display", numberValidator);
|
|
231
|
+
display_decimals = parseInt(display_decimals);
|
|
142
232
|
await saveAsset(
|
|
143
233
|
keystore_path,
|
|
144
234
|
network_info.chainId.toString(),
|
|
145
235
|
token_address,
|
|
146
236
|
token_info_result.output.symbol,
|
|
147
237
|
token_info_result.output.name,
|
|
148
|
-
token_info_result.output.decimals
|
|
149
|
-
|
|
150
|
-
console.log(
|
|
151
|
-
chalk.green("Asset added successfully")
|
|
238
|
+
token_info_result.output.decimals,
|
|
239
|
+
display_decimals
|
|
152
240
|
);
|
|
153
241
|
}
|
|
154
242
|
|
|
@@ -158,10 +246,10 @@ export const showAssets = async (
|
|
|
158
246
|
default_network: string
|
|
159
247
|
) => {
|
|
160
248
|
const options_assets_list = [
|
|
161
|
-
'> Back',
|
|
162
|
-
new inquirer.Separator('----------------------------------'),
|
|
163
249
|
'> Show Assets',
|
|
164
|
-
'> Add Asset'
|
|
250
|
+
'> Add Asset',
|
|
251
|
+
new inquirer.Separator('----------------------------------'),
|
|
252
|
+
'> Back'
|
|
165
253
|
];
|
|
166
254
|
|
|
167
255
|
const selected_option = await selectSomething(options_assets_list);
|
|
@@ -186,7 +274,8 @@ export const batchGetTokenBalance = async (
|
|
|
186
274
|
account_address: string,
|
|
187
275
|
asset_info_list: any,
|
|
188
276
|
rpc_url: string,
|
|
189
|
-
chain_type: string
|
|
277
|
+
chain_type: string,
|
|
278
|
+
chain_id: string
|
|
190
279
|
) => {
|
|
191
280
|
let asset_list_len = asset_info_list.length;
|
|
192
281
|
let promise_list: any = [];
|
|
@@ -218,6 +307,64 @@ export const batchGetTokenBalance = async (
|
|
|
218
307
|
symbol: asset_info.symbol,
|
|
219
308
|
balance: asset_balance
|
|
220
309
|
});
|
|
310
|
+
deleteTokenBalance(
|
|
311
|
+
chain_id,
|
|
312
|
+
account_address,
|
|
313
|
+
asset_info.address
|
|
314
|
+
);
|
|
221
315
|
}
|
|
316
|
+
|
|
317
|
+
deleteTokenBalance(
|
|
318
|
+
chain_id,
|
|
319
|
+
account_address,
|
|
320
|
+
"0"
|
|
321
|
+
)
|
|
222
322
|
return asset_balance_info_list;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export const getBatchAccountBalance = async (
|
|
326
|
+
keystore_path: string,
|
|
327
|
+
account_address_list: string[],
|
|
328
|
+
asset_info_list: any,
|
|
329
|
+
rpc_url: string,
|
|
330
|
+
network_name: string,
|
|
331
|
+
show_gas_token: boolean,
|
|
332
|
+
show_extended_token: boolean,
|
|
333
|
+
) => {
|
|
334
|
+
let asset_info_list_len = asset_info_list.length;
|
|
335
|
+
|
|
336
|
+
let network_info = getNetworkInfoByName(keystore_path, network_name);
|
|
337
|
+
let chain_type = getChainType(network_info.chainId.toString());
|
|
338
|
+
let is_evm = chain_type === "evm";
|
|
339
|
+
if (show_gas_token) {
|
|
340
|
+
await updateBalance(
|
|
341
|
+
account_address_list,
|
|
342
|
+
"0",
|
|
343
|
+
network_info.chainId.toString(),
|
|
344
|
+
rpc_url,
|
|
345
|
+
is_evm
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (show_extended_token) {
|
|
350
|
+
for (let i = 0; i < asset_info_list_len; i++) {
|
|
351
|
+
let asset_info = asset_info_list[i];
|
|
352
|
+
let token_address = asset_info.address;
|
|
353
|
+
await updateBalance(
|
|
354
|
+
account_address_list,
|
|
355
|
+
token_address,
|
|
356
|
+
network_info.chainId.toString(),
|
|
357
|
+
rpc_url,
|
|
358
|
+
is_evm
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
let batchAccountBalanceOf: any = getTokenBalance(
|
|
363
|
+
network_info.chainId.toString(),
|
|
364
|
+
account_address_list,
|
|
365
|
+
asset_info_list,
|
|
366
|
+
network_info
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
return batchAccountBalanceOf;
|
|
223
370
|
}
|
package/src/home_page.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { selectSomething } from "./utils";
|
|
2
|
+
import { showNetwork } from "./network";
|
|
3
3
|
import { accountSetting } from "./account";
|
|
4
4
|
import { showTools } from "./tools";
|
|
5
5
|
const { WativeCore } = require("wative-core");
|
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 } from "./utils";
|
|
3
|
+
import { showIntroduction, getKeystorePath, updateStorage } from "./utils";
|
|
4
4
|
import { createNetwork } from "./network";
|
|
5
5
|
import { showHomePage } from "./home_page";
|
|
6
6
|
|
|
@@ -16,6 +16,7 @@ const main = async () => {
|
|
|
16
16
|
|
|
17
17
|
const keystore_path = await getKeystorePath();
|
|
18
18
|
await createNetwork(keystore_path);
|
|
19
|
+
updateStorage(keystore_path);
|
|
19
20
|
|
|
20
21
|
const network_path = path.resolve(keystore_path, 'network.json');
|
|
21
22
|
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
package/src/network.ts
CHANGED
|
@@ -13,14 +13,16 @@ import {
|
|
|
13
13
|
getSymbol,
|
|
14
14
|
getColor,
|
|
15
15
|
Result,
|
|
16
|
-
getAccountChainType
|
|
16
|
+
getAccountChainType,
|
|
17
|
+
formatAddr
|
|
17
18
|
} from "./utils";
|
|
18
19
|
import {
|
|
19
20
|
getAccountInfo,
|
|
20
21
|
saveAccountInfo
|
|
21
22
|
} from "./account";
|
|
22
|
-
import { getAccountBalanceInEvm, getAccountBalanceInSolana } from "./web3";
|
|
23
|
+
import { deleteTokenBalance, getAccountBalanceInEvm, getAccountBalanceInSolana } from "./web3";
|
|
23
24
|
import { getChainType, getNativeTokenDecimals } from "./chain";
|
|
25
|
+
import { addToken } from "./assets";
|
|
24
26
|
|
|
25
27
|
export const createNetwork = async (keystore_path: string) => {
|
|
26
28
|
const network_path = path.resolve(keystore_path, 'network.json');
|
|
@@ -40,8 +42,6 @@ export const createNetwork = async (keystore_path: string) => {
|
|
|
40
42
|
|
|
41
43
|
export const selectOrEditNetwork = async (keystore_path: string, selected_network: any) => {
|
|
42
44
|
let options: any[] = [
|
|
43
|
-
'> Back',
|
|
44
|
-
new inquirer.Separator('----------------------------------'),
|
|
45
45
|
'> Edit'
|
|
46
46
|
];
|
|
47
47
|
|
|
@@ -49,6 +49,9 @@ export const selectOrEditNetwork = async (keystore_path: string, selected_networ
|
|
|
49
49
|
options.push('> Remove');
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
options.push(new inquirer.Separator('----------------------------------'));
|
|
53
|
+
options.push('> Back');
|
|
54
|
+
|
|
52
55
|
const selected_network_info = await selectSomething(options);
|
|
53
56
|
|
|
54
57
|
switch (selected_network_info) {
|
|
@@ -229,7 +232,11 @@ export const showAvailableNetworks = async (keystore_path: string) => {
|
|
|
229
232
|
}
|
|
230
233
|
}
|
|
231
234
|
|
|
232
|
-
let options: any = [
|
|
235
|
+
let options: any = [
|
|
236
|
+
'> Back',
|
|
237
|
+
'+ Add Network',
|
|
238
|
+
new inquirer.Separator(`----Networks(evm)----`)
|
|
239
|
+
];
|
|
233
240
|
|
|
234
241
|
for (let i = 0; i < evm_ids.length; i++) {
|
|
235
242
|
const evm_id = evm_ids[i];
|
|
@@ -261,35 +268,172 @@ export const showAvailableNetworks = async (keystore_path: string) => {
|
|
|
261
268
|
return;
|
|
262
269
|
}
|
|
263
270
|
|
|
271
|
+
if (selected_option === '+ Add Network') {
|
|
272
|
+
await addNetwork(keystore_path);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
|
|
264
277
|
let option_id = options.indexOf(selected_option);
|
|
265
278
|
let select_network: any;
|
|
266
|
-
if (option_id < evm_ids.length +
|
|
267
|
-
select_network = networks.networks[evm_ids[option_id -
|
|
279
|
+
if (option_id < evm_ids.length + 3) {
|
|
280
|
+
select_network = networks.networks[evm_ids[option_id - 3]];
|
|
268
281
|
} else {
|
|
269
|
-
select_network = networks.networks[solana_ids[option_id - evm_ids.length -
|
|
282
|
+
select_network = networks.networks[solana_ids[option_id - evm_ids.length - 4]];
|
|
270
283
|
}
|
|
271
284
|
|
|
272
285
|
await selectOrEditNetwork(keystore_path, select_network);
|
|
273
286
|
await showAvailableNetworks(keystore_path);
|
|
274
287
|
}
|
|
275
288
|
|
|
289
|
+
export const showDataview = async (keystore_path: string) => {
|
|
290
|
+
let options: any = [
|
|
291
|
+
'> Enhanced Balance Display',
|
|
292
|
+
new inquirer.Separator('----------------------------------'),
|
|
293
|
+
'> Back',
|
|
294
|
+
];
|
|
295
|
+
|
|
296
|
+
const selected_option = await selectSomething(options);
|
|
297
|
+
switch (selected_option) {
|
|
298
|
+
case '> Enhanced Balance Display': {
|
|
299
|
+
await enhancedBalanceDisplay(keystore_path);
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
case '> Back': {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
await showDataview(keystore_path);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export const updateStatus = async (keystore_path: string) => {
|
|
311
|
+
const network_path = path.resolve(keystore_path, 'network.json');
|
|
312
|
+
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
313
|
+
|
|
314
|
+
if (!("status" in networks)) {
|
|
315
|
+
networks.status = {
|
|
316
|
+
fullAddr: false,
|
|
317
|
+
gasToken: false,
|
|
318
|
+
extendedToken: false
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
let options = [
|
|
323
|
+
`> Show Full Address [${networks.status.fullAddr ? "ON" : "OFF"}]`,
|
|
324
|
+
`> Show Gas Token [${networks.status.gasToken ? "ON" : "OFF"}]`,
|
|
325
|
+
`> Show Extended Token[${networks.status.extendedToken ? "ON" : "OFF"}]`,
|
|
326
|
+
new inquirer.Separator('----------------------------------'),
|
|
327
|
+
'> Back',
|
|
328
|
+
];
|
|
329
|
+
|
|
330
|
+
const selected_option = await selectSomething(options);
|
|
331
|
+
|
|
332
|
+
if (selected_option === '> Back') {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (selected_option.includes('Full Address')) {
|
|
337
|
+
networks.status.fullAddr = await selectFlag();
|
|
338
|
+
} else if (selected_option.includes('Gas Token')) {
|
|
339
|
+
networks.status.gasToken = await selectFlag();
|
|
340
|
+
} else if (selected_option.includes('Extended Token')) {
|
|
341
|
+
networks.status.extendedToken = await selectFlag();
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
fs.writeFileSync(network_path, JSON.stringify(networks, null, 2));
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export const selectFlag = async () => {
|
|
348
|
+
let options = [
|
|
349
|
+
'> On',
|
|
350
|
+
'> Off'
|
|
351
|
+
];
|
|
352
|
+
|
|
353
|
+
const selected_option = await selectSomething(options);
|
|
354
|
+
switch (selected_option) {
|
|
355
|
+
case '> On': {
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
case '> Off': {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export const showTokenList = async (keystore_path: string) => {
|
|
365
|
+
const network_path = path.resolve(keystore_path, 'network.json');
|
|
366
|
+
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
367
|
+
|
|
368
|
+
let network_settings_map: any = {};
|
|
369
|
+
for (let network_info of networks.networks) {
|
|
370
|
+
network_settings_map[network_info.chainId.toString()] = network_info.name;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const assets_path = path.resolve(keystore_path, 'assets.json');
|
|
374
|
+
const assets = JSON.parse(fs.readFileSync(assets_path, 'utf8'));
|
|
375
|
+
|
|
376
|
+
for (let chain_id in assets) {
|
|
377
|
+
console.log(`----- Networks (${network_settings_map[chain_id]}) -------`);
|
|
378
|
+
|
|
379
|
+
let token_list_len = assets[chain_id].length;
|
|
380
|
+
for (let i = 0; i < token_list_len; i++) {
|
|
381
|
+
let token_info = assets[chain_id][i];
|
|
382
|
+
console.log(`${i + 1}.${token_info.symbol} CA: ${chalk.green(`${formatAddr(token_info.address)}`)
|
|
383
|
+
} Decimals: ${token_info.display_decimals ? token_info.display_decimals : "4"}`);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export const enhancedBalanceDisplay = async (keystore_path: string) => {
|
|
389
|
+
const options = [
|
|
390
|
+
'> Status',
|
|
391
|
+
'> Token List',
|
|
392
|
+
'> Add Token',
|
|
393
|
+
new inquirer.Separator('----------------------------------'),
|
|
394
|
+
'> Back',
|
|
395
|
+
];
|
|
396
|
+
|
|
397
|
+
const selected_option = await selectSomething(options);
|
|
398
|
+
|
|
399
|
+
switch (selected_option) {
|
|
400
|
+
case '> Status': {
|
|
401
|
+
await updateStatus(keystore_path);
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
case '> Token List': {
|
|
405
|
+
await showTokenList(keystore_path);
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
case '> Add Token': {
|
|
409
|
+
await addToken(keystore_path);
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
case '> Back': {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
await enhancedBalanceDisplay(keystore_path);
|
|
418
|
+
}
|
|
419
|
+
|
|
276
420
|
export const showNetwork = async (keystore_path: string) => {
|
|
277
421
|
let network_info_list = [
|
|
278
|
-
'>
|
|
422
|
+
'> Networks',
|
|
423
|
+
'> Dataview',
|
|
279
424
|
new inquirer.Separator('----------------------------------'),
|
|
280
|
-
'>
|
|
281
|
-
'> Add Network'
|
|
425
|
+
'> Back'
|
|
282
426
|
];
|
|
283
427
|
|
|
284
428
|
const selected_network_info = await selectSomething(network_info_list);
|
|
285
429
|
|
|
286
430
|
switch (selected_network_info) {
|
|
287
|
-
case '>
|
|
431
|
+
case '> Networks': {
|
|
288
432
|
await showAvailableNetworks(keystore_path);
|
|
289
433
|
break;
|
|
290
434
|
}
|
|
291
|
-
case '>
|
|
292
|
-
await
|
|
435
|
+
case '> Dataview': {
|
|
436
|
+
await showDataview(keystore_path);
|
|
293
437
|
break;
|
|
294
438
|
}
|
|
295
439
|
case '> Back': {
|
|
@@ -341,10 +485,11 @@ export const getNetworkInfoByName = (keystore_path: string, network_name: string
|
|
|
341
485
|
export const getAccountAddress = (keystore_path: string, account_label: string, account_id: number) => {
|
|
342
486
|
const account_info = getAccountInfo(keystore_path, account_label);
|
|
343
487
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
default_network = account_info.data[account_id].default_network;
|
|
488
|
+
if (account_info.account_type === "PK") {
|
|
489
|
+
return account_info.data[account_id].ciphertexts.address;
|
|
347
490
|
}
|
|
491
|
+
|
|
492
|
+
let default_network = account_info.default_network;
|
|
348
493
|
let network_type = getNetworkTypeByName(keystore_path, default_network);
|
|
349
494
|
|
|
350
495
|
if (network_type === "solana") {
|
|
@@ -422,6 +567,44 @@ export const switchPPNetwork = async (keystore_path: string, account_label: stri
|
|
|
422
567
|
);
|
|
423
568
|
}
|
|
424
569
|
|
|
570
|
+
export const showAllAccounts = async (keystore_path: string, account_label: string, account_index: number) => {
|
|
571
|
+
const network_path = path.resolve(keystore_path, 'network.json');
|
|
572
|
+
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
573
|
+
const network_list = networks.networks;
|
|
574
|
+
const network_len = network_list.length;
|
|
575
|
+
|
|
576
|
+
let account_info = getAccountInfo(keystore_path, account_label);
|
|
577
|
+
let default_network = account_info.default_network;
|
|
578
|
+
|
|
579
|
+
const network_type = getNetworkTypeByName(keystore_path, default_network);
|
|
580
|
+
|
|
581
|
+
for (let i = 0; i < network_len; i++) {
|
|
582
|
+
|
|
583
|
+
const network = network_list[i];
|
|
584
|
+
const this_network_type = getNetworkTypeByName(keystore_path, network.name);
|
|
585
|
+
if (account_info.account_type === "PK" && network_type !== this_network_type) {
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
let account_address: string;
|
|
590
|
+
if (account_info.account_type === "PK") {
|
|
591
|
+
account_address = account_info.data[account_index].ciphertexts.address;
|
|
592
|
+
} else {
|
|
593
|
+
if (this_network_type === "evm") {
|
|
594
|
+
account_address = account_info.data[account_index].ciphertexts.evm.address;
|
|
595
|
+
} else {
|
|
596
|
+
account_address = account_info.data[account_index].ciphertexts.solana.address;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if (network.name === default_network) {
|
|
601
|
+
console.log(`● ${account_address} [${network.name}]`);
|
|
602
|
+
} else {
|
|
603
|
+
console.log(`○ ${account_address} [${network.name}]`);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
425
608
|
export const switchNetworkByAccountLabel = async (keystore_path: string, account_label: string, is_account_label: boolean) => {
|
|
426
609
|
const network_path = path.resolve(keystore_path, 'network.json');
|
|
427
610
|
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
@@ -523,6 +706,8 @@ export const getAccountBalance = async (account: string, keystore_path: string,
|
|
|
523
706
|
let balance = new BigNumber(result.output.toString());
|
|
524
707
|
result.output = balance.dividedBy(Math.pow(10, decimals)).toFixed(4, BigNumber.ROUND_FLOOR);
|
|
525
708
|
}
|
|
709
|
+
|
|
710
|
+
deleteTokenBalance(network_info.chainId.toString(), account, "0");
|
|
526
711
|
return result;
|
|
527
712
|
}
|
|
528
713
|
|
|
@@ -560,3 +745,8 @@ export const getEvmNetworks = (keystore_path: string) => {
|
|
|
560
745
|
return result;
|
|
561
746
|
}
|
|
562
747
|
|
|
748
|
+
export const getStatus = (keystore_path: string) => {
|
|
749
|
+
const network_path = path.resolve(keystore_path, 'network.json');
|
|
750
|
+
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
751
|
+
return networks.status;
|
|
752
|
+
}
|
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 { chainAddressValidator, confirmSomething, editorSomething, getAccountChainType, hexValidator, inputSomething, numberValidator, selectSomething } from "./utils";
|
|
4
|
+
import { addrValidator, chainAddressValidator, confirmSomething, editorSomething, getAccountChainType, hexValidator, inputSomething, numberValidator, selectSomething } 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';
|
|
@@ -638,10 +638,10 @@ const excuteTools = async (keystore_path: string, account_label: string, account
|
|
|
638
638
|
);
|
|
639
639
|
|
|
640
640
|
const option_send_tx = [
|
|
641
|
-
'> Back',
|
|
642
|
-
new inquirer.Separator('----------------------------------'),
|
|
643
641
|
'> Send Raw Tx',
|
|
644
|
-
'> Send Token'
|
|
642
|
+
'> Send Token',
|
|
643
|
+
new inquirer.Separator('----------------------------------'),
|
|
644
|
+
'> Back',
|
|
645
645
|
];
|
|
646
646
|
|
|
647
647
|
const selected_send_tx = await selectSomething(option_send_tx);
|
|
@@ -697,10 +697,10 @@ const excuteTools = async (keystore_path: string, account_label: string, account
|
|
|
697
697
|
|
|
698
698
|
export const selectToolsOptions = async (keystore_path: string, account_label: string, account_address: string, wative_core: typeof WativeCore) => {
|
|
699
699
|
const tools_options = [
|
|
700
|
-
'> Back',
|
|
701
|
-
new inquirer.Separator('----------------------------------'),
|
|
702
700
|
'> SendTx',
|
|
703
|
-
'> SignMessage'
|
|
701
|
+
'> SignMessage',
|
|
702
|
+
new inquirer.Separator('----------------------------------'),
|
|
703
|
+
'> Back'
|
|
704
704
|
];
|
|
705
705
|
|
|
706
706
|
const selected_tools_option = await selectSomething(tools_options);
|
|
@@ -729,15 +729,44 @@ export const selectToolsOptions = async (keystore_path: string, account_label: s
|
|
|
729
729
|
}
|
|
730
730
|
|
|
731
731
|
export const showTools = async (keystore_path: string, wative_core: typeof WativeCore) => {
|
|
732
|
-
|
|
733
|
-
|
|
732
|
+
let options = [
|
|
733
|
+
"> Send Tx",
|
|
734
|
+
"> Search Accounts",
|
|
735
|
+
new inquirer.Separator('----------------------------------'),
|
|
736
|
+
"> Back"
|
|
737
|
+
];
|
|
738
|
+
|
|
739
|
+
let selected_option = await selectSomething(options);
|
|
740
|
+
|
|
741
|
+
if (selected_option === "> Back") {
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
let account_address: any;
|
|
746
|
+
if (selected_option === "> Send Tx") {
|
|
747
|
+
account_address = await inputSomething("Input address to send tx", chainAddressValidator);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
if (selected_option === "> Search Accounts") {
|
|
751
|
+
account_address = await inputSomething("Input part address to send tx", addrValidator);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
let account_label_info = wative_core.account.getAccountLabel(account_address);
|
|
755
|
+
if (account_label_info === null) {
|
|
756
|
+
console.log(chalk.red("Account not found"));
|
|
757
|
+
await showTools(keystore_path, wative_core);
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
let account_label = account_label_info.account_label;
|
|
762
|
+
account_address = account_label_info.account_address;
|
|
734
763
|
if (account_label === null) {
|
|
735
764
|
console.log(chalk.red("Account not found"));
|
|
736
765
|
await showTools(keystore_path, wative_core);
|
|
737
766
|
return;
|
|
738
767
|
}
|
|
739
768
|
let login_result = await loginIn(account_label, wative_core);
|
|
740
|
-
if (!login_result) {
|
|
769
|
+
if (!login_result.isLoginIn) {
|
|
741
770
|
await showTools(keystore_path, wative_core);
|
|
742
771
|
return;
|
|
743
772
|
}
|