Skip to content

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

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)#225
jiangyj545 wants to merge 1 commit into
capofficial:mainfrom
jiangyj545:fix/pool-metrics-issue6

Conversation

@jiangyj545
Copy link
Copy Markdown

Problem

Issue #6 reports that pool performance metrics show incorrect or nonsensical numbers.

Root Cause Analysis

Three categories of bugs in src/components/pool/Pools.svelte:

  1. Division by zero in feeAPY: setFeeAPYs() divides by _balances[asset] without checking if the value is > 0. When balance is 0, undefined, or not yet loaded → Infinity or NaN displayed as APY %.

  2. No null-safety on store values: $globalUPLs[asset], $bufferBalances[asset], $poolStakes[asset] are rendered directly via numberWithCommas(). Before stores populate (or for missing assets) these are undefined → displays raw "undefined" or misleading "0".

  3. Loose equality in % of Pool: Uses == 0 instead of > 0 check, meaning falsy values slip through.

Fix

  • Added > 0 guard in setFeeAPYs() — only calculates APY when balance is positive
  • Added safeMetric() helper — returns "-" for undefined/null/NaN/Infinity values
  • Applied safeMetric() to all 6 metric cells: Balance, Fee APY, Trader UP/L, Buffer, Your Balance
  • Changed % of Pool from == 0 to > 0 strict check

Changes

File Change
src/components/pool/Pools.svelte +16/-10: null-safety guards + safeMetric helper

Build

npx rollup -c passes cleanly (only pre-existing warnings)

…apofficial#6)

- Add > 0 check in feeAPY calculation to prevent division by zero
- Add safeMetric() helper for null-safe metric display
- Show '-' instead of NaN/Infinity/undefined in all pool metric cells
- Use strict equality (> 0 instead of == 0) for % of Pool calculation
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