@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.
package/dist/index.js CHANGED
@@ -12900,6 +12900,7 @@ var InventoryView = class {
12900
12900
 
12901
12901
  // modules/payments-v2/receive/Receive.ts
12902
12902
  var ACK_BATCH_SIZE = 200;
12903
+ var REFRESH_INTERVAL_MS = 750;
12903
12904
  var POLL_INTERVAL_MS = 3e4;
12904
12905
  var ATTENTION_CLAIM_CONFLICT = "claim:conflict";
12905
12906
  function receivedDedupKey(tokenId, stateHash) {
@@ -12916,6 +12917,7 @@ var Receive = class {
12916
12917
  drainFlight = new SingleFlight();
12917
12918
  pollTimer = null;
12918
12919
  unsubscribeWake = null;
12920
+ lastRefreshAt = 0;
12919
12921
  drainOnce() {
12920
12922
  return this.drainFlight.run(() => this.doDrain());
12921
12923
  }
@@ -12933,8 +12935,28 @@ var Receive = class {
12933
12935
  this.unsubscribeWake?.();
12934
12936
  this.unsubscribeWake = null;
12935
12937
  }
12938
+ /**
12939
+ * Flush what has been accepted, then ask for a mirror refresh — at most once
12940
+ * per REFRESH_INTERVAL_MS.
12941
+ *
12942
+ * The flush is not incidental. A `claimed` ack is what materializes a token
12943
+ * into SERVER inventory, and acks otherwise sit queued until ACK_BATCH_SIZE
12944
+ * (200) — so for any ordinary drain, including the 54-token case this exists
12945
+ * for, refreshing before the flush would query an inventory holding none of
12946
+ * the tokens just accepted, and the balance would still only move at the end.
12947
+ * Ordering is preserved: store() still precedes the ack (§5.7).
12948
+ */
12949
+ async maybeRefresh(deps, pending, epochOf) {
12950
+ if (deps.refreshView === void 0) return;
12951
+ const now = deps.now?.() ?? Date.now();
12952
+ if (now - this.lastRefreshAt < REFRESH_INTERVAL_MS) return;
12953
+ this.lastRefreshAt = now;
12954
+ await flushAcks(deps, pending, epochOf);
12955
+ deps.refreshView();
12956
+ }
12936
12957
  async doDrain() {
12937
12958
  const deps = this.deps;
12959
+ this.lastRefreshAt = deps.now?.() ?? Date.now();
12938
12960
  const engine = deps.engine();
12939
12961
  const stored = [];
12940
12962
  const pending = [];
@@ -12944,8 +12966,10 @@ var Receive = class {
12944
12966
  let basis = record !== null && record.syncEpoch === deps.syncEpoch() ? record : null;
12945
12967
  for (let pass = 0; pass < 2; pass++) {
12946
12968
  for await (const entry of deps.delivery.incoming(basis === null ? void 0 : String(basis.cursor))) {
12969
+ const storedBefore = stored.length;
12947
12970
  await this.processEntry(deps, engine, entry, pending, stored);
12948
12971
  if (pending.length >= ACK_BATCH_SIZE) await flushAcks(deps, pending, pageEpoch);
12972
+ if (stored.length > storedBefore) await this.maybeRefresh(deps, pending, pageEpoch);
12949
12973
  }
12950
12974
  await flushAcks(deps, pending, pageEpoch);
12951
12975
  const served = deps.delivery.incomingEpoch();
@@ -13845,7 +13869,7 @@ function composeFacadeParts(deps, hooks) {
13845
13869
  machineDeps,
13846
13870
  machine: new TransferMachine(machineDeps),
13847
13871
  heldStates,
13848
- receiveLoop: buildReceive(deps, hooks, historyStore, heldStates),
13872
+ receiveLoop: buildReceive(deps, hooks, historyStore, heldStates, view),
13849
13873
  requests: buildRequests(deps, hooks),
13850
13874
  restoreDeps: buildRestoreDeps(deps, machineDeps, machineStores, view)
13851
13875
  };
@@ -13912,7 +13936,7 @@ function buildMachineDeps(deps, hooks, historyStore) {
13912
13936
  }
13913
13937
  };
13914
13938
  }
13915
- function buildReceive(deps, hooks, historyStore, heldStates) {
13939
+ function buildReceive(deps, hooks, historyStore, heldStates, view) {
13916
13940
  return new Receive({
13917
13941
  delivery: deps.deliveryPort,
13918
13942
  engine: () => hooks.engine(),
@@ -13926,6 +13950,11 @@ function buildReceive(deps, hooks, historyStore, heldStates) {
13926
13950
  registry: deps.registry,
13927
13951
  recordReceived: (record) => recordReceived(historyStore, record),
13928
13952
  emit: (event, transfer) => deps.emit(event, transfer),
13953
+ // The mirror is the balance the wallet renders; refresh it as the drain runs
13954
+ // so a multi-token receive lands progressively instead of all at the end.
13955
+ refreshView: () => {
13956
+ void view.delta().catch(() => void 0);
13957
+ },
13929
13958
  attention: (transferId, code, detail) => {
13930
13959
  deps.emit(
13931
13960
  "transfer:attention",