@1sat/sweep-ui 0.0.93 → 0.0.95

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.
@@ -1 +1 @@
1
- {"version":3,"file":"SweepApp.d.ts","sourceRoot":"","sources":["../../src/components/SweepApp.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,UAAU,CAAA;AAgB3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAmB1C,MAAM,WAAW,aAAa;IAC7B,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI,CAAA;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,wBAAgB,QAAQ,CAAC,EACxB,UAAU,EAAE,WAAW,EACvB,MAAM,EAAE,cAAc,EACtB,SAAS,GACT,EAAE,aAAa,+BAimBf"}
1
+ {"version":3,"file":"SweepApp.d.ts","sourceRoot":"","sources":["../../src/components/SweepApp.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,UAAU,CAAA;AAgB3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAmB1C,MAAM,WAAW,aAAa;IAC7B,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI,CAAA;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,wBAAgB,QAAQ,CAAC,EACxB,UAAU,EAAE,WAAW,EACvB,MAAM,EAAE,cAAc,EACtB,SAAS,GACT,EAAE,aAAa,+BAonBf"}
package/dist/index.js CHANGED
@@ -286,12 +286,13 @@ var SWEEP_BATCH_SIZE = 25;
286
286
  function getOwner(output) {
287
287
  return output.events?.find((e) => e.startsWith("own:"))?.slice(4);
288
288
  }
289
- function buildKeys(outputs, keyMap) {
290
- return outputs.map((output) => {
291
- const owner = getOwner(output);
289
+ function buildKeys(outputs, keyMap, inputs = outputs) {
290
+ const owners = new Map(outputs.map((output) => [output.outpoint, getOwner(output)]));
291
+ return inputs.map(({ outpoint }) => {
292
+ const owner = owners.get(outpoint);
292
293
  const key = owner ? keyMap.get(owner) : undefined;
293
294
  if (!key)
294
- throw new Error(`No key for output ${output.outpoint} (owner: ${owner})`);
295
+ throw new Error(`No key for output ${outpoint} (owner: ${owner})`);
295
296
  return key;
296
297
  });
297
298
  }
@@ -330,18 +331,19 @@ async function executeSweep(params) {
330
331
  const inputs = await prepareSweepInputs(ctx, batch);
331
332
  const cancelResult = await sweepOrdinals.execute(ctx, {
332
333
  inputs,
333
- keys: buildKeys(batch, keys)
334
+ keys: buildKeys(batch, keys, inputs)
334
335
  });
335
- if (cancelResult.error) {
336
- result.errors.push(`Listings batch ${b + 1}: ${cancelResult.error}`);
337
- break;
338
- }
339
- if (cancelResult.txid)
340
- result.listingTxids.push(cancelResult.txid);
336
+ if (cancelResult.error)
337
+ throw new Error(cancelResult.error);
338
+ const txid = cancelResult.txid?.trim();
339
+ if (!txid)
340
+ throw new Error("Cancellation returned no transaction ID");
341
+ result.listingTxids.push(txid);
341
342
  result.cancelledListings.push(...batch.map((o) => o.outpoint));
342
343
  } catch (e) {
343
344
  result.errors.push(`Listings batch ${b + 1}: ${e instanceof Error ? e.message : String(e)}`);
344
- break;
345
+ onProgress("Sweep stopped with errors");
346
+ return result;
345
347
  }
346
348
  }
347
349
  }
@@ -351,13 +353,15 @@ async function executeSweep(params) {
351
353
  const inputs = await prepareSweepInputs(ctx, funding);
352
354
  const bsvResult = await sweepBsv.execute(ctx, {
353
355
  inputs,
354
- keys: buildKeys(funding, keys),
356
+ keys: buildKeys(funding, keys, inputs),
355
357
  amount
356
358
  });
357
359
  if (bsvResult.error)
358
- result.errors.push(`BSV: ${bsvResult.error}`);
359
- else if (bsvResult.txid)
360
- result.bsvTxid = bsvResult.txid;
360
+ throw new Error(bsvResult.error);
361
+ const txid = bsvResult.txid?.trim();
362
+ if (!txid)
363
+ throw new Error("Sweep returned no transaction ID");
364
+ result.bsvTxid = txid;
361
365
  } catch (e) {
362
366
  result.errors.push(`BSV: ${e instanceof Error ? e.message : String(e)}`);
363
367
  }
@@ -373,14 +377,14 @@ async function executeSweep(params) {
373
377
  const inputs = await prepareSweepInputs(ctx, batch);
374
378
  const ordResult = await sweepOrdinals.execute(ctx, {
375
379
  inputs,
376
- keys: buildKeys(batch, keys)
380
+ keys: buildKeys(batch, keys, inputs)
377
381
  });
378
- if (ordResult.error) {
379
- result.errors.push(`Ordinals batch ${b + 1}/${batches.length}: ${ordResult.error}`);
380
- break;
381
- }
382
- if (ordResult.txid)
383
- result.ordinalTxids.push(ordResult.txid);
382
+ if (ordResult.error)
383
+ throw new Error(ordResult.error);
384
+ const txid = ordResult.txid?.trim();
385
+ if (!txid)
386
+ throw new Error("Sweep returned no transaction ID");
387
+ result.ordinalTxids.push(txid);
384
388
  result.sweptOutpoints.push(...batch.map((o) => o.outpoint));
385
389
  } catch (e) {
386
390
  result.errors.push(`Ordinals batch ${b + 1}/${batches.length}: ${e instanceof Error ? e.message : String(e)}`);
@@ -2425,7 +2429,8 @@ function SweepApp({
2425
2429
  setSweepProgress(label + "...");
2426
2430
  try {
2427
2431
  const txid = await op();
2428
- addTx(label, txid);
2432
+ if (txid)
2433
+ addTx(label, txid);
2429
2434
  toast.success(label);
2430
2435
  await refreshAssets();
2431
2436
  } catch (e) {
@@ -2465,11 +2470,14 @@ function SweepApp({
2465
2470
  amount: sweepAmount ?? undefined,
2466
2471
  onProgress: setSweepProgress
2467
2472
  });
2468
- if (result.errors.length > 0)
2469
- throw new Error(result.errors[0]);
2470
2473
  for (const txid of result.listingTxids)
2471
2474
  addTx("Cancel listings", txid);
2472
- return result.bsvTxid ?? result.listingTxids[0] ?? "";
2475
+ if (result.errors.length > 0) {
2476
+ if (result.cancelledListings.length > 0)
2477
+ await refreshAssets();
2478
+ throw new Error(result.errors[0]);
2479
+ }
2480
+ return result.bsvTxid ?? "";
2473
2481
  });
2474
2482
  }, [
2475
2483
  resolveWallet,
@@ -2479,7 +2487,8 @@ function SweepApp({
2479
2487
  getSelectedFunding,
2480
2488
  runOperation,
2481
2489
  keyMap,
2482
- addTx
2490
+ addTx,
2491
+ refreshAssets
2483
2492
  ]);
2484
2493
  const handleCancelListings = useCallback2(async () => {
2485
2494
  const wallet = resolveWallet();
@@ -2494,11 +2503,27 @@ function SweepApp({
2494
2503
  listings: assets.listings,
2495
2504
  onProgress: setSweepProgress
2496
2505
  });
2497
- if (result.errors.length > 0)
2506
+ if (result.errors.length > 0) {
2507
+ for (const txid of result.listingTxids)
2508
+ addTx("Cancel listings", txid);
2509
+ if (result.cancelledListings.length > 0)
2510
+ await refreshAssets();
2498
2511
  throw new Error(result.errors[0]);
2499
- return result.listingTxids[0] ?? "";
2512
+ }
2513
+ for (let i = 0;i < result.listingTxids.length - 1; i++) {
2514
+ addTx("Cancel listings", result.listingTxids[i]);
2515
+ }
2516
+ return result.listingTxids[result.listingTxids.length - 1] ?? "";
2500
2517
  });
2501
- }, [resolveWallet, legacyKeys, assets, keyMap, runOperation]);
2518
+ }, [
2519
+ resolveWallet,
2520
+ legacyKeys,
2521
+ assets,
2522
+ keyMap,
2523
+ runOperation,
2524
+ addTx,
2525
+ refreshAssets
2526
+ ]);
2502
2527
  const handleSendBsv = useCallback2(async (destination) => {
2503
2528
  if (!legacyKeys || !assets)
2504
2529
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"sweeper.d.ts","sourceRoot":"","sources":["../../src/lib/sweeper.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAG7C,wFAAwF;AACxF,eAAO,MAAM,gBAAgB,KAAK,CAAA;AAElC,MAAM,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7C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/sweep-ui",
3
- "version": "0.0.93",
3
+ "version": "0.0.95",
4
4
  "description": "Sweep UI components for migrating legacy BSV assets",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -29,11 +29,11 @@
29
29
  ],
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
- "@1sat/actions": "0.0.214",
33
- "@1sat/client": "0.0.52",
34
- "@1sat/connect": "0.0.92",
35
- "@1sat/types": "0.0.44",
36
- "@1sat/utils": "0.0.35",
32
+ "@1sat/actions": "0.0.216",
33
+ "@1sat/client": "0.0.53",
34
+ "@1sat/connect": "0.0.93",
35
+ "@1sat/types": "0.0.45",
36
+ "@1sat/utils": "0.0.36",
37
37
  "bitcoin-backup": "^0.0.11",
38
38
  "class-variance-authority": "^0.7.1",
39
39
  "clsx": "^2.1.1",
@@ -42,11 +42,11 @@
42
42
  "tailwind-merge": "^3.5.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "@bsv/sdk": "^2.5.0",
45
+ "@bsv/sdk": "^2.6.0",
46
46
  "react": "^18.0.0 || ^19.0.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@bsv/sdk": "^2.5.0",
49
+ "@bsv/sdk": "^2.6.0",
50
50
  "@types/react": "^19.0.0",
51
51
  "react": "^19.0.0",
52
52
  "typescript": "~5.7.0"
@@ -221,7 +221,7 @@ export function SweepApp({
221
221
  setSweepProgress(label + '...')
222
222
  try {
223
223
  const txid = await op()
224
- addTx(label, txid)
224
+ if (txid) addTx(label, txid)
225
225
  toast.success(label)
226
226
  await refreshAssets()
227
227
  } catch (e) {
@@ -261,9 +261,12 @@ export function SweepApp({
261
261
  amount: sweepAmount ?? undefined,
262
262
  onProgress: setSweepProgress,
263
263
  })
264
- if (result.errors.length > 0) throw new Error(result.errors[0])
265
264
  for (const txid of result.listingTxids) addTx('Cancel listings', txid)
266
- return result.bsvTxid ?? result.listingTxids[0] ?? ''
265
+ if (result.errors.length > 0) {
266
+ if (result.cancelledListings.length > 0) await refreshAssets()
267
+ throw new Error(result.errors[0])
268
+ }
269
+ return result.bsvTxid ?? ''
267
270
  })
268
271
  }, [
269
272
  resolveWallet,
@@ -274,6 +277,7 @@ export function SweepApp({
274
277
  runOperation,
275
278
  keyMap,
276
279
  addTx,
280
+ refreshAssets,
277
281
  ])
278
282
 
279
283
  const handleCancelListings = useCallback(async () => {
@@ -289,10 +293,25 @@ export function SweepApp({
289
293
  listings: assets.listings,
290
294
  onProgress: setSweepProgress,
291
295
  })
292
- if (result.errors.length > 0) throw new Error(result.errors[0])
293
- return result.listingTxids[0] ?? ''
296
+ if (result.errors.length > 0) {
297
+ for (const txid of result.listingTxids) addTx('Cancel listings', txid)
298
+ if (result.cancelledListings.length > 0) await refreshAssets()
299
+ throw new Error(result.errors[0])
300
+ }
301
+ for (let i = 0; i < result.listingTxids.length - 1; i++) {
302
+ addTx('Cancel listings', result.listingTxids[i])
303
+ }
304
+ return result.listingTxids[result.listingTxids.length - 1] ?? ''
294
305
  })
295
- }, [resolveWallet, legacyKeys, assets, keyMap, runOperation])
306
+ }, [
307
+ resolveWallet,
308
+ legacyKeys,
309
+ assets,
310
+ keyMap,
311
+ runOperation,
312
+ addTx,
313
+ refreshAssets,
314
+ ])
296
315
 
297
316
  const handleSendBsv = useCallback(
298
317
  async (destination: string) => {
@@ -32,12 +32,15 @@ function getOwner(output: IndexedOutput): string | undefined {
32
32
  function buildKeys(
33
33
  outputs: IndexedOutput[],
34
34
  keyMap: Map<string, PrivateKey>,
35
+ inputs: Pick<IndexedOutput, 'outpoint'>[] = outputs,
35
36
  ): PrivateKey[] {
36
- return outputs.map((output) => {
37
- const owner = getOwner(output)
37
+ const owners = new Map(
38
+ outputs.map((output) => [output.outpoint, getOwner(output)]),
39
+ )
40
+ return inputs.map(({ outpoint }) => {
41
+ const owner = owners.get(outpoint)
38
42
  const key = owner ? keyMap.get(owner) : undefined
39
- if (!key)
40
- throw new Error(`No key for output ${output.outpoint} (owner: ${owner})`)
43
+ if (!key) throw new Error(`No key for output ${outpoint} (owner: ${owner})`)
41
44
  return key
42
45
  })
43
46
  }
@@ -95,19 +98,19 @@ export async function executeSweep(params: {
95
98
  const inputs = await prepareSweepInputs(ctx, batch)
96
99
  const cancelResult = await sweepOrdinals.execute(ctx, {
97
100
  inputs,
98
- keys: buildKeys(batch, keys),
101
+ keys: buildKeys(batch, keys, inputs),
99
102
  })
100
- if (cancelResult.error) {
101
- result.errors.push(`Listings batch ${b + 1}: ${cancelResult.error}`)
102
- break
103
- }
104
- if (cancelResult.txid) result.listingTxids.push(cancelResult.txid)
103
+ if (cancelResult.error) throw new Error(cancelResult.error)
104
+ const txid = cancelResult.txid?.trim()
105
+ if (!txid) throw new Error('Cancellation returned no transaction ID')
106
+ result.listingTxids.push(txid)
105
107
  result.cancelledListings.push(...batch.map((o) => o.outpoint))
106
108
  } catch (e) {
107
109
  result.errors.push(
108
110
  `Listings batch ${b + 1}: ${e instanceof Error ? e.message : String(e)}`,
109
111
  )
110
- break
112
+ onProgress('Sweep stopped with errors')
113
+ return result
111
114
  }
112
115
  }
113
116
  }
@@ -118,11 +121,13 @@ export async function executeSweep(params: {
118
121
  const inputs = await prepareSweepInputs(ctx, funding)
119
122
  const bsvResult = await sweepBsv.execute(ctx, {
120
123
  inputs,
121
- keys: buildKeys(funding, keys),
124
+ keys: buildKeys(funding, keys, inputs),
122
125
  amount,
123
126
  })
124
- if (bsvResult.error) result.errors.push(`BSV: ${bsvResult.error}`)
125
- else if (bsvResult.txid) result.bsvTxid = bsvResult.txid
127
+ if (bsvResult.error) throw new Error(bsvResult.error)
128
+ const txid = bsvResult.txid?.trim()
129
+ if (!txid) throw new Error('Sweep returned no transaction ID')
130
+ result.bsvTxid = txid
126
131
  } catch (e) {
127
132
  result.errors.push(`BSV: ${e instanceof Error ? e.message : String(e)}`)
128
133
  }
@@ -143,15 +148,12 @@ export async function executeSweep(params: {
143
148
  const inputs = await prepareSweepInputs(ctx, batch)
144
149
  const ordResult = await sweepOrdinals.execute(ctx, {
145
150
  inputs,
146
- keys: buildKeys(batch, keys),
151
+ keys: buildKeys(batch, keys, inputs),
147
152
  })
148
- if (ordResult.error) {
149
- result.errors.push(
150
- `Ordinals batch ${b + 1}/${batches.length}: ${ordResult.error}`,
151
- )
152
- break
153
- }
154
- if (ordResult.txid) result.ordinalTxids.push(ordResult.txid)
153
+ if (ordResult.error) throw new Error(ordResult.error)
154
+ const txid = ordResult.txid?.trim()
155
+ if (!txid) throw new Error('Sweep returned no transaction ID')
156
+ result.ordinalTxids.push(txid)
155
157
  result.sweptOutpoints.push(...batch.map((o) => o.outpoint))
156
158
  } catch (e) {
157
159
  result.errors.push(