diff --git a/src/components/pool/Pools.svelte b/src/components/pool/Pools.svelte index 2ad0552..2e03740 100644 --- a/src/components/pool/Pools.svelte +++ b/src/components/pool/Pools.svelte @@ -31,12 +31,30 @@ function setFeeAPYs(_balances) { if (!_balances) return; - if (_balances['ETH']) feeAPY['ETH'] = 100 * 95 * 12 / _balances['ETH']; // Approx 95 ETH per month in fees - if (_balances['USDC']) feeAPY['USDC'] = 100 * 100000 * 12 / _balances['USDC']; // Approx 100,000 USDC per month in fees + // Approx 95 ETH per month in fees — guard against zero/negative balances + if (_balances['ETH'] && _balances['ETH'] > 0) { + feeAPY['ETH'] = 100 * 95 * 12 / _balances['ETH']; + } else { + feeAPY['ETH'] = null; + } + // Approx 100,000 USDC per month in fees + if (_balances['USDC'] && _balances['USDC'] > 0) { + feeAPY['USDC'] = 100 * 100000 * 12 / _balances['USDC']; + } else { + feeAPY['USDC'] = null; + } } $: setFeeAPYs($poolBalances); + /** Safely format a metric value, returning fallback for NaN/Infinity/null/undefined */ + function safeMetric(val, fallback = '-') { + if (val === null || val === undefined) return fallback; + const n = Number(val); + if (!isFinite(n)) return fallback; // catches both NaN and Infinity + return formatForDisplay(n); + } +