@unicitylabs/sphere-sdk 0.1.6 → 0.1.8

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.
@@ -324,6 +324,15 @@ interface TokenBalance {
324
324
  readonly tokenCount: number;
325
325
  readonly decimals: number;
326
326
  }
327
+ interface Asset {
328
+ readonly coinId: string;
329
+ readonly symbol: string;
330
+ readonly name: string;
331
+ readonly decimals: number;
332
+ readonly iconUrl?: string;
333
+ readonly totalAmount: string;
334
+ readonly tokenCount: number;
335
+ }
327
336
  type TransferStatus = 'pending' | 'submitted' | 'confirmed' | 'delivered' | 'completed' | 'failed';
328
337
  interface TransferRequest {
329
338
  readonly coinId: string;
@@ -1468,6 +1477,11 @@ declare class PaymentsModule {
1468
1477
  * Get balance for coin type
1469
1478
  */
1470
1479
  getBalance(coinId?: string): TokenBalance[];
1480
+ /**
1481
+ * Get aggregated assets (tokens grouped by coinId)
1482
+ * Only includes confirmed tokens
1483
+ */
1484
+ getAssets(coinId?: string): Asset[];
1471
1485
  /**
1472
1486
  * Get all tokens
1473
1487
  */
@@ -324,6 +324,15 @@ interface TokenBalance {
324
324
  readonly tokenCount: number;
325
325
  readonly decimals: number;
326
326
  }
327
+ interface Asset {
328
+ readonly coinId: string;
329
+ readonly symbol: string;
330
+ readonly name: string;
331
+ readonly decimals: number;
332
+ readonly iconUrl?: string;
333
+ readonly totalAmount: string;
334
+ readonly tokenCount: number;
335
+ }
327
336
  type TransferStatus = 'pending' | 'submitted' | 'confirmed' | 'delivered' | 'completed' | 'failed';
328
337
  interface TransferRequest {
329
338
  readonly coinId: string;
@@ -1468,6 +1477,11 @@ declare class PaymentsModule {
1468
1477
  * Get balance for coin type
1469
1478
  */
1470
1479
  getBalance(coinId?: string): TokenBalance[];
1480
+ /**
1481
+ * Get aggregated assets (tokens grouped by coinId)
1482
+ * Only includes confirmed tokens
1483
+ */
1484
+ getAssets(coinId?: string): Asset[];
1471
1485
  /**
1472
1486
  * Get all tokens
1473
1487
  */
@@ -2217,7 +2217,7 @@ var LIMITS = {
2217
2217
  };
2218
2218
 
2219
2219
  // types/txf.ts
2220
- var ARCHIVED_PREFIX = "_archived_";
2220
+ var ARCHIVED_PREFIX = "archived-";
2221
2221
  var FORKED_PREFIX = "_forked_";
2222
2222
  var RESERVED_KEYS = ["_meta", "_nametag", "_tombstones", "_invalidatedNametags", "_outbox", "_mintOutbox", "_sent", "_invalid", "_integrity"];
2223
2223
  function isTokenKey(key) {
@@ -3166,16 +3166,14 @@ var PaymentsModule = class {
3166
3166
  const result = await provider.load();
3167
3167
  if (result.success && result.data) {
3168
3168
  this.loadFromStorageData(result.data);
3169
- this.log(`Loaded from provider ${id}: ${this.tokens.size} tokens`);
3169
+ this.log(`Loaded metadata from provider ${id}`);
3170
3170
  break;
3171
3171
  }
3172
3172
  } catch (err) {
3173
3173
  console.error(`[Payments] Failed to load from provider ${id}:`, err);
3174
3174
  }
3175
3175
  }
3176
- if (this.tokens.size === 0) {
3177
- await this.loadTokensFromFileStorage();
3178
- }
3176
+ await this.loadTokensFromFileStorage();
3179
3177
  await this.loadNametagFromFileStorage();
3180
3178
  const historyData = await this.deps.storage.get(STORAGE_KEYS_ADDRESS.TRANSACTION_HISTORY);
3181
3179
  if (historyData) {
@@ -3720,6 +3718,34 @@ var PaymentsModule = class {
3720
3718
  }
3721
3719
  return Array.from(balances.values());
3722
3720
  }
3721
+ /**
3722
+ * Get aggregated assets (tokens grouped by coinId)
3723
+ * Only includes confirmed tokens
3724
+ */
3725
+ getAssets(coinId) {
3726
+ const assets = /* @__PURE__ */ new Map();
3727
+ for (const token of this.tokens.values()) {
3728
+ if (token.status !== "confirmed") continue;
3729
+ if (coinId && token.coinId !== coinId) continue;
3730
+ const key = token.coinId;
3731
+ const existing = assets.get(key);
3732
+ if (existing) {
3733
+ existing.totalAmount = (BigInt(existing.totalAmount) + BigInt(token.amount)).toString();
3734
+ existing.tokenCount++;
3735
+ } else {
3736
+ assets.set(key, {
3737
+ coinId: token.coinId,
3738
+ symbol: token.symbol,
3739
+ name: token.name,
3740
+ decimals: token.decimals,
3741
+ iconUrl: token.iconUrl,
3742
+ totalAmount: token.amount,
3743
+ tokenCount: 1
3744
+ });
3745
+ }
3746
+ }
3747
+ return Array.from(assets.values());
3748
+ }
3723
3749
  /**
3724
3750
  * Get all tokens
3725
3751
  */
@@ -3813,7 +3839,8 @@ var PaymentsModule = class {
3813
3839
  for (const [providerId, provider] of providers) {
3814
3840
  if (!provider.listTokenIds || !provider.getToken) continue;
3815
3841
  try {
3816
- const tokenIds = await provider.listTokenIds();
3842
+ const allIds = await provider.listTokenIds();
3843
+ const tokenIds = allIds.filter((id) => id.startsWith("token-"));
3817
3844
  this.log(`Found ${tokenIds.length} token files in ${providerId}`);
3818
3845
  for (const tokenId of tokenIds) {
3819
3846
  try {
@@ -3864,9 +3891,7 @@ var PaymentsModule = class {
3864
3891
  console.warn(`[Payments] Failed to load tokens from ${providerId}:`, error);
3865
3892
  }
3866
3893
  }
3867
- if (this.tokens.size > 0) {
3868
- await this.save();
3869
- }
3894
+ this.log(`Loaded ${this.tokens.size} tokens from file storage`);
3870
3895
  }
3871
3896
  /**
3872
3897
  * Update an existing token
@@ -4727,9 +4752,9 @@ var PaymentsModule = class {
4727
4752
  return data ? JSON.parse(data) : [];
4728
4753
  }
4729
4754
  async createStorageData() {
4730
- const tokens = Array.from(this.tokens.values());
4731
4755
  return await buildTxfStorageData(
4732
- tokens,
4756
+ [],
4757
+ // Empty - active tokens stored as token-xxx files
4733
4758
  {
4734
4759
  version: 1,
4735
4760
  address: this.deps.identity.l1Address,