@t2000/engine 0.50.2 → 0.50.3

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.js CHANGED
@@ -530,7 +530,7 @@ async function fetchAddressPortfolio(address, apiKey, fallbackRpcUrl) {
530
530
  return blockvision;
531
531
  }
532
532
  }
533
- const degraded = await fetchPortfolioFromSuiRpc(address, fallbackRpcUrl);
533
+ const degraded = await fetchPortfolioFromSuiRpc(address, apiKey, fallbackRpcUrl);
534
534
  portfolioCache.set(address, { data: degraded, ts: Date.now() });
535
535
  return degraded;
536
536
  } finally {
@@ -599,21 +599,28 @@ async function fetchPortfolioFromBlockVision(address, apiKey) {
599
599
  source: "blockvision"
600
600
  };
601
601
  }
602
- async function fetchPortfolioFromSuiRpc(address, fallbackRpcUrl) {
602
+ async function fetchPortfolioFromSuiRpc(address, apiKey, fallbackRpcUrl) {
603
603
  const walletCoins = await fetchWalletCoins(address, fallbackRpcUrl).catch((err) => {
604
604
  console.warn("[blockvision-prices] sui rpc coin fetch failed:", err);
605
605
  return [];
606
606
  });
607
+ const nonStableCoinTypes = walletCoins.map((c) => c.coinType).filter((coinType) => !(coinType in STABLE_USD_PRICES));
608
+ const livePrices = apiKey && apiKey.trim().length > 0 && nonStableCoinTypes.length > 0 ? await fetchTokenPrices(nonStableCoinTypes, apiKey).catch((err) => {
609
+ console.warn("[blockvision-prices] price-list fallback failed:", err);
610
+ return {};
611
+ }) : {};
607
612
  const coins = walletCoins.map((c) => {
608
613
  const stablePrice = STABLE_USD_PRICES[c.coinType] ?? null;
614
+ const livePrice = livePrices[c.coinType]?.price ?? null;
615
+ const price = stablePrice ?? livePrice;
609
616
  const amount = Number(c.totalBalance) / 10 ** c.decimals;
610
- const usdValue = stablePrice != null && Number.isFinite(amount) ? amount * stablePrice : null;
617
+ const usdValue = price != null && Number.isFinite(amount) ? amount * price : null;
611
618
  return {
612
619
  coinType: c.coinType,
613
620
  symbol: c.symbol,
614
621
  decimals: c.decimals,
615
622
  balance: c.totalBalance,
616
- price: stablePrice,
623
+ price,
617
624
  usdValue
618
625
  };
619
626
  });