@arkade-os/sdk 0.3.1 → 0.3.2
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/dist/cjs/repositories/walletRepository.js +1 -0
- package/dist/cjs/wallet/serviceWorker/worker.js +29 -16
- package/dist/esm/repositories/walletRepository.js +1 -0
- package/dist/esm/wallet/serviceWorker/worker.js +29 -16
- package/dist/types/wallet/serviceWorker/worker.d.ts +1 -0
- package/package.json +1 -1
|
@@ -31,6 +31,7 @@ const deserializeTapLeaf = (t) => {
|
|
|
31
31
|
};
|
|
32
32
|
const deserializeVtxo = (o) => ({
|
|
33
33
|
...o,
|
|
34
|
+
createdAt: new Date(o.createdAt),
|
|
34
35
|
tapTree: fromHex(o.tapTree),
|
|
35
36
|
forfeitTapLeafScript: deserializeTapLeaf(o.forfeitTapLeafScript),
|
|
36
37
|
intentTapLeafScript: deserializeTapLeaf(o.intentTapLeafScript),
|
|
@@ -69,6 +69,33 @@ class Worker {
|
|
|
69
69
|
const address = await this.wallet.getBoardingAddress();
|
|
70
70
|
return await this.walletRepository.getUtxos(address);
|
|
71
71
|
}
|
|
72
|
+
async getTransactionHistory() {
|
|
73
|
+
if (!this.wallet)
|
|
74
|
+
return [];
|
|
75
|
+
let txs = [];
|
|
76
|
+
try {
|
|
77
|
+
const { boardingTxs, commitmentsToIgnore: roundsToIgnore } = await this.wallet.getBoardingTxs();
|
|
78
|
+
const { spendable, spent } = await this.getAllVtxos();
|
|
79
|
+
// convert VTXOs to offchain transactions
|
|
80
|
+
console.log("getTransactionHistory - vtxosToTxs:", spendable);
|
|
81
|
+
const offchainTxs = (0, transactionHistory_1.vtxosToTxs)(spendable, spent, roundsToIgnore);
|
|
82
|
+
txs = [...boardingTxs, ...offchainTxs];
|
|
83
|
+
// sort transactions by creation time in descending order (newest first)
|
|
84
|
+
txs.sort(
|
|
85
|
+
// place createdAt = 0 (unconfirmed txs) first, then descending
|
|
86
|
+
(a, b) => {
|
|
87
|
+
if (a.createdAt === 0)
|
|
88
|
+
return -1;
|
|
89
|
+
if (b.createdAt === 0)
|
|
90
|
+
return 1;
|
|
91
|
+
return b.createdAt - a.createdAt;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error("Error getting transaction history:", error);
|
|
96
|
+
}
|
|
97
|
+
return txs;
|
|
98
|
+
}
|
|
72
99
|
async start(withServiceWorkerUpdate = true) {
|
|
73
100
|
self.addEventListener("message", async (event) => {
|
|
74
101
|
await this.handleMessage(event);
|
|
@@ -116,7 +143,7 @@ class Worker {
|
|
|
116
143
|
const address = await this.wallet.getAddress();
|
|
117
144
|
await this.walletRepository.saveVtxos(address, vtxos);
|
|
118
145
|
// Get transaction history to cache boarding txs
|
|
119
|
-
const txs = await this.
|
|
146
|
+
const txs = await this.getTransactionHistory();
|
|
120
147
|
if (txs)
|
|
121
148
|
await this.walletRepository.saveTransactions(address, txs);
|
|
122
149
|
// unsubscribe previous subscription if any
|
|
@@ -434,21 +461,7 @@ class Worker {
|
|
|
434
461
|
return;
|
|
435
462
|
}
|
|
436
463
|
try {
|
|
437
|
-
const
|
|
438
|
-
const { spendable, spent } = await this.getAllVtxos();
|
|
439
|
-
// convert VTXOs to offchain transactions
|
|
440
|
-
const offchainTxs = (0, transactionHistory_1.vtxosToTxs)(spendable, spent, roundsToIgnore);
|
|
441
|
-
const txs = [...boardingTxs, ...offchainTxs];
|
|
442
|
-
// sort transactions by creation time in descending order (newest first)
|
|
443
|
-
txs.sort(
|
|
444
|
-
// place createdAt = 0 (unconfirmed txs) first, then descending
|
|
445
|
-
(a, b) => {
|
|
446
|
-
if (a.createdAt === 0)
|
|
447
|
-
return -1;
|
|
448
|
-
if (b.createdAt === 0)
|
|
449
|
-
return 1;
|
|
450
|
-
return b.createdAt - a.createdAt;
|
|
451
|
-
});
|
|
464
|
+
const txs = await this.getTransactionHistory();
|
|
452
465
|
event.source?.postMessage(response_1.Response.transactionHistory(message.id, txs));
|
|
453
466
|
}
|
|
454
467
|
catch (error) {
|
|
@@ -28,6 +28,7 @@ const deserializeTapLeaf = (t) => {
|
|
|
28
28
|
};
|
|
29
29
|
const deserializeVtxo = (o) => ({
|
|
30
30
|
...o,
|
|
31
|
+
createdAt: new Date(o.createdAt),
|
|
31
32
|
tapTree: fromHex(o.tapTree),
|
|
32
33
|
forfeitTapLeafScript: deserializeTapLeaf(o.forfeitTapLeafScript),
|
|
33
34
|
intentTapLeafScript: deserializeTapLeaf(o.intentTapLeafScript),
|
|
@@ -66,6 +66,33 @@ export class Worker {
|
|
|
66
66
|
const address = await this.wallet.getBoardingAddress();
|
|
67
67
|
return await this.walletRepository.getUtxos(address);
|
|
68
68
|
}
|
|
69
|
+
async getTransactionHistory() {
|
|
70
|
+
if (!this.wallet)
|
|
71
|
+
return [];
|
|
72
|
+
let txs = [];
|
|
73
|
+
try {
|
|
74
|
+
const { boardingTxs, commitmentsToIgnore: roundsToIgnore } = await this.wallet.getBoardingTxs();
|
|
75
|
+
const { spendable, spent } = await this.getAllVtxos();
|
|
76
|
+
// convert VTXOs to offchain transactions
|
|
77
|
+
console.log("getTransactionHistory - vtxosToTxs:", spendable);
|
|
78
|
+
const offchainTxs = vtxosToTxs(spendable, spent, roundsToIgnore);
|
|
79
|
+
txs = [...boardingTxs, ...offchainTxs];
|
|
80
|
+
// sort transactions by creation time in descending order (newest first)
|
|
81
|
+
txs.sort(
|
|
82
|
+
// place createdAt = 0 (unconfirmed txs) first, then descending
|
|
83
|
+
(a, b) => {
|
|
84
|
+
if (a.createdAt === 0)
|
|
85
|
+
return -1;
|
|
86
|
+
if (b.createdAt === 0)
|
|
87
|
+
return 1;
|
|
88
|
+
return b.createdAt - a.createdAt;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
console.error("Error getting transaction history:", error);
|
|
93
|
+
}
|
|
94
|
+
return txs;
|
|
95
|
+
}
|
|
69
96
|
async start(withServiceWorkerUpdate = true) {
|
|
70
97
|
self.addEventListener("message", async (event) => {
|
|
71
98
|
await this.handleMessage(event);
|
|
@@ -113,7 +140,7 @@ export class Worker {
|
|
|
113
140
|
const address = await this.wallet.getAddress();
|
|
114
141
|
await this.walletRepository.saveVtxos(address, vtxos);
|
|
115
142
|
// Get transaction history to cache boarding txs
|
|
116
|
-
const txs = await this.
|
|
143
|
+
const txs = await this.getTransactionHistory();
|
|
117
144
|
if (txs)
|
|
118
145
|
await this.walletRepository.saveTransactions(address, txs);
|
|
119
146
|
// unsubscribe previous subscription if any
|
|
@@ -431,21 +458,7 @@ export class Worker {
|
|
|
431
458
|
return;
|
|
432
459
|
}
|
|
433
460
|
try {
|
|
434
|
-
const
|
|
435
|
-
const { spendable, spent } = await this.getAllVtxos();
|
|
436
|
-
// convert VTXOs to offchain transactions
|
|
437
|
-
const offchainTxs = vtxosToTxs(spendable, spent, roundsToIgnore);
|
|
438
|
-
const txs = [...boardingTxs, ...offchainTxs];
|
|
439
|
-
// sort transactions by creation time in descending order (newest first)
|
|
440
|
-
txs.sort(
|
|
441
|
-
// place createdAt = 0 (unconfirmed txs) first, then descending
|
|
442
|
-
(a, b) => {
|
|
443
|
-
if (a.createdAt === 0)
|
|
444
|
-
return -1;
|
|
445
|
-
if (b.createdAt === 0)
|
|
446
|
-
return 1;
|
|
447
|
-
return b.createdAt - a.createdAt;
|
|
448
|
-
});
|
|
461
|
+
const txs = await this.getTransactionHistory();
|
|
449
462
|
event.source?.postMessage(Response.transactionHistory(message.id, txs));
|
|
450
463
|
}
|
|
451
464
|
catch (error) {
|
|
@@ -29,6 +29,7 @@ export declare class Worker {
|
|
|
29
29
|
* Get all boarding utxos from wallet repository
|
|
30
30
|
*/
|
|
31
31
|
private getAllBoardingUtxos;
|
|
32
|
+
private getTransactionHistory;
|
|
32
33
|
start(withServiceWorkerUpdate?: boolean): Promise<void>;
|
|
33
34
|
clear(): Promise<void>;
|
|
34
35
|
reload(): Promise<void>;
|