Skip to content

fix(token-input): display correct USD value for selected balance#463

Merged
gabitoesmiapodo merged 5 commits into
developfrom
fix/393
Apr 21, 2026
Merged

fix(token-input): display correct USD value for selected balance#463
gabitoesmiapodo merged 5 commits into
developfrom
fix/393

Conversation

@gabitoesmiapodo
Copy link
Copy Markdown
Collaborator

@gabitoesmiapodo gabitoesmiapodo commented Apr 21, 2026

Summary

Closes #393

The Token Input approximate USD field always rendered ~$0.00 regardless of the selected token or wallet balance. Three defects fed into the same symptom: the estimate was computed from the typed input amount (zero at mount), the initial token carried no priceUSD extension, and the subsequent lookup against tokensByChainId compared addresses with strict equality against differently-cased entries.

Changes

  • Compute estimatedUSDValue from priceUSD × balance instead of priceUSD × amount, so a price appears as soon as the balance resolves
  • Source priceUSD from useTokens({ chainId, withBalance: true }) inside useTokenInput, covering single-token mode where the initial token carries no extensions
  • Expose priceUSD and isLoadingPrice from the hook and render a spinner in the USD slot while either price or balance is loading
  • Compare token addresses case-insensitively when resolving priceUSD from tokensByChainId, so checksum-cased list entries match the lowercased selection
  • Remove the now-redundant testnet guard and as number cast from the render branch
  • Update the TokenInput demo hook mock and add unit tests for the new hook return values

Acceptance criteria

  • Approximate USD value reflects the connected wallet's balance on Mainnet ETH, Polygon POL, Polygon USDC, and OP ETH
  • USD value updates as soon as a token is selected, without requiring input or pressing MAX
  • Testnet chains continue to render the No price data label

Test plan

Automated tests

  • pnpm test src/components/sharedComponents/TokenInput/useTokenInput.test.ts
  • pnpm test src/components/pageComponents/home/Examples/demos/TokenInput/index.test.tsx

Manual verification

  1. pnpm dev
  2. Open the Token Input demo and switch to Multi token mode
  3. Connect a wallet with balance on Mainnet ETH, Polygon POL/USDC, and OP ETH
  4. Confirm the ~$ slot shows a spinner while loading, then a non-zero figure equal to balance × price
  5. Switch to a testnet chain and confirm the No price data label is shown

Breaking changes

None.

Checklist

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

Screenshots

Screen.Recording.2026-04-20.at.23.41.57.mov

…ading

Compute the estimated USD field from price × balance instead of
price × amount, so selecting a token immediately shows its USD worth
without requiring user input or pressing MAX.

Add useTokens call inside useTokenInput to fetch prices for the
selected token chain, fixing single-token mode where the initial token
carries no priceUSD. Expose priceUSD and isLoadingPrice from the hook.

Show a spinner in the USD slot while price or balance is loading.

Closes #393
Copilot AI review requested due to automatic review settings April 21, 2026 02:12
@gabitoesmiapodo gabitoesmiapodo self-assigned this Apr 21, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 21, 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 21, 2026 2:34am
demo.dappbooster Ready Ready Preview, Comment Apr 21, 2026 2:34am
docs.dappbooster Ready Ready Preview, Comment Apr 21, 2026 2:34am

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 the TokenInput “~$0.00” USD estimate by sourcing a token’s priceUSD reliably and computing the estimate from the connected wallet’s balance (instead of the typed amount), with loading feedback in the UI.

Changes:

  • Extend useTokenInput to derive priceUSD (case-insensitive address match) and expose isLoadingPrice.
  • Update TokenInput to compute estimatedUSDValue from priceUSD × balance and show a spinner while price/balance is loading.
  • Update demo mocks and add/extend unit tests for the hook’s new return values.

Reviewed changes

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

File Description
src/components/sharedComponents/TokenInput/useTokenInput.tsx Adds useTokens integration to resolve priceUSD + loading state and exposes them from the hook.
src/components/sharedComponents/TokenInput/useTokenInput.test.ts Adds tests validating priceUSD and isLoadingPrice behavior and token switching.
src/components/sharedComponents/TokenInput/index.tsx Switches USD estimation to be balance-based and adds spinner rendering while loading.
src/components/pageComponents/home/Examples/demos/TokenInput/index.test.tsx Updates hook mock shape to include new fields.

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

Comment thread src/components/sharedComponents/TokenInput/useTokenInput.tsx
Comment thread src/components/sharedComponents/TokenInput/useTokenInput.tsx Outdated
Comment thread src/components/sharedComponents/TokenInput/useTokenInput.tsx
Decouple price loading from combined isLoadingBalances so consumers
that only need to know when price data is ready (TokenInput's USD
display) are not kept in a loading state by unrelated balance queries.
isLoadingBalances retains its current union semantics; TokenSelect
consumers are unaffected.
Add missing @returns entries to useTokenInput JSDoc so consumers can
discover the USD price value and its loading state.
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 - approximate USD value always displays ~$0.00

2 participants