@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.
@@ -3153,6 +3153,7 @@ var logger = {
3153
3153
 
3154
3154
  // modules/payments-v2/receive/Receive.ts
3155
3155
  var ACK_BATCH_SIZE = 200;
3156
+ var REFRESH_INTERVAL_MS = 750;
3156
3157
  var POLL_INTERVAL_MS = 3e4;
3157
3158
  var ATTENTION_CLAIM_CONFLICT = "claim:conflict";
3158
3159
  function receivedDedupKey(tokenId, stateHash) {
@@ -3169,6 +3170,7 @@ var Receive = class {
3169
3170
  drainFlight = new SingleFlight();
3170
3171
  pollTimer = null;
3171
3172
  unsubscribeWake = null;
3173
+ lastRefreshAt = 0;
3172
3174
  drainOnce() {
3173
3175
  return this.drainFlight.run(() => this.doDrain());
3174
3176
  }
@@ -3186,8 +3188,28 @@ var Receive = class {
3186
3188
  this.unsubscribeWake?.();
3187
3189
  this.unsubscribeWake = null;
3188
3190
  }
3191
+ /**
3192
+ * Flush what has been accepted, then ask for a mirror refresh — at most once
3193
+ * per REFRESH_INTERVAL_MS.
3194
+ *
3195
+ * The flush is not incidental. A `claimed` ack is what materializes a token
3196
+ * into SERVER inventory, and acks otherwise sit queued until ACK_BATCH_SIZE
3197
+ * (200) — so for any ordinary drain, including the 54-token case this exists
3198
+ * for, refreshing before the flush would query an inventory holding none of
3199
+ * the tokens just accepted, and the balance would still only move at the end.
3200
+ * Ordering is preserved: store() still precedes the ack (§5.7).
3201
+ */
3202
+ async maybeRefresh(deps, pending, epochOf) {
3203
+ if (deps.refreshView === void 0) return;
3204
+ const now = deps.now?.() ?? Date.now();
3205
+ if (now - this.lastRefreshAt < REFRESH_INTERVAL_MS) return;
3206
+ this.lastRefreshAt = now;
3207
+ await flushAcks(deps, pending, epochOf);
3208
+ deps.refreshView();
3209
+ }
3189
3210
  async doDrain() {
3190
3211
  const deps = this.deps;
3212
+ this.lastRefreshAt = deps.now?.() ?? Date.now();
3191
3213
  const engine = deps.engine();
3192
3214
  const stored = [];
3193
3215
  const pending = [];
@@ -3197,8 +3219,10 @@ var Receive = class {
3197
3219
  let basis = record !== null && record.syncEpoch === deps.syncEpoch() ? record : null;
3198
3220
  for (let pass = 0; pass < 2; pass++) {
3199
3221
  for await (const entry of deps.delivery.incoming(basis === null ? void 0 : String(basis.cursor))) {
3222
+ const storedBefore = stored.length;
3200
3223
  await this.processEntry(deps, engine, entry, pending, stored);
3201
3224
  if (pending.length >= ACK_BATCH_SIZE) await flushAcks(deps, pending, pageEpoch);
3225
+ if (stored.length > storedBefore) await this.maybeRefresh(deps, pending, pageEpoch);
3202
3226
  }
3203
3227
  await flushAcks(deps, pending, pageEpoch);
3204
3228
  const served = deps.delivery.incomingEpoch();
@@ -4098,7 +4122,7 @@ function composeFacadeParts(deps, hooks) {
4098
4122
  machineDeps,
4099
4123
  machine: new TransferMachine(machineDeps),
4100
4124
  heldStates,
4101
- receiveLoop: buildReceive(deps, hooks, historyStore, heldStates),
4125
+ receiveLoop: buildReceive(deps, hooks, historyStore, heldStates, view),
4102
4126
  requests: buildRequests(deps, hooks),
4103
4127
  restoreDeps: buildRestoreDeps(deps, machineDeps, machineStores, view)
4104
4128
  };
@@ -4165,7 +4189,7 @@ function buildMachineDeps(deps, hooks, historyStore) {
4165
4189
  }
4166
4190
  };
4167
4191
  }
4168
- function buildReceive(deps, hooks, historyStore, heldStates) {
4192
+ function buildReceive(deps, hooks, historyStore, heldStates, view) {
4169
4193
  return new Receive({
4170
4194
  delivery: deps.deliveryPort,
4171
4195
  engine: () => hooks.engine(),
@@ -4179,6 +4203,11 @@ function buildReceive(deps, hooks, historyStore, heldStates) {
4179
4203
  registry: deps.registry,
4180
4204
  recordReceived: (record) => recordReceived(historyStore, record),
4181
4205
  emit: (event, transfer) => deps.emit(event, transfer),
4206
+ // The mirror is the balance the wallet renders; refresh it as the drain runs
4207
+ // so a multi-token receive lands progressively instead of all at the end.
4208
+ refreshView: () => {
4209
+ void view.delta().catch(() => void 0);
4210
+ },
4182
4211
  attention: (transferId, code, detail) => {
4183
4212
  deps.emit(
4184
4213
  "transfer:attention",