Skip to content

Format balance and est. cost values in trading widget#791

Merged
realproject7 merged 2 commits intomainfrom
task/789-trading-format
Apr 3, 2026
Merged

Format balance and est. cost values in trading widget#791
realproject7 merged 2 commits intomainfrom
task/789-trading-format

Conversation

@realproject7
Copy link
Copy Markdown
Owner

Summary

  • Adds formatTokenAmount() helper to TradingWidget.tsx with tiered precision:
    • Values >= 1: 2 decimal places with thousands separators (e.g. 5,034.43)
    • Values >= 0.001: 4 decimal places (e.g. 0.0033)
    • Values < 0.001: 6 decimal places (e.g. 0.000001)
  • Applied to all balance displays (2 locations) and estimate cost/return values (2 locations)
  • Works across all pay token modes (ETH, USDC, HUNT, PLOT)

Before/After

  • Balance: 5034.425044895956140455 HUNT5,034.43 HUNT
  • Est. cost: 68.623631443223832041 HUNT68.62 HUNT

Test Plan

  • Verify balance formatting in buy tab (ETH, USDC, HUNT, PLOT modes)
  • Verify balance formatting in sell tab
  • Verify est. cost formatting for Zap buys
  • Verify max cost / min return formatting for PLOT direct trades
  • Verify small values (< 0.001) display correctly

Fixes #789

🤖 Generated with Claude Code

Add formatTokenAmount() helper with precision rules:
- >= 1: 2 decimals with thousands separators (e.g. 5,034.43)
- >= 0.001: 4 decimals (e.g. 0.0033)
- < 0.001: 6 decimals (e.g. 0.000001)

Applied to all balance displays and estimate cost/return values
across ETH, USDC, HUNT, and PLOT modes.

Fixes #789

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 3, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
plotlink Ignored Ignored Apr 3, 2026 8:13am

Request Review

Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: REQUEST CHANGES

Summary

The helper improves readability for normal values, but it still misformats one class of numbers: tiny non-zero amounts can now render as zero. That is a user-visible correctness issue for balances and estimates.

Findings

  • [medium] formatTokenAmount() rounds every value below 0.001 with toFixed(6). For any non-zero amount smaller than 0.0000005, that returns 0.000000, so the widget shows a real balance / estimate as zero instead of a tiny positive value. The issue explicitly allowed scientific notation here, and the repo already uses toExponential(0) for very small values in lib/format.ts:12.
    • File: src/components/TradingWidget.tsx:31
    • Suggestion: switch the smallest range to scientific notation (or another non-zero-preserving representation) instead of fixed 6dp once the value falls below the precision floor.

Decision

Requesting changes because the new formatter can misstate tiny non-zero token amounts as zero.

Values below 0.000001 now use toExponential(2) instead of toFixed(6)
to prevent rendering as "0.000000". Consistent with existing
toExponential usage in lib/format.ts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE

Summary

The formatter now preserves tiny non-zero values instead of collapsing them to zero, while still improving readability for the normal balance and estimate cases. I do not have further review findings on this PR.

Findings

  • None.

Decision

Approved on code review.

@realproject7 realproject7 merged commit 443ce07 into main Apr 3, 2026
5 checks passed
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.

[Bug] Trading widget: unformatted balance and est. cost values

2 participants