hodl-wallet 1.5.2 → 1.5.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.mjs +23 -18
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -86,7 +86,7 @@ class Wallet {
|
|
|
86
86
|
|
|
87
87
|
async selectNetwork(networkPlugins) {
|
|
88
88
|
// Sort networks by usage count (descending)
|
|
89
|
-
const sortedNetworks = networkPlugins.sort((a, b) =>
|
|
89
|
+
const sortedNetworks = networkPlugins.sort((a, b) =>
|
|
90
90
|
(this.networkUsage[b.name] || 0) - (this.networkUsage[a.name] || 0)
|
|
91
91
|
);
|
|
92
92
|
|
|
@@ -301,7 +301,12 @@ class Wallet {
|
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
async transferFunds() {
|
|
304
|
-
const
|
|
304
|
+
const contacts = this.db.get('contact') || {};
|
|
305
|
+
const addressBook = Object.entries(contacts).map(([address, data]) => ({
|
|
306
|
+
address,
|
|
307
|
+
name: data.name
|
|
308
|
+
}));
|
|
309
|
+
|
|
305
310
|
addressBook.push({ name: 'Go Back', address: '' });
|
|
306
311
|
|
|
307
312
|
// Implement autocomplete for address book
|
|
@@ -314,7 +319,7 @@ class Wallet {
|
|
|
314
319
|
return addressBook
|
|
315
320
|
.filter(entry => entry.name.toLowerCase().includes(input.toLowerCase()) || entry.address.toLowerCase().includes(input.toLowerCase()))
|
|
316
321
|
.map(entry => ({
|
|
317
|
-
name: entry.address ? `${entry.
|
|
322
|
+
name: entry.address ? `${entry.address} (${entry.name})` : entry.name,
|
|
318
323
|
value: entry.address
|
|
319
324
|
}))
|
|
320
325
|
.concat([{ name: input, value: input }]); // Add the input as a possible choice
|
|
@@ -374,7 +379,7 @@ class Wallet {
|
|
|
374
379
|
// Add transaction to history
|
|
375
380
|
this.addToTransactions(address, token, amount, receipt.transactionHash);
|
|
376
381
|
|
|
377
|
-
if (!
|
|
382
|
+
if (!contacts[address]) {
|
|
378
383
|
await this.addToAddressBook(address);
|
|
379
384
|
}
|
|
380
385
|
|
|
@@ -438,7 +443,10 @@ class Wallet {
|
|
|
438
443
|
|
|
439
444
|
history.forEach(tx => {
|
|
440
445
|
const date = this.formatDate(tx.timestamp);
|
|
441
|
-
|
|
446
|
+
const contact = this.db.get('contact', tx.recipient);
|
|
447
|
+
const recipient = contact ? `${tx.recipient} (${contact.name})` : tx.recipient;
|
|
448
|
+
const amount = parseFloat(tx.amount).toFixed(3);
|
|
449
|
+
table.push([date, recipient, tx.token, amount]);
|
|
442
450
|
table.push([{ colSpan: 4, content: this.selectedNetwork.explorer + tx.hash }]);
|
|
443
451
|
});
|
|
444
452
|
|
|
@@ -453,9 +461,8 @@ class Wallet {
|
|
|
453
461
|
});
|
|
454
462
|
|
|
455
463
|
if (name.trim() !== '') {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
this.db.set('addressBook', addressBook);
|
|
464
|
+
|
|
465
|
+
this.db.set('contact', address, 'name', name);
|
|
459
466
|
|
|
460
467
|
const table = new Table({
|
|
461
468
|
head: [{ colSpan: 2, content: "Recipient saved to the address book." }],
|
|
@@ -558,12 +565,10 @@ class Wallet {
|
|
|
558
565
|
|
|
559
566
|
const date = this.formatDate(new Date());
|
|
560
567
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
parseFloat(amount).toFixed(3)
|
|
566
|
-
]);
|
|
568
|
+
const contact = this.db.get('contact', address);
|
|
569
|
+
const recipient = contact ? `${address} (${contact.name})` : address;
|
|
570
|
+
|
|
571
|
+
table.push([date, recipient, token, parseFloat(amount).toFixed(3)]);
|
|
567
572
|
table.push([{ colSpan: 4, content: this.selectedNetwork.explorer + hash }]);
|
|
568
573
|
|
|
569
574
|
console.log(table.toString());
|
|
@@ -844,9 +849,9 @@ while (true) {
|
|
|
844
849
|
name: 'action',
|
|
845
850
|
message: 'What would you like to do?',
|
|
846
851
|
choices: [
|
|
847
|
-
{ name: 'Transfer Funds', value: '
|
|
852
|
+
{ name: 'Transfer Funds', value: 'transferFunds' },
|
|
848
853
|
{ name: 'Show Balance', value: 'balance' },
|
|
849
|
-
{ name: 'Show Sent Transfers', value: '
|
|
854
|
+
{ name: 'Show Sent Transfers', value: 'showTransactions' },
|
|
850
855
|
{ name: 'Account Settings', value: 'account' },
|
|
851
856
|
{ name: 'Exit', value: 'exit' }
|
|
852
857
|
],
|
|
@@ -856,10 +861,10 @@ while (true) {
|
|
|
856
861
|
case 'balance':
|
|
857
862
|
await wallet.showBalance();
|
|
858
863
|
break;
|
|
859
|
-
case '
|
|
864
|
+
case 'transferFunds':
|
|
860
865
|
await wallet.transferFunds();
|
|
861
866
|
break;
|
|
862
|
-
case '
|
|
867
|
+
case 'showTransactions':
|
|
863
868
|
await wallet.showTransactions();
|
|
864
869
|
break;
|
|
865
870
|
case 'account':
|