Skip to content

Reject amounts/prices with more than 18 decimal places (#2109)#2723

Open
thedavidmeister wants to merge 1 commit into
mainfrom
2026-06-13-issue-2109
Open

Reject amounts/prices with more than 18 decimal places (#2109)#2723
thedavidmeister wants to merge 1 commit into
mainfrom
2026-06-13-issue-2109

Conversation

@thedavidmeister

Copy link
Copy Markdown
Contributor

Fixes #2109.

Problem

Entering an amount/io-ratio with more than 18 decimal places fails to parse in
the underlying Float decimal parser and surfaces a cryptic low-level error.
Per the issue, 0.0015116073271035947 (19 places) errors while
0.001511607327103594 (18 places) works.

Change (TS / webapp only)

  • New shared helper packages/ui-components/src/lib/services/validateAmount.ts
    — a pure, parser-independent string check (validateAmount /
    countDecimalPlaces / MAX_DECIMALS) that counts fractional digits of a
    plain decimal string and rejects more than 18 with a friendly message
    (Too many decimal places. A maximum of 18 decimal places is allowed.).
    Non-plain-decimal input (empty, scientific notation, thousands separators,
    letters) returns null decimals so it is left for the existing parser to
    handle rather than mislabelled "too many decimals". Exported from both the
    package root and the ./services subpath.
  • InputTokenAmount.svelte validates the raw input, shows the error under
    the field (data-testid="decimals-error"), and does not propagate the invalid
    value (it resets to zero). The MAX button clears the error.
  • TakeOrderModal.svelte validates the price-cap input reactively, shows the
    error (data-testid="price-cap-error"), and keeps the submit button disabled
    while it is invalid.

Tests (discriminating)

  • validateAmount.test.ts (new, 14 tests): asserts exact decimal counts and the
    exact { isValid, errorMessage } for the issue's 18- vs 19-place values, a
    negative 19-place value, integers/short decimals, and that integer-part digits
    and non-plain-decimal input are not flagged.
  • InputTokenAmount.test.ts (+3): 19 places shows the friendly error and resets
    the value to 0; exactly 18 places shows no error and keeps the value; a valid
    value clears a prior error.
  • TakeOrderModal.test.ts (+2): a 19-place price cap shows the error and keeps
    submit disabled; an 18-place price cap shows no error and enables submit.

Each new test was verified to fail when the 18 threshold is mutated (to 100),
so they catch a regression rather than merely pass.

Verification

  • ui-components: full suite 103 files / 653 tests pass; targeted
    validateAmount + InputTokenAmount pass; npm run lint and npm run check
    clean (0 errors).
  • webapp: TakeOrderModal (33), DepositModal (11), WithdrawModal (10) pass;
    npm run lint clean. svelte-check reports 2 pre-existing, env-only errors in
    handleWalletInitialization.ts/.test.ts (missing
    PUBLIC_WALLETCONNECT_PROJECT_ID from $env/static/public — files untouched
    by this PR).

🤖 Generated with Claude Code

Entering an amount or price with more than 18 decimal places (e.g. the
io-ratio `0.0015116073271035947`, 19 places) made `Float.parse` fail with a
cryptic low-level decimal-float error. Add a shared, parser-independent
`validateAmount` helper in ui-components that counts the fractional digits of
a plain decimal string and rejects more than 18 with a friendly message.

Wire it into `InputTokenAmount.svelte` (shows the error under the field and
does not propagate the invalid value) and into the `TakeOrderModal` price-cap
input (shows the error and keeps the submit button disabled). The helper is a
pure string check, so values with exactly 18 places keep working.

Fixes #2109

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@thedavidmeister thedavidmeister self-assigned this Jun 13, 2026
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@thedavidmeister, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 19 minutes and 34 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1eec91ef-4855-4e1d-b6d2-b3a2e20e29f8

📥 Commits

Reviewing files that changed from the base of the PR and between 70be6b1 and 3f5a8a5.

📒 Files selected for processing (8)
  • packages/ui-components/src/__tests__/InputTokenAmount.test.ts
  • packages/ui-components/src/__tests__/validateAmount.test.ts
  • packages/ui-components/src/lib/components/input/InputTokenAmount.svelte
  • packages/ui-components/src/lib/index.ts
  • packages/ui-components/src/lib/services/index.ts
  • packages/ui-components/src/lib/services/validateAmount.ts
  • packages/webapp/src/__tests__/TakeOrderModal.test.ts
  • packages/webapp/src/lib/components/TakeOrderModal.svelte
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-06-13-issue-2109

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@thedavidmeister

Copy link
Copy Markdown
Contributor Author

screenshot

UI screenshot: rejecting amounts/prices with more than 18 decimal places

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.

Validation for rainlang strings with more than 18 decimals.

1 participant