@unicitylabs/sphere-sdk 0.8.0-dev.2 → 0.8.0-dev.4

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.
@@ -29299,6 +29299,19 @@ var TokenRegistry = class _TokenRegistry {
29299
29299
  // ===========================================================================
29300
29300
  // Cache (StorageProvider)
29301
29301
  // ===========================================================================
29302
+ /**
29303
+ * Per-network cache keys. The registry cache MUST be namespaced by remoteUrl:
29304
+ * testnet and testnet2 ship DIFFERENT coinIds for the same symbol, so a single
29305
+ * global key let a stale testnet snapshot be served for a testnet2 request —
29306
+ * wrong/missing icons AND self-mint resolving the wrong-network coinId. Keying
29307
+ * by remoteUrl isolates the snapshots so a network can never read another's.
29308
+ */
29309
+ cacheKeys() {
29310
+ const base = STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE;
29311
+ const baseTs = STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS;
29312
+ if (!this.remoteUrl) return { data: base, ts: baseTs };
29313
+ return { data: `${base}:${this.remoteUrl}`, ts: `${baseTs}:${this.remoteUrl}` };
29314
+ }
29302
29315
  /**
29303
29316
  * Load definitions from StorageProvider cache.
29304
29317
  * Only applies if cache exists and is fresh (within refreshIntervalMs).
@@ -29306,9 +29319,10 @@ var TokenRegistry = class _TokenRegistry {
29306
29319
  async loadFromCache() {
29307
29320
  if (!this.storage) return false;
29308
29321
  try {
29322
+ const { data: dataKey, ts: tsKey } = this.cacheKeys();
29309
29323
  const [cached, cachedTs] = await Promise.all([
29310
- this.storage.get(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE),
29311
- this.storage.get(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS)
29324
+ this.storage.get(dataKey),
29325
+ this.storage.get(tsKey)
29312
29326
  ]);
29313
29327
  if (!cached || !cachedTs) return false;
29314
29328
  const ts = parseInt(cachedTs, 10);
@@ -29331,9 +29345,10 @@ var TokenRegistry = class _TokenRegistry {
29331
29345
  async saveToCache(definitions) {
29332
29346
  if (!this.storage) return;
29333
29347
  try {
29348
+ const { data: dataKey, ts: tsKey } = this.cacheKeys();
29334
29349
  await Promise.all([
29335
- this.storage.set(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE, JSON.stringify(definitions)),
29336
- this.storage.set(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS, String(Date.now()))
29350
+ this.storage.set(dataKey, JSON.stringify(definitions)),
29351
+ this.storage.set(tsKey, String(Date.now()))
29337
29352
  ]);
29338
29353
  } catch {
29339
29354
  }