@ecency/wallets 1.4.10 → 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.
@@ -2360,26 +2360,73 @@ var PointTransactionType = /* @__PURE__ */ ((PointTransactionType2) => {
2360
2360
  PointTransactionType2[PointTransactionType2["MINTED"] = 991] = "MINTED";
2361
2361
  return PointTransactionType2;
2362
2362
  })(PointTransactionType || {});
2363
- function getAllTokensListQueryOptions(query) {
2363
+ function createFallbackTokenMetadata(symbol) {
2364
+ return {
2365
+ issuer: "",
2366
+ symbol,
2367
+ name: symbol,
2368
+ metadata: "{}",
2369
+ precision: 0,
2370
+ maxSupply: "0",
2371
+ supply: "0",
2372
+ circulatingSupply: "0",
2373
+ stakingEnabled: false,
2374
+ unstakingCooldown: 0,
2375
+ delegationEnabled: false,
2376
+ undelegationCooldown: 0,
2377
+ numberTransactions: 0,
2378
+ totalStaked: "0"
2379
+ };
2380
+ }
2381
+ async function getLayer2TokensMetadata(username) {
2382
+ if (!username) {
2383
+ return [];
2384
+ }
2385
+ let balances = [];
2386
+ try {
2387
+ balances = await getQueryClient().fetchQuery(
2388
+ getHiveEngineTokensBalancesQueryOptions(username)
2389
+ );
2390
+ } catch {
2391
+ balances = [];
2392
+ }
2393
+ const uniqueSymbols = Array.from(
2394
+ new Set(
2395
+ balances.map((balance) => balance.symbol).filter((symbol) => Boolean(symbol))
2396
+ )
2397
+ );
2398
+ if (uniqueSymbols.length === 0) {
2399
+ return [];
2400
+ }
2401
+ let metadataList = [];
2402
+ try {
2403
+ metadataList = await getQueryClient().fetchQuery(
2404
+ getHiveEngineTokensMetadataQueryOptions(uniqueSymbols)
2405
+ );
2406
+ } catch {
2407
+ metadataList = [];
2408
+ }
2409
+ const metadataBySymbol = new Map(
2410
+ metadataList.map((token) => [token.symbol, token])
2411
+ );
2412
+ return uniqueSymbols.map(
2413
+ (symbol) => metadataBySymbol.get(symbol) ?? createFallbackTokenMetadata(symbol)
2414
+ );
2415
+ }
2416
+ function getAllTokensListQueryOptions(username) {
2364
2417
  return queryOptions({
2365
- queryKey: ["ecency-wallets", "all-tokens-list", query],
2418
+ queryKey: ["ecency-wallets", "all-tokens-list", username ?? null],
2366
2419
  queryFn: async () => {
2367
- await getQueryClient().prefetchQuery(
2368
- getHiveEngineTokensMetadataQueryOptions(HiveEngineTokens)
2369
- );
2370
- const metadataList = getQueryClient().getQueryData(getHiveEngineTokensMetadataQueryOptions(HiveEngineTokens).queryKey);
2371
2420
  return {
2372
2421
  basic: [
2373
2422
  "POINTS" /* Points */,
2374
2423
  "HIVE" /* Hive */,
2375
2424
  "HP" /* HivePower */,
2376
2425
  "HBD" /* HiveDollar */
2377
- ].filter((token) => token.toLowerCase().includes(query.toLowerCase())),
2378
- external: Object.values(EcencyWalletCurrency).filter(
2379
- (token) => token.toLowerCase().includes(query.toLowerCase())
2380
- ),
2426
+ ],
2427
+ external: Object.values(EcencyWalletCurrency),
2381
2428
  spk: ["SPK" /* Spk */, "LARYNX", "LP"],
2382
- layer2: metadataList
2429
+ layer2: await getLayer2TokensMetadata(username)
2383
2430
  };
2384
2431
  }
2385
2432
  });
@@ -3237,7 +3284,7 @@ function useImportWallet(username, currency) {
3237
3284
  }
3238
3285
  });
3239
3286
  }
3240
- function getGroupedChainTokens(tokens, show = false) {
3287
+ function getGroupedChainTokens(tokens, defaultShow) {
3241
3288
  if (!tokens) {
3242
3289
  return {};
3243
3290
  }
@@ -3247,8 +3294,16 @@ function getGroupedChainTokens(tokens, show = false) {
3247
3294
  ({ type, symbol }) => type === "CHAIN" || Object.values(EcencyWalletCurrency).includes(symbol)
3248
3295
  ),
3249
3296
  R.map((item) => {
3250
- item.meta.show = show;
3251
- return item;
3297
+ const meta = {
3298
+ ...item.meta ?? {}
3299
+ };
3300
+ if (typeof meta.show !== "boolean" && typeof defaultShow === "boolean") {
3301
+ meta.show = defaultShow;
3302
+ }
3303
+ return {
3304
+ ...item,
3305
+ meta
3306
+ };
3252
3307
  }),
3253
3308
  // Chain tokens are unique by symbol, so indexing by symbol
3254
3309
  // gives a direct lookup map instead of an array-based grouping.