@unicitylabs/sphere-sdk 0.14.11-dev.1 → 0.14.11-dev.3

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.
@@ -12884,6 +12884,7 @@ var InventoryView = class {
12884
12884
 
12885
12885
  // modules/payments-v2/receive/Receive.ts
12886
12886
  var ACK_BATCH_SIZE = 200;
12887
+ var REFRESH_INTERVAL_MS = 750;
12887
12888
  var POLL_INTERVAL_MS = 3e4;
12888
12889
  var ATTENTION_CLAIM_CONFLICT = "claim:conflict";
12889
12890
  function receivedDedupKey(tokenId, stateHash) {
@@ -12900,6 +12901,7 @@ var Receive = class {
12900
12901
  drainFlight = new SingleFlight();
12901
12902
  pollTimer = null;
12902
12903
  unsubscribeWake = null;
12904
+ lastRefreshAt = 0;
12903
12905
  drainOnce() {
12904
12906
  return this.drainFlight.run(() => this.doDrain());
12905
12907
  }
@@ -12917,8 +12919,28 @@ var Receive = class {
12917
12919
  this.unsubscribeWake?.();
12918
12920
  this.unsubscribeWake = null;
12919
12921
  }
12922
+ /**
12923
+ * Flush what has been accepted, then ask for a mirror refresh — at most once
12924
+ * per REFRESH_INTERVAL_MS.
12925
+ *
12926
+ * The flush is not incidental. A `claimed` ack is what materializes a token
12927
+ * into SERVER inventory, and acks otherwise sit queued until ACK_BATCH_SIZE
12928
+ * (200) — so for any ordinary drain, including the 54-token case this exists
12929
+ * for, refreshing before the flush would query an inventory holding none of
12930
+ * the tokens just accepted, and the balance would still only move at the end.
12931
+ * Ordering is preserved: store() still precedes the ack (§5.7).
12932
+ */
12933
+ async maybeRefresh(deps, pending, epochOf) {
12934
+ if (deps.refreshView === void 0) return;
12935
+ const now = deps.now?.() ?? Date.now();
12936
+ if (now - this.lastRefreshAt < REFRESH_INTERVAL_MS) return;
12937
+ this.lastRefreshAt = now;
12938
+ await flushAcks(deps, pending, epochOf);
12939
+ deps.refreshView();
12940
+ }
12920
12941
  async doDrain() {
12921
12942
  const deps = this.deps;
12943
+ this.lastRefreshAt = deps.now?.() ?? Date.now();
12922
12944
  const engine = deps.engine();
12923
12945
  const stored = [];
12924
12946
  const pending = [];
@@ -12928,8 +12950,10 @@ var Receive = class {
12928
12950
  let basis = record !== null && record.syncEpoch === deps.syncEpoch() ? record : null;
12929
12951
  for (let pass = 0; pass < 2; pass++) {
12930
12952
  for await (const entry of deps.delivery.incoming(basis === null ? void 0 : String(basis.cursor))) {
12953
+ const storedBefore = stored.length;
12931
12954
  await this.processEntry(deps, engine, entry, pending, stored);
12932
12955
  if (pending.length >= ACK_BATCH_SIZE) await flushAcks(deps, pending, pageEpoch);
12956
+ if (stored.length > storedBefore) await this.maybeRefresh(deps, pending, pageEpoch);
12933
12957
  }
12934
12958
  await flushAcks(deps, pending, pageEpoch);
12935
12959
  const served = deps.delivery.incomingEpoch();
@@ -13829,7 +13853,7 @@ function composeFacadeParts(deps, hooks) {
13829
13853
  machineDeps,
13830
13854
  machine: new TransferMachine(machineDeps),
13831
13855
  heldStates,
13832
- receiveLoop: buildReceive(deps, hooks, historyStore, heldStates),
13856
+ receiveLoop: buildReceive(deps, hooks, historyStore, heldStates, view),
13833
13857
  requests: buildRequests(deps, hooks),
13834
13858
  restoreDeps: buildRestoreDeps(deps, machineDeps, machineStores, view)
13835
13859
  };
@@ -13896,7 +13920,7 @@ function buildMachineDeps(deps, hooks, historyStore) {
13896
13920
  }
13897
13921
  };
13898
13922
  }
13899
- function buildReceive(deps, hooks, historyStore, heldStates) {
13923
+ function buildReceive(deps, hooks, historyStore, heldStates, view) {
13900
13924
  return new Receive({
13901
13925
  delivery: deps.deliveryPort,
13902
13926
  engine: () => hooks.engine(),
@@ -13910,6 +13934,11 @@ function buildReceive(deps, hooks, historyStore, heldStates) {
13910
13934
  registry: deps.registry,
13911
13935
  recordReceived: (record) => recordReceived(historyStore, record),
13912
13936
  emit: (event, transfer) => deps.emit(event, transfer),
13937
+ // The mirror is the balance the wallet renders; refresh it as the drain runs
13938
+ // so a multi-token receive lands progressively instead of all at the end.
13939
+ refreshView: () => {
13940
+ void view.delta().catch(() => void 0);
13941
+ },
13913
13942
  attention: (transferId, code, detail) => {
13914
13943
  deps.emit(
13915
13944
  "transfer:attention",