hodl-wallet 1.7.2 → 1.7.6
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 +27 -4
- 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());
|
|
@@ -414,7 +435,9 @@ class Wallet {
|
|
|
414
435
|
// Add transaction to history
|
|
415
436
|
await this.addToTransactions(address, token, amount, receipt.transactionHash);
|
|
416
437
|
|
|
417
|
-
if
|
|
438
|
+
// Check if the address is already in contacts before asking to add it
|
|
439
|
+
const existingContact = await this.db.get('contact', this.network.name, address);
|
|
440
|
+
if (!existingContact) {
|
|
418
441
|
await this.addToAddressBook(address);
|
|
419
442
|
}
|
|
420
443
|
|
|
@@ -483,7 +506,7 @@ class Wallet {
|
|
|
483
506
|
const date = this.formatDate(tx.timestamp);
|
|
484
507
|
const contact = await this.db.get('contact', this.network.name, tx.recipient);
|
|
485
508
|
const recipient = contact ? `${tx.recipient} (${contact.name})` : tx.recipient;
|
|
486
|
-
const amount =
|
|
509
|
+
const amount = this.formatAmount(tx.amount);
|
|
487
510
|
table.push([date, recipient, tx.token, amount]);
|
|
488
511
|
table.push([{ colSpan: 4, content: this.selectedNetwork.explorer + tx.hash }]);
|
|
489
512
|
}
|
|
@@ -572,7 +595,7 @@ class Wallet {
|
|
|
572
595
|
const contact = await this.db.get('contact', this.network.name, address);
|
|
573
596
|
const recipient = contact ? `${address} (${contact.name})` : address;
|
|
574
597
|
|
|
575
|
-
table.push([date, recipient, token,
|
|
598
|
+
table.push([date, recipient, token, this.formatAmount(amount)]);
|
|
576
599
|
table.push([{ colSpan: 4, content: this.selectedNetwork.explorer + hash }]);
|
|
577
600
|
|
|
578
601
|
console.log(table.toString());
|