Skip to content

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

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

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

Conversation

@jiangyj545
Copy link
Copy Markdown

Summary

Fixes #6 — Pool performance metrics display incorrect or nonsensical numbers (NaN, Infinity, undefined).

Root Cause

In src/components/pool/Pools.svelte, several code paths produce invalid output when pool data is loading or contains edge-case values:

  1. Fee APY calculation (setFeeAPYs): 100 * 95 * 12 / _balances["ETH"] produces Infinity when balance is 0 or undefined
  2. All metric cells: Accessing store values like $poolBalances[asset] returns undefined before data loads → numberWithCommas(undefined) and formatForDisplay(undefined) propagate through
  3. % of Pool: Division by undefined/falsy poolBalance produces NaN

Changes

File: src/components/pool/Pools.svelte

  • Added safe(val, fallback) helper function that guards against null, undefined, NaN, and Infinity
  • Guarded setFeeAPYs() to only calculate when balance > 0 (prevents Infinity)
  • Wrapped all 8 metric display cells with safe() calls:
    • Balance, Fee APY, Trader UP/L, Buffer, Your Balance, % of Pool
  • During isLoading state, metrics show instead of raw invalid values
  • After load completes, missing data gracefully degrades to or 0

Verification

npm install && npx rollup -c   # ✅ Build successful (bundle created)

Compared to Other PRs

PR Approach Coverage
#240 NaN/Infinity guard in template only Partial
#171 Markdown file (not a fix) N/A
This PR safe() helper + feeAPY source guard + all 8 cells + loading state Comprehensive

Bounty

Issue #6 — $50 paid in crypto

…apofficial#6)

- Add safe() helper to sanitize all displayed metric values
- Guard feeAPY calculation against zero/div-by-zero (produces Infinity)
- Show '…' during loading state instead of raw NaN/undefined
- Handle edge case: % of Pool when poolBalance is falsy
- All numeric cells now gracefully degrade to '—' or '0'
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.

Pool metrics are wrong / weird

1 participant