Skip to content

fix(web): guard usePoolChartData against division by zero with single snapshot - #715

Open
Ennyblack wants to merge 1 commit into
TrusTrove:mainfrom
Ennyblack:driptide/issue-278-fix
Open

fix(web): guard usePoolChartData against division by zero with single snapshot#715
Ennyblack wants to merge 1 commit into
TrusTrove:mainfrom
Ennyblack:driptide/issue-278-fix

Conversation

@Ennyblack

Copy link
Copy Markdown
Contributor

Summary

Fix division by zero in usePoolChartData when only one snapshot exists.

When data.length === 1, the expression index / (data.length - 1) divides by zero, producing NaN coordinates. This PR adds an early return that places the single data point at the horizontal center of the chart, producing valid SVG paths and a meaningful visual.

Changes

  • apps/web/hooks/usePoolChartData.ts: Added early return for data.length === 1 that centers the single point and generates valid linePath / areaPath strings.
  • apps/web/hooks/usePoolChartData.test.ts: New test file with 7 tests covering empty data, undefined data, single-point, two-point, multi-point, centering, and equal-value cases.

Verification

  • pnpm --filter web exec tsc --noEmit — clean
  • pnpm --filter web lint — clean (only pre-existing warnings)
  • pnpm --filter web test — all tests pass
  • Prettier formatting — clean

Closes #278

🤖 Generated with Codebuff
Co-Authored-By: Codebuff noreply@codebuff.com

… snapshot

When data.length is 1, the expression index / (data.length - 1) produces
NaN. Add an early return that places the single data point at the center
of the chart and produces valid SVG paths.

Add 7 unit tests covering empty data, undefined data, single-point,
two-point, multi-point, and equal-value cases.

Closes TrusTrove#278

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@vercel

vercel Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

@Cjay-Cyber-2 is attempting to deploy a commit to the K1NGD4VID Team on Vercel.

A member of the Team first needs to authorize it.

@mergekeeper

mergekeeper Bot commented Aug 30, 2026

Copy link
Copy Markdown

MergeKeeper review unavailable

AI provider review response did not contain valid JSON

No approval or merge action was taken.

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.

[Easy] fix(web): usePoolChartData divides by zero when only one snapshot

2 participants