-
Notifications
You must be signed in to change notification settings - Fork 33
fix: normalize inputAmount by stripping leading zeros after first non… #1118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Conversation
b6b4017
to
be8511f
Compare
be8511f
to
a9a012e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why you didn't use zod?
|
I'm not using
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat implementation. thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I resolved my comments. you can move it to test.
📝 Summary
0000
,0.
, or0.0000
without immediate formatting00001
→1
,0000.01
→0.01
)0.00001
— input below this (e.g.0.00000
) is blocked🔍 Changes
Added four regex constants in UPPER_SNAKE_CASE:
ALL_ZERO_REGEX
– detects pure-zero strings (e.g.,0000
,0.000
)LEADING_ZEROS_REGEX
– strips leading zeros only when followed by a digitLEADING_DOT_REGEX
– normalizes inputs like.5
→0.5
ALLOWABLE_ZERO_INPUT_REGEX
– allows partial raw-zero input like0.
,0.000
Updated
setInputAmount
:ALL_ZERO_REGEX
+ALLOWABLE_ZERO_INPUT_REGEX
)LEADING_ZEROS_REGEX
andLEADING_DOT_REGEX
0.00001
by checking parsed numeric value🛠️ How to Test
✅ Some Test Scenarios
00000
00000
0.
0.
0.0000
0.0000
00001
1
0000.01
0.01
.5
0.5
0.00001
0.00001
🔄 Updates (since last review)
sanitize/validate
logic intosanitizer.ts
&validation.ts
sanitizer.test.ts
&validation.test.ts
with edge‑case coverageconstants.ts
(ALL_ZERO_REGEX
,LEADING_ZEROS_REGEX
,LEADING_DOT_REGEX
,ALLOWABLE_ZERO_INPUT_REGEX
) — now internalized insanitizer.ts
andvalidation.ts.
0.00000
)sanitizer.ts
: includesformatThousandsWithCommas
,replaceSpacesWithDash
validation.ts
: includesisValidCurrencyFormat
,isNumeric
,isColorKeyOverridden
0000
→0
) on input blurquoteStore
.🧪 Verification Steps
sanitizer.ts
andvalidation.ts
for correct function extraction.yarn test
and confirm that all tests insanitizer.test.ts
andvalidation.test.ts
pass.