@1sat/wallet-toolbox 0.0.35 → 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 +5 -1
- package/dist/wallet/factory.js +49 -2
- package/package.json +1 -1
package/dist/wallet/factory.d.ts
CHANGED
|
@@ -21,13 +21,17 @@ export interface WebWalletConfig {
|
|
|
21
21
|
adminOriginator: string;
|
|
22
22
|
/** Permission configuration for WalletPermissionsManager */
|
|
23
23
|
permissionsConfig: PermissionsManagerConfig;
|
|
24
|
-
/** Fee model. Default: { model: 'sat/kb', value:
|
|
24
|
+
/** Fee model. Default: { model: 'sat/kb', value: 100 } */
|
|
25
25
|
feeModel?: {
|
|
26
26
|
model: "sat/kb";
|
|
27
27
|
value: number;
|
|
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,13 +162,60 @@ export async function createWebWallet(config) {
|
|
|
162
162
|
unprovenAttemptsLimitMain: 144,
|
|
163
163
|
});
|
|
164
164
|
monitor.addDefaultTasks();
|
|
165
|
-
// 9.
|
|
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) {
|
|
170
|
+
try {
|
|
171
|
+
const auth = await storage.getAuth();
|
|
172
|
+
await storage.syncToWriter(auth, remoteClient);
|
|
173
|
+
console.log("[Monitor] Synced to backup after broadcast");
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
console.warn("[Monitor] Failed to sync after broadcast:", err);
|
|
177
|
+
}
|
|
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) {
|
|
193
|
+
try {
|
|
194
|
+
const auth = await storage.getAuth();
|
|
195
|
+
await storage.syncToWriter(auth, remoteClient);
|
|
196
|
+
console.log("[Monitor] Synced to backup after confirmation");
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
console.warn("[Monitor] Failed to sync after confirmation:", err);
|
|
200
|
+
}
|
|
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
|
+
};
|
|
212
|
+
// 10. Create cleanup function
|
|
166
213
|
const destroy = async () => {
|
|
167
214
|
monitor.stopTasks();
|
|
168
215
|
await monitor.destroy();
|
|
169
216
|
await underlyingWallet.destroy();
|
|
170
217
|
};
|
|
171
|
-
//
|
|
218
|
+
// 11. Create fullSync function if remote storage is connected
|
|
172
219
|
const fullSyncFn = remoteClient
|
|
173
220
|
? async (onProgress) => {
|
|
174
221
|
return fullSync({
|