@unicitylabs/sphere-sdk 0.14.11-dev.7 → 0.14.11-dev.8

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.
@@ -536,12 +536,19 @@ var SerialChain = class {
536
536
  return run;
537
537
  }
538
538
  };
539
- function coalesced(run) {
539
+ function coalesced(run, observe) {
540
540
  let inFlight = false;
541
541
  let queued = false;
542
542
  const start = () => {
543
543
  inFlight = true;
544
- void run().catch(() => void 0).finally(() => {
544
+ let running;
545
+ try {
546
+ running = run();
547
+ } catch {
548
+ running = Promise.resolve();
549
+ }
550
+ observe?.(running);
551
+ void running.catch(() => void 0).finally(() => {
545
552
  inFlight = false;
546
553
  if (!queued) return;
547
554
  queued = false;
@@ -3248,6 +3255,17 @@ var Receive = class {
3248
3255
  await flushAcks(deps, pending, epochOf);
3249
3256
  deps.refreshView();
3250
3257
  }
3258
+ /** One listing pass: process each entry, flushing and refreshing as it goes. */
3259
+ async drainPages(ctx, basis) {
3260
+ const { deps, engine, pending, stored, pageEpoch } = ctx;
3261
+ for await (const entry of deps.delivery.incoming(basis === null ? void 0 : String(basis.cursor))) {
3262
+ const storedBefore = stored.length;
3263
+ await this.processEntry(deps, engine, entry, pending, stored);
3264
+ if (pending.length >= ACK_BATCH_SIZE) await flushAcks(deps, pending, pageEpoch);
3265
+ if (stored.length > storedBefore) await this.maybeRefresh(deps, pending, pageEpoch);
3266
+ }
3267
+ await flushAcks(deps, pending, pageEpoch);
3268
+ }
3251
3269
  async doDrain() {
3252
3270
  const deps = this.deps;
3253
3271
  this.lastRefreshAt = deps.now?.() ?? Date.now();
@@ -3259,13 +3277,7 @@ var Receive = class {
3259
3277
  const record = await deps.kv.get(STORE_KEYS.streamCursor("mailbox"));
3260
3278
  let basis = record !== null && record.syncEpoch === deps.syncEpoch() ? record : null;
3261
3279
  for (let pass = 0; pass < 2; pass++) {
3262
- for await (const entry of deps.delivery.incoming(basis === null ? void 0 : String(basis.cursor))) {
3263
- const storedBefore = stored.length;
3264
- await this.processEntry(deps, engine, entry, pending, stored);
3265
- if (pending.length >= ACK_BATCH_SIZE) await flushAcks(deps, pending, pageEpoch);
3266
- if (stored.length > storedBefore) await this.maybeRefresh(deps, pending, pageEpoch);
3267
- }
3268
- await flushAcks(deps, pending, pageEpoch);
3280
+ await this.drainPages({ deps, engine, pending, stored, pageEpoch }, basis);
3269
3281
  const served = deps.delivery.incomingEpoch();
3270
3282
  if (basis === null || served === null || served === basis.syncEpoch) break;
3271
3283
  await deps.kv.remove(STORE_KEYS.streamCursor("mailbox"));
@@ -3278,6 +3290,7 @@ var Receive = class {
3278
3290
  logger.warn("PaymentsV2", "receive ack flush failed \u2014 cursor holds at the acked prefix:", flushErr);
3279
3291
  });
3280
3292
  }
3293
+ if (stored.length > 0) deps.refreshView?.();
3281
3294
  return stored;
3282
3295
  }
3283
3296
  async processEntry(deps, engine, entry, pending, stored) {
@@ -4208,7 +4221,7 @@ function composeFacadeParts(deps, hooks) {
4208
4221
  const machineDeps = buildMachineDeps(deps, hooks, historyStore);
4209
4222
  const machineStores = createMachineStores(deps.kv);
4210
4223
  const heldStates = /* @__PURE__ */ new Map();
4211
- const refreshView = coalesced(() => view.delta());
4224
+ const refreshView = coalesced(() => view.delta(), hooks.track);
4212
4225
  return {
4213
4226
  ownPubkeyBytes,
4214
4227
  view,
@@ -4351,7 +4364,8 @@ var PaymentsFacade = class {
4351
4364
  const parts = composeFacadeParts(deps, {
4352
4365
  engine: () => this.engine(),
4353
4366
  send: (request) => this.send(request),
4354
- isActiveOp: (id) => this.activeMoneyOps.has(id)
4367
+ isActiveOp: (id) => this.activeMoneyOps.has(id),
4368
+ track: (op) => this.trackTail(op)
4355
4369
  });
4356
4370
  this.view = parts.view;
4357
4371
  this.wakeRefresh = parts.refreshView;
@@ -4491,7 +4505,6 @@ var PaymentsFacade = class {
4491
4505
  }
4492
4506
  async receive() {
4493
4507
  const transfers = await this.track(this.receiveLoop.drainOnce());
4494
- if (transfers.length > 0) this.trackTail(this.view.delta());
4495
4508
  return { transfers };
4496
4509
  }
4497
4510
  mint(coinId, amount) {