From 3a9bdc2236c634dd946f62b394454e3f16da7ad6 Mon Sep 17 00:00:00 2001 From: Hermes Admin Date: Sat, 30 May 2026 06:06:17 +0800 Subject: [PATCH] fix: guard pool metrics against NaN/Infinity/undefined values (fixes #6) - Fee APY: return null instead of dividing by zero when pool balance is 0 or empty - Add safeMetric() helper to gracefully handle NaN, Infinity, null, undefined - % of Pool column: use safeMetric to prevent Infinity display - Shows '-' for invalid metrics instead of nonsensical numbers --- src/components/pool/Pools.svelte | 34 ++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) 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); + } +