-
Notifications
You must be signed in to change notification settings - Fork 13
[TASK-6558] prevent e in token input #491
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
Conversation
📝 Walkthrough📝 WalkthroughWalkthroughThe changes in the Changes
Possibly related PRs
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
src/components/Global/TokenAmountInput/index.tsx (1)
81-83
: LGTM! Consider adding a comment explaining the e-key prevention.The implementation correctly prevents scientific notation input, which improves the user experience for token amount entry.
Add a comment to explain why we're preventing 'e':
+ // Prevent scientific notation ('e' key) in numeric input if (e.key.toLowerCase() === 'e') { e.preventDefault() }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- src/components/Global/TokenAmountInput/index.tsx (2 hunks)
🔇 Additional comments (1)
src/components/Global/TokenAmountInput/index.tsx (1)
Line range hint
22-24
: Verify input validation constraints.The component handles decimal input but lacks explicit validation for:
- Maximum value constraints
- Decimal place limitations
- Precision handling for large numbers
This could lead to potential issues with token amount calculations or display.
Let's check if there are any validation utilities or constants defined elsewhere:
Consider adding:
- Maximum value validation
- Decimal place constraints
- Proper numeric validation using regex or validation utilities
? '0' | ||
: inputDenomination === 'USD' | ||
? utils.formatTokenAmount(Number(tokenValue) / (selectedTokenData?.price ?? 0)) | ||
: '$' + utils.formatTokenAmount(Number(tokenValue) * (selectedTokenData?.price ?? 0))} |
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.
🛠️ Refactor suggestion
Consider simplifying the nested ternary expression.
While the falsy value handling is correct, the nested ternary makes the code harder to read and maintain.
Consider refactoring to improve readability:
- {!tokenValue
- ? '0'
- : inputDenomination === 'USD'
- ? utils.formatTokenAmount(Number(tokenValue) / (selectedTokenData?.price ?? 0))
- : '$' + utils.formatTokenAmount(Number(tokenValue) * (selectedTokenData?.price ?? 0))}
+ {(() => {
+ if (!tokenValue) return '0';
+ const amount = inputDenomination === 'USD'
+ ? Number(tokenValue) / (selectedTokenData?.price ?? 0)
+ : Number(tokenValue) * (selectedTokenData?.price ?? 0);
+ return inputDenomination === 'USD'
+ ? utils.formatTokenAmount(amount)
+ : '$' + utils.formatTokenAmount(amount);
+ })()}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
? '0' | |
: inputDenomination === 'USD' | |
? utils.formatTokenAmount(Number(tokenValue) / (selectedTokenData?.price ?? 0)) | |
: '$' + utils.formatTokenAmount(Number(tokenValue) * (selectedTokenData?.price ?? 0))} | |
{(() => { | |
if (!tokenValue) return '0'; | |
const amount = inputDenomination === 'USD' | |
? Number(tokenValue) / (selectedTokenData?.price ?? 0) | |
: Number(tokenValue) * (selectedTokenData?.price ?? 0); | |
return inputDenomination === 'USD' | |
? utils.formatTokenAmount(amount) | |
: '$' + utils.formatTokenAmount(amount); | |
})()} |
8d4ead5
to
2510d87
Compare
2510d87
to
a78ff25
Compare
a78ff25
to
0852ae6
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.
suggestion(blocking): it's a good opportunity to prevent '+' and '-' also (they are valid in decimal mode too)
e.preventDefault() | ||
if (onSubmit) onSubmit() | ||
} | ||
if (['e', '+', '-'].includes(e.key.toLowerCase())) { |
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.
praise: nice!
No description provided.