Reject amounts/prices with more than 18 decimal places (#2109)#2723
Reject amounts/prices with more than 18 decimal places (#2109)#2723thedavidmeister wants to merge 1 commit into
Conversation
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>
|
Warning Review limit reached
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |

Fixes #2109.
Problem
Entering an amount/io-ratio with more than 18 decimal places fails to parse in
the underlying
Floatdecimal parser and surfaces a cryptic low-level error.Per the issue,
0.0015116073271035947(19 places) errors while0.001511607327103594(18 places) works.Change (TS / webapp only)
packages/ui-components/src/lib/services/validateAmount.ts— a pure, parser-independent string check (
validateAmount/countDecimalPlaces/MAX_DECIMALS) that counts fractional digits of aplain 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
nulldecimals so it is left for the existing parser tohandle rather than mislabelled "too many decimals". Exported from both the
package root and the
./servicessubpath.InputTokenAmount.sveltevalidates the raw input, shows the error underthe field (
data-testid="decimals-error"), and does not propagate the invalidvalue (it resets to zero). The MAX button clears the error.
TakeOrderModal.sveltevalidates the price-cap input reactively, shows theerror (
data-testid="price-cap-error"), and keeps the submit button disabledwhile it is invalid.
Tests (discriminating)
validateAmount.test.ts(new, 14 tests): asserts exact decimal counts and theexact
{ isValid, errorMessage }for the issue's 18- vs 19-place values, anegative 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 resetsthe value to
0; exactly 18 places shows no error and keeps the value; a validvalue clears a prior error.
TakeOrderModal.test.ts(+2): a 19-place price cap shows the error and keepssubmit 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; targetedvalidateAmount+InputTokenAmountpass;npm run lintandnpm run checkclean (0 errors).
webapp:TakeOrderModal(33),DepositModal(11),WithdrawModal(10) pass;npm run lintclean.svelte-checkreports 2 pre-existing, env-only errors inhandleWalletInitialization.ts/.test.ts(missingPUBLIC_WALLETCONNECT_PROJECT_IDfrom$env/static/public— files untouchedby this PR).
🤖 Generated with Claude Code