Skip to content

fix: guard pool metrics against NaN/Infinity/undefined values (fixes #6)#240

Open
jiangyj545 wants to merge 1 commit into
capofficial:mainfrom
jiangyj545:fix/pool-metrics-issue6
Open

fix: guard pool metrics against NaN/Infinity/undefined values (fixes #6)#240
jiangyj545 wants to merge 1 commit into
capofficial:mainfrom
jiangyj545:fix/pool-metrics-issue6

Conversation

@jiangyj545
Copy link
Copy Markdown

Problem

Pool performance metrics display incorrect or nonsensical numbers (Infinity, NaN, or extremely large values) when pool balances are zero, empty, or not yet loaded.

Root Cause

Three issues in src/components/pool/Pools.svelte:

  1. Fee APY calculation divides by pool balance without zero-guard:

    feeAPY["ETH"] = 100 * 95 * 12 / _balances["ETH"] // → Infinity if balance is 0
  2. % of Pool column divides stake by balance without safety check — same Infinity problem.

  3. formatForDisplay() does not handle Infinity (only catches NaN via isNaN()), so Infinity passes through and renders as garbage.

Fix

  • Fee APY: Return null when pool balance is ≤ 0 or falsy, instead of dividing by zero
  • New safeMetric() helper: Catches null, undefined, NaN, and Infinity in one place, returns "-" fallback
  • Fee APY display: Uses safeMetric() — shows "-" when balance is unavailable, otherwise X%
  • % of Pool display: Uses safeMetric() for the division result (existing zero-check kept as first guard)

Changes

File Change
src/components/pool/Pools.svelte +26/-8: guarded division + safeMetric helper

Build

npx rollup -c ✅ (no new warnings; circular deps are pre-existing)

…apofficial#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant