Skip to content

fix: clamp decimals in format utils to prevent RangeError crash - #113

Merged
stackdapp-dev merged 1 commit into
developfrom
claude/fix-format-amount-range-error
Mar 16, 2026
Merged

stackdapp-dev merged 1 commit into
developfrom
claude/fix-format-amount-range-error

Conversation

@stackdapp-dev

Copy link
Copy Markdown
Owner

Summary

  • Root cause: formatAmount(value, 0) set minimumFractionDigits: 2 but maximumFractionDigits: 0, causing toLocaleString to throw RangeError: maximumFractionDigits value is out of range
  • This crashed the entire React tree when tapping "Simulate" on /wallet (LoanSimulator line 727: formatAmount(effectiveCollateralPrice, 0))
  • Fixed by clamping minimumFractionDigits to not exceed maximumFractionDigits in formatAmount, and clamping negative decimals in formatCurrency and formatPercent

Test plan

  • Added 6 new unit tests covering decimals=0, decimals=1, and negative decimals for all three functions
  • All 70 utils tests pass
  • Full suite: 1630 tests pass, 0 failures

🤖 Generated with Claude Code

…revent RangeError

When formatAmount was called with decimals=0 (e.g., in LoanSimulator simulate mode),
minimumFractionDigits (hardcoded at 2) exceeded maximumFractionDigits (0), causing
toLocaleString to throw RangeError that crashed the entire React tree.

Also added clamping to formatCurrency and formatPercent for negative decimals values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel

vercel Bot commented Mar 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stackd-web Ready Ready Preview, Comment Mar 16, 2026 1:34pm

@stackdapp-dev
stackdapp-dev merged commit d847641 into develop Mar 16, 2026
3 checks passed

This branch was successfully deployed

1 active deployment
Preview — 3843cef5 Deployed Mar 16, 2026 by vercel[bot]
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.

2 participants