@partylayer/sdk 0.10.2 → 0.11.0

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.mjs CHANGED
@@ -585,6 +585,7 @@ function createTelemetryAdapter(config) {
585
585
  return config;
586
586
  }
587
587
  var SESSION_STORAGE_KEY = "active_session";
588
+ var WALLETS_CHANGED_DEBOUNCE_MS = 50;
588
589
  var PartyLayerClient = class {
589
590
  config;
590
591
  adapters = /* @__PURE__ */ new Map();
@@ -611,6 +612,8 @@ var PartyLayerClient = class {
611
612
  // torn down in destroy(). Empty → listWallets() output is byte-identical.
612
613
  announceRegistry = /* @__PURE__ */ new Map();
613
614
  announceUnsubscribe = null;
615
+ /** Pending debounced `wallets:changed` emit (coalesces an announce burst). */
616
+ walletsChangedTimer = null;
614
617
  origin;
615
618
  constructor(config) {
616
619
  this.config = config;
@@ -654,7 +657,7 @@ var PartyLayerClient = class {
654
657
  this.updateRegistryStatus();
655
658
  if (this.announceEnabled) {
656
659
  this.announceUnsubscribe = subscribeAnnouncedProviders(
657
- (p) => this.announceRegistry.set(p.id, p),
660
+ (p) => this.onAnnounceAccumulated(p),
658
661
  { createProvider: (a) => createExtensionChannelProvider({ target: a.target ?? a.id }) }
659
662
  );
660
663
  }
@@ -801,6 +804,30 @@ var PartyLayerClient = class {
801
804
  refreshDiscovery() {
802
805
  this.announceEntriesCache = null;
803
806
  }
807
+ /**
808
+ * Persistent-accumulator callback (mounted at construction). On each newly
809
+ * announced provider:
810
+ * 1. record it in the live `announceRegistry` (unchanged);
811
+ * 2. invalidate the one-shot `announceEntriesCache` — the SAME invalidation
812
+ * as {@link refreshDiscovery}, so the next `listWallets()` re-aggregates
813
+ * and surfaces the wallet. This does NOT touch `warmPlans` (those hold
814
+ * only GenericDiscoveryAdapter popup plans — a disjoint set);
815
+ * 3. emit a DEBOUNCED `wallets:changed` signal so a reactive consumer (e.g.
816
+ * the React provider) re-lists. The debounce coalesces a burst — and the
817
+ * construction-time reply storm — into one emit (no re-discovery storm).
818
+ *
819
+ * Byte-identical idle: with zero announces this never fires — no invalidation,
820
+ * no emit, no re-list.
821
+ */
822
+ onAnnounceAccumulated(p) {
823
+ this.announceRegistry.set(p.id, p);
824
+ this.announceEntriesCache = null;
825
+ if (this.walletsChangedTimer !== null) return;
826
+ this.walletsChangedTimer = setTimeout(() => {
827
+ this.walletsChangedTimer = null;
828
+ this.emit("wallets:changed", { type: "wallets:changed", reason: "announced" });
829
+ }, WALLETS_CHANGED_DEBOUNCE_MS);
830
+ }
804
831
  /**
805
832
  * Aggregate `canton:announceProvider` wallets into the picker list (A2).
806
833
  *
@@ -1341,6 +1368,10 @@ var PartyLayerClient = class {
1341
1368
  this.announceUnsubscribe?.();
1342
1369
  this.announceUnsubscribe = null;
1343
1370
  this.announceRegistry.clear();
1371
+ if (this.walletsChangedTimer !== null) {
1372
+ clearTimeout(this.walletsChangedTimer);
1373
+ this.walletsChangedTimer = null;
1374
+ }
1344
1375
  this.eventHandlers.clear();
1345
1376
  this.activeSession = null;
1346
1377
  }