Skip to content

fix(token-input): format max value with thousand separators#450

Merged
gabitoesmiapodo merged 8 commits intodevelopfrom
fix/295
Apr 10, 2026
Merged

fix(token-input): format max value with thousand separators#450
gabitoesmiapodo merged 8 commits intodevelopfrom
fix/295

Conversation

@gabitoesmiapodo
Copy link
Copy Markdown
Collaborator

Summary

Closes #295

When clicking the Max button in TokenInput, the value bypassed NumericFormat's formatting
pipeline because BigNumberInput's inputRef was not connected to the NumericFormat
instance. A displayValue state now provides a controlled value string so NumericFormat
applies thousand separators on external value changes (max click, token change) as it does
during typing.

Changes

  • Add displayValue state to BigNumberInput with render-time sync from the value prop;
    maps 0n to '' to preserve the placeholder
  • Update updateValue to set prevValueRef before onChange so user-typed intermediate
    strings (trailing dots, trailing zeros) are not overwritten by the sync
  • Pass value: displayValue through renderInputProps so NumericFormat operates in
    controlled mode
  • Clear amountError in handleSetMax to dismiss any prior validation error on max click
  • Add 4 tests: empty placeholder on 0n, thousand-separator formatting on external value
    change, reset to placeholder, user-typed "0" preserved

Acceptance criteria

  • Clicking Max fills the input with the value formatted with thousand separators
  • Normal typing and validation continue to work as before
  • Placeholder shows when no amount is entered (0n)

Test plan

Automated tests

Modified: src/components/sharedComponents/BigNumberInput.test.tsx

pnpm test src/components/sharedComponents/BigNumberInput.test.tsx

Manual verification

  1. Open the token input demo
  2. Connect a wallet with a token balance > 999
  3. Click "Max" — value should appear with thousand separators (e.g. 1,234.56)
  4. Type a value manually — formatting and validation should work as before
  5. Clear the input — placeholder 0.00 should reappear

Breaking changes

None.

Screenshots

None.

Checklist

  • Self-reviewed my own diff
  • Tests added or updated
  • Docs updated (if applicable)
  • No unrelated changes bundled in

When clicking Max, the value bypassed NumericFormat's formatting
pipeline because BigNumberInput's inputRef was not connected to
NumericFormat. The display updated via direct DOM manipulation which
NumericFormat never observed.

Add a displayValue state to BigNumberInput driven by a render-time
sync that fires when the value or decimals props change externally.
This gives NumericFormat a controlled value prop so thousand
separators are applied on max click as they are during typing.

Also clear amountError on max click since the max value is by
definition within the valid range.

Closes #295
Copilot AI review requested due to automatic review settings April 9, 2026 20:43
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 9, 2026

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

Project Deployment Actions Updated (UTC)
components.dappbooster Ready Ready Preview, Comment Apr 9, 2026 9:29pm
demo.dappbooster Ready Ready Preview, Comment Apr 9, 2026 9:29pm
docs.dappbooster Ready Ready Preview, Comment Apr 9, 2026 9:29pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes TokenInput “Max” behavior so externally set values (e.g., max click / token change) flow through NumericFormat and get thousand separators, matching formatting applied during typing.

Changes:

  • Introduces a controlled displayValue string in BigNumberInput for the renderInput path so NumericFormat formats external updates.
  • Clears amountError on “Max” click to dismiss stale validation errors.
  • Adds tests covering placeholder behavior for 0n and thousand-separator formatting on external value changes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/components/sharedComponents/TokenInput/index.tsx Clears prior amount error on Max click before setting amount.
src/components/sharedComponents/BigNumberInput.tsx Adds displayValue state and sync logic; passes controlled value into renderInput.
src/components/sharedComponents/BigNumberInput.test.tsx Adds NumericFormat integration tests for formatting and placeholder behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gabitoesmiapodo gabitoesmiapodo requested a review from Copilot April 9, 2026 20:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Guard setDisplayValue calls behind renderInput check to avoid
unnecessary state updates when the native input path is active.
Add test for decimals change (token switch) to cover the render-time
sync path that was previously untested.
@gabitoesmiapodo gabitoesmiapodo merged commit 724469b into develop Apr 10, 2026
8 checks passed
@gabitoesmiapodo gabitoesmiapodo deleted the fix/295 branch April 10, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Token input "max" value not validated nor formatted

2 participants