@1sat/wallet-toolbox 0.0.36 → 0.0.37
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/wallet/factory.d.ts +4 -0
- package/dist/wallet/factory.js +31 -9
- package/package.json +1 -1
package/dist/wallet/factory.d.ts
CHANGED
|
@@ -28,6 +28,10 @@ export interface WebWalletConfig {
|
|
|
28
28
|
};
|
|
29
29
|
/** Remote storage URL. If provided, attempts to connect for cloud backup. */
|
|
30
30
|
remoteStorageUrl?: string;
|
|
31
|
+
/** Callback when a transaction is broadcasted (called after remote sync if connected) */
|
|
32
|
+
onTransactionBroadcasted?: (txid: string) => void;
|
|
33
|
+
/** Callback when a transaction is proven (called after remote sync if connected) */
|
|
34
|
+
onTransactionProven?: (txid: string, blockHeight: number) => void;
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
33
37
|
* Result of wallet creation.
|
package/dist/wallet/factory.js
CHANGED
|
@@ -162,10 +162,11 @@ export async function createWebWallet(config) {
|
|
|
162
162
|
unprovenAttemptsLimitMain: 144,
|
|
163
163
|
});
|
|
164
164
|
monitor.addDefaultTasks();
|
|
165
|
-
// 9. Wire up monitor callbacks
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
165
|
+
// 9. Wire up monitor callbacks - sync to remote first, then call user callbacks
|
|
166
|
+
monitor.onTransactionBroadcasted = async (result) => {
|
|
167
|
+
console.log("[Monitor] Transaction broadcasted:", result.txid);
|
|
168
|
+
// Sync to remote backup first (if connected)
|
|
169
|
+
if (remoteClient) {
|
|
169
170
|
try {
|
|
170
171
|
const auth = await storage.getAuth();
|
|
171
172
|
await storage.syncToWriter(auth, remoteClient);
|
|
@@ -174,9 +175,21 @@ export async function createWebWallet(config) {
|
|
|
174
175
|
catch (err) {
|
|
175
176
|
console.warn("[Monitor] Failed to sync after broadcast:", err);
|
|
176
177
|
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
}
|
|
179
|
+
// Then call user callback (if provided)
|
|
180
|
+
if (result.txid && config.onTransactionBroadcasted) {
|
|
181
|
+
try {
|
|
182
|
+
config.onTransactionBroadcasted(result.txid);
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
console.warn("[Monitor] User callback error after broadcast:", err);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
monitor.onTransactionProven = async (status) => {
|
|
190
|
+
console.log("[Monitor] Transaction proven:", status.txid, "block", status.blockHeight);
|
|
191
|
+
// Sync to remote backup first (if connected)
|
|
192
|
+
if (remoteClient) {
|
|
180
193
|
try {
|
|
181
194
|
const auth = await storage.getAuth();
|
|
182
195
|
await storage.syncToWriter(auth, remoteClient);
|
|
@@ -185,8 +198,17 @@ export async function createWebWallet(config) {
|
|
|
185
198
|
catch (err) {
|
|
186
199
|
console.warn("[Monitor] Failed to sync after confirmation:", err);
|
|
187
200
|
}
|
|
188
|
-
}
|
|
189
|
-
|
|
201
|
+
}
|
|
202
|
+
// Then call user callback (if provided)
|
|
203
|
+
if (config.onTransactionProven) {
|
|
204
|
+
try {
|
|
205
|
+
config.onTransactionProven(status.txid, status.blockHeight);
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
console.warn("[Monitor] User callback error after proven:", err);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
190
212
|
// 10. Create cleanup function
|
|
191
213
|
const destroy = async () => {
|
|
192
214
|
monitor.stopTasks();
|