@ecency/wallets 1.4.11 → 1.4.12

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.
@@ -2387,26 +2387,73 @@ var PointTransactionType = /* @__PURE__ */ ((PointTransactionType2) => {
2387
2387
  PointTransactionType2[PointTransactionType2["MINTED"] = 991] = "MINTED";
2388
2388
  return PointTransactionType2;
2389
2389
  })(PointTransactionType || {});
2390
- function getAllTokensListQueryOptions(query) {
2390
+ function createFallbackTokenMetadata(symbol) {
2391
+ return {
2392
+ issuer: "",
2393
+ symbol,
2394
+ name: symbol,
2395
+ metadata: "{}",
2396
+ precision: 0,
2397
+ maxSupply: "0",
2398
+ supply: "0",
2399
+ circulatingSupply: "0",
2400
+ stakingEnabled: false,
2401
+ unstakingCooldown: 0,
2402
+ delegationEnabled: false,
2403
+ undelegationCooldown: 0,
2404
+ numberTransactions: 0,
2405
+ totalStaked: "0"
2406
+ };
2407
+ }
2408
+ async function getLayer2TokensMetadata(username) {
2409
+ if (!username) {
2410
+ return [];
2411
+ }
2412
+ let balances = [];
2413
+ try {
2414
+ balances = await sdk.getQueryClient().fetchQuery(
2415
+ getHiveEngineTokensBalancesQueryOptions(username)
2416
+ );
2417
+ } catch {
2418
+ balances = [];
2419
+ }
2420
+ const uniqueSymbols = Array.from(
2421
+ new Set(
2422
+ balances.map((balance) => balance.symbol).filter((symbol) => Boolean(symbol))
2423
+ )
2424
+ );
2425
+ if (uniqueSymbols.length === 0) {
2426
+ return [];
2427
+ }
2428
+ let metadataList = [];
2429
+ try {
2430
+ metadataList = await sdk.getQueryClient().fetchQuery(
2431
+ getHiveEngineTokensMetadataQueryOptions(uniqueSymbols)
2432
+ );
2433
+ } catch {
2434
+ metadataList = [];
2435
+ }
2436
+ const metadataBySymbol = new Map(
2437
+ metadataList.map((token) => [token.symbol, token])
2438
+ );
2439
+ return uniqueSymbols.map(
2440
+ (symbol) => metadataBySymbol.get(symbol) ?? createFallbackTokenMetadata(symbol)
2441
+ );
2442
+ }
2443
+ function getAllTokensListQueryOptions(username) {
2391
2444
  return reactQuery.queryOptions({
2392
- queryKey: ["ecency-wallets", "all-tokens-list", query],
2445
+ queryKey: ["ecency-wallets", "all-tokens-list", username ?? null],
2393
2446
  queryFn: async () => {
2394
- await sdk.getQueryClient().prefetchQuery(
2395
- getHiveEngineTokensMetadataQueryOptions(HiveEngineTokens)
2396
- );
2397
- const metadataList = sdk.getQueryClient().getQueryData(getHiveEngineTokensMetadataQueryOptions(HiveEngineTokens).queryKey);
2398
2447
  return {
2399
2448
  basic: [
2400
2449
  "POINTS" /* Points */,
2401
2450
  "HIVE" /* Hive */,
2402
2451
  "HP" /* HivePower */,
2403
2452
  "HBD" /* HiveDollar */
2404
- ].filter((token) => token.toLowerCase().includes(query.toLowerCase())),
2405
- external: Object.values(EcencyWalletCurrency).filter(
2406
- (token) => token.toLowerCase().includes(query.toLowerCase())
2407
- ),
2453
+ ],
2454
+ external: Object.values(EcencyWalletCurrency),
2408
2455
  spk: ["SPK" /* Spk */, "LARYNX", "LP"],
2409
- layer2: metadataList
2456
+ layer2: await getLayer2TokensMetadata(username)
2410
2457
  };
2411
2458
  }
2412
2459
  });