@1sat/wallet-toolbox 0.0.14 → 0.0.16
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.js +22 -23
- package/package.json +1 -1
package/dist/wallet/factory.js
CHANGED
|
@@ -100,34 +100,33 @@ export async function createWebWallet(config) {
|
|
|
100
100
|
backups: storageAny._backups?.map(b => b.settings?.storageIdentityKey),
|
|
101
101
|
conflictingActives: storageAny._conflictingActives?.map(c => c.settings?.storageIdentityKey),
|
|
102
102
|
});
|
|
103
|
-
//
|
|
104
|
-
//
|
|
103
|
+
// Treat backups as conflicts to pull any data they have.
|
|
104
|
+
// Remote storage may have transactions that local doesn't know about
|
|
105
|
+
// (e.g., from sweep-ui syncing to remote).
|
|
106
|
+
if (storageAny._backups && storageAny._backups.length > 0) {
|
|
107
|
+
console.log("[createWebWallet] Reclassifying backups as conflicts to pull remote data...");
|
|
108
|
+
storageAny._conflictingActives = storageAny._conflictingActives || [];
|
|
109
|
+
storageAny._conflictingActives.push(...storageAny._backups);
|
|
110
|
+
storageAny._backups = [];
|
|
111
|
+
}
|
|
112
|
+
// If there are conflicting actives (including reclassified backups), resolve by merging into local
|
|
113
|
+
// This is now blocking since setActive no longer holds IDB transactions during network calls
|
|
105
114
|
if (storageAny._conflictingActives && storageAny._conflictingActives.length > 0) {
|
|
106
115
|
const localKey = storageAny._active?.settings?.storageIdentityKey;
|
|
107
116
|
if (localKey && storageAny.setActive) {
|
|
108
|
-
console.log("[createWebWallet]
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
console.log("[createWebWallet] Syncing with remote storage...");
|
|
118
|
+
try {
|
|
119
|
+
await storageAny.setActive(localKey, (msg) => {
|
|
120
|
+
console.log("[createWebWallet] Sync:", msg);
|
|
121
|
+
return msg;
|
|
122
|
+
});
|
|
123
|
+
console.log("[createWebWallet] Remote sync complete");
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
console.log("[createWebWallet] Remote sync failed:", err instanceof Error ? err.message : err);
|
|
127
|
+
}
|
|
117
128
|
}
|
|
118
129
|
}
|
|
119
|
-
else if (storageAny._backups && storageAny._backups.length > 0 && storageAny.updateBackups) {
|
|
120
|
-
// No conflicts - push local state to remote backup (non-blocking to avoid IDB timeout)
|
|
121
|
-
console.log("[createWebWallet] Starting background backup to remote...");
|
|
122
|
-
storageAny.updateBackups(undefined, (msg) => {
|
|
123
|
-
console.log("[createWebWallet] Backup:", msg);
|
|
124
|
-
return msg;
|
|
125
|
-
}).then(() => {
|
|
126
|
-
console.log("[createWebWallet] Background backup complete");
|
|
127
|
-
}).catch((err) => {
|
|
128
|
-
console.log("[createWebWallet] Background backup failed:", err instanceof Error ? err.message : err);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
130
|
// Update wallet's storage reference
|
|
132
131
|
underlyingWallet._storage = storage;
|
|
133
132
|
console.log("[createWebWallet] Remote storage connected successfully");
|