Skip to content

fix: use dynamic decimals in getDisplayAmount instead of hardcoded USDC 6#1926

Open
natsukingly wants to merge 1 commit intox402-foundation:mainfrom
natsukingly:fix/display-amount-decimals
Open

fix: use dynamic decimals in getDisplayAmount instead of hardcoded USDC 6#1926
natsukingly wants to merge 1 commit intox402-foundation:mainfrom
natsukingly:fix/display-amount-decimals

Conversation

@natsukingly
Copy link
Copy Markdown

Summary

getDisplayAmount in x402HTTPResourceServer hardcodes / 1000000 assuming all assets use 6 decimals (USDC). This breaks display amounts for tokens like WBTC (8 decimals) or DAI (18 decimals).

Changes

  • Added getAssetDecimalsForRequirements method to x402ResourceServer that delegates to the registered scheme server's getAssetDecimals
  • Updated getDisplayAmount to dynamically determine decimals from the asset's scheme server
  • Falls back to 6 decimals when the scheme doesn't implement getAssetDecimals

Test plan

  • Full monorepo build passes
  • Verify display amounts render correctly for USDC (6), WBTC (8), and DAI (18)

@github-actions github-actions bot added typescript sdk Changes to core v2 packages labels Apr 4, 2026
ryanRfox added a commit to ryanRfox/x402 that referenced this pull request Apr 10, 2026
Read token name from firstRequirement.extra.name with a neutral
"Token" fallback instead of hardcoding "USDC". Aligns with x402-foundation#1926
which takes the same approach for the server-side fallback paywall.

Affected display strings: payment header, testnet prompt, balance
display, amount row, insufficient balance error message.

This PR was prepared with the assistance of a coding agent and
reviewed by Ryan R. Fox (an actual human) before submission.
@phdargen phdargen self-assigned this Apr 11, 2026
ryanRfox added a commit to ryanRfox/x402 that referenced this pull request Apr 11, 2026
Read token name from firstRequirement.extra.name with a neutral
"Token" fallback instead of hardcoding "USDC". Aligns with x402-foundation#1926
which takes the same approach for the server-side fallback paywall.

Affected display strings: payment header, testnet prompt, balance
display, amount row, insufficient balance error message.

This PR was prepared with the assistance of a coding agent and
reviewed by Ryan R. Fox (an actual human) before submission.
ryanRfox added a commit to ryanRfox/x402 that referenced this pull request Apr 11, 2026
Read token name from firstRequirement.extra.name with a neutral
"Token" fallback instead of hardcoding "USDC". Aligns with x402-foundation#1926
which takes the same approach for the server-side fallback paywall.

Affected display strings: payment header, testnet prompt, balance
display, amount row, insufficient balance error message.

This PR was prepared with the assistance of a coding agent and
reviewed by Ryan R. Fox (an actual human) before submission.
@ryanRfox
Copy link
Copy Markdown
Contributor

FWIW in your review @phdargen I'm cherrypicking this into my local SDK builds because it's the proper fix for the UI issues I've been encountering.

thanks for providing this fix @natsukingly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sdk Changes to core v2 packages typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants