hodl-wallet 1.7.4 → 1.7.8
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/index.js +24 -3
- package/network/eth.js +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -37,6 +37,27 @@ class Wallet {
|
|
|
37
37
|
this.networkUsage = {};
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
formatAmount(num) {
|
|
41
|
+
num = parseFloat(num);
|
|
42
|
+
const numStr = num.toString();
|
|
43
|
+
|
|
44
|
+
if (!numStr.includes('.')) {
|
|
45
|
+
// No decimal point; append '.00'
|
|
46
|
+
return numStr + '.00';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const decimalPart = numStr.split('.')[1];
|
|
50
|
+
const decimalLength = decimalPart.length;
|
|
51
|
+
|
|
52
|
+
if (decimalLength === 1) {
|
|
53
|
+
// One decimal digit; append '0'
|
|
54
|
+
return num.toFixed(2);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// More than one decimal digit; round to 3 decimal places if needed
|
|
58
|
+
return decimalLength > 3 ? num.toFixed(3) : numStr;
|
|
59
|
+
}
|
|
60
|
+
|
|
40
61
|
async initialize() {
|
|
41
62
|
try {
|
|
42
63
|
this.networkUsage = await this.db.get('networkUsage') || {};
|
|
@@ -315,7 +336,7 @@ class Wallet {
|
|
|
315
336
|
});
|
|
316
337
|
|
|
317
338
|
balances.forEach(([token, balance]) => {
|
|
318
|
-
table.push([token,
|
|
339
|
+
table.push([token, this.formatAmount(balance)]);
|
|
319
340
|
});
|
|
320
341
|
|
|
321
342
|
console.log(table.toString());
|
|
@@ -485,7 +506,7 @@ class Wallet {
|
|
|
485
506
|
const date = this.formatDate(tx.timestamp);
|
|
486
507
|
const contact = await this.db.get('contact', this.network.name, tx.recipient);
|
|
487
508
|
const recipient = contact ? `${tx.recipient} (${contact.name})` : tx.recipient;
|
|
488
|
-
const amount =
|
|
509
|
+
const amount = this.formatAmount(tx.amount);
|
|
489
510
|
table.push([date, recipient, tx.token, amount]);
|
|
490
511
|
table.push([{ colSpan: 4, content: this.selectedNetwork.explorer + tx.hash }]);
|
|
491
512
|
}
|
|
@@ -574,7 +595,7 @@ class Wallet {
|
|
|
574
595
|
const contact = await this.db.get('contact', this.network.name, address);
|
|
575
596
|
const recipient = contact ? `${address} (${contact.name})` : address;
|
|
576
597
|
|
|
577
|
-
table.push([date, recipient, token,
|
|
598
|
+
table.push([date, recipient, token, this.formatAmount(amount)]);
|
|
578
599
|
table.push([{ colSpan: 4, content: this.selectedNetwork.explorer + hash }]);
|
|
579
600
|
|
|
580
601
|
console.log(table.toString());
|
package/network/eth.js
CHANGED
|
@@ -3,7 +3,7 @@ import Web3Network from './lib/Web3Network.js';
|
|
|
3
3
|
export default {
|
|
4
4
|
NetworkClass: Web3Network,
|
|
5
5
|
name: '[ERC-20] Ethereum',
|
|
6
|
-
url: 'https://
|
|
6
|
+
url: 'https://ethereum.publicnode.com',
|
|
7
7
|
nativeToken: 'ETH',
|
|
8
8
|
explorer: 'https://etherscan.io/tx/',
|
|
9
9
|
tokens: {
|