Skip to content

fix(samples/frontend): scale default quote amount by source currency decimals#604

Open
pengying wants to merge 1 commit into
06-18-fix_samples_kotlin_select_crypto_network_when_funding_a_quote_from_usdcfrom
06-18-fix_samples_frontend_scale_default_quote_amount_by_source_currency_decimals
Open

fix(samples/frontend): scale default quote amount by source currency decimals#604
pengying wants to merge 1 commit into
06-18-fix_samples_kotlin_select_crypto_network_when_funding_a_quote_from_usdcfrom
06-18-fix_samples_frontend_scale_default_quote_amount_by_source_currency_decimals

Conversation

@pengying

Copy link
Copy Markdown
Contributor

The quote step hardcoded lockedCurrencyAmount=1000, which is $10.00 in USD
(2 decimals) but only 0.001 USDC (6 decimals) — below corridor minimums,
causing AMOUNT_OUT_OF_RANGE when funding from USDC. Default to 10 major
units scaled by the source currency's decimals (USD->1000, USDC->10000000).

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

…decimals

The quote step hardcoded lockedCurrencyAmount=1000, which is $10.00 in USD
(2 decimals) but only 0.001 USDC (6 decimals) — below corridor minimums,
causing AMOUNT_OUT_OF_RANGE when funding from USDC. Default to 10 major
units scaled by the source currency's decimals (USD->1000, USDC->10000000).

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

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown

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

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
grid-flow-builder Ignored Ignored Preview Jun 18, 2026 8:49pm
grid-wallet-demo Ignored Ignored Preview Jun 18, 2026 8:49pm

Request Review

pengying commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug in the CreateQuote sample step where lockedCurrencyAmount was hardcoded to 1000, which is $10.00 in USD but only 0.001 USDC — well below corridor minimums, causing AMOUNT_OUT_OF_RANGE errors when a user selected USDC as the source currency.

  • Introduces SOURCE_CURRENCY_DECIMALS ({ USD: 2, USDC: 6 }) and DEFAULT_SEND_UNITS = 10, then computes lockedCurrencyAmount = DEFAULT_SEND_UNITS * 10 ** decimals inside the useEffect. USD behaviour is unchanged (1000 = $10.00); USDC now correctly produces 10,000,000 (~10 USDC).
  • A ?? 2 fallback guards against any future currency not yet listed in the decimals map, preserving USD-like behaviour as a safe default.

Confidence Score: 5/5

Safe to merge — the change is a targeted fix to a sample UI default value with no backend or data-model impact.

The fix is a small arithmetic expression computed entirely from a hardcoded lookup table with integer exponents. For both listed currencies the result is an exact integer within JS's safe-integer range (USD→1000, USDC→10,000,000), so there are no floating-point concerns. The ?? 2 fallback is a sensible default. No new state, no new API paths, no auth changes.

No files require special attention.

Important Files Changed

Filename Overview
samples/frontend/src/steps/CreateQuote.tsx Adds SOURCE_CURRENCY_DECIMALS map and DEFAULT_SEND_UNITS constant to compute a correctly-scaled lockedCurrencyAmount per source currency; math is exact for all listed decimal values.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User selects sourceCurrency] --> B{sourceCurrency in\nSOURCE_CURRENCY_DECIMALS?}
    B -- Yes --> C["decimals = SOURCE_CURRENCY_DECIMALS[sourceCurrency]\n(USD→2, USDC→6)"]
    B -- No\n(fallback) --> D[decimals = 2]
    C --> E["lockedCurrencyAmount =\nDEFAULT_SEND_UNITS × 10^decimals\n(USD→1000, USDC→10 000 000)"]
    D --> E
    E --> F[setBody with updated quote payload]
    F --> G[User submits → POST /api/quotes]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[User selects sourceCurrency] --> B{sourceCurrency in\nSOURCE_CURRENCY_DECIMALS?}
    B -- Yes --> C["decimals = SOURCE_CURRENCY_DECIMALS[sourceCurrency]\n(USD→2, USDC→6)"]
    B -- No\n(fallback) --> D[decimals = 2]
    C --> E["lockedCurrencyAmount =\nDEFAULT_SEND_UNITS × 10^decimals\n(USD→1000, USDC→10 000 000)"]
    D --> E
    E --> F[setBody with updated quote payload]
    F --> G[User submits → POST /api/quotes]
Loading

Reviews (1): Last reviewed commit: "fix(samples/frontend): scale default quo..." | Re-trigger Greptile

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.

1 participant