-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix: allow amount inputs to be empty #288
Conversation
And refactor the two places found to have buggy amounts into this new component. Fixes liftedinit#281
Warning Rate limit exceeded@hansl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 4 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughThis change introduces a new React component called Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Form
participant AmountInput
User->>Form: Opens send form
Form->>AmountInput: Passes current amount value & onValueChange callback
User->>AmountInput: Enters or updates amount
AmountInput->>Form: Calls onValueChange(newValue)
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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 (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #288 +/- ##
==========================================
+ Coverage 53.57% 53.61% +0.04%
==========================================
Files 209 210 +1
Lines 17246 17255 +9
==========================================
+ Hits 9240 9252 +12
+ Misses 8006 8003 -3 ☔ View full report in Codecov by Sentry. |
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 comments (3)
components/bank/forms/sendForm.tsx (1)
75-104
: 🛠️ Refactor suggestionConsider updating validation schema for empty values.
The validation schema requires a value but the AmountInput component allows empty values. Consider updating the schema to align with the new component's behavior.
amount: Yup.number() - .required('Amount is required') + .transform((value) => (value === '' ? null : value)) + .nullable() + .required('Amount is required') .positive('Amount must be positive')components/bank/forms/ibcSendForm.tsx (2)
129-132
:⚠️ Potential issueValidation schema conflicts with PR objective.
The validation schema requires the amount to be non-empty and positive, which conflicts with the PR objective to "allow amount inputs to be empty".
Update the validation schema to allow empty amounts:
- amount: Yup.number() - .required('Amount is required') + amount: Yup.string() + .test('valid-amount', 'Amount must be positive when provided', function(value) { + if (!value) return true; + const num = Number(value); + return !isNaN(num) && num > 0; + })
168-338
:⚠️ Potential issueVerify empty amount handling in submission logic.
The form submission logic needs to be verified to handle empty amounts correctly. Currently, it attempts to convert the amount to base units without checking if it's empty.
Update the submission handler to handle empty amounts:
const handleSend = async (values: { recipient: string; - amount: string; + amount: string | ''; selectedToken: CombinedBalanceInfo; memo: string; }) => { setIsSending(true); try { + if (!values.amount) { + throw new Error('Amount is required for sending tokens'); + } // Convert amount to base units const exponent = values.selectedToken.metadata?.denom_units[1]?.exponent ?? 6; const amountInBaseUnits = parseNumberToBigInt(values.amount, exponent).toString();
🧹 Nitpick comments (3)
components/react/inputs/AmountInput.tsx (2)
18-39
: Consider adding input validation for maximum decimal places.The current regex allows any number of decimal places. Consider adding validation for the maximum number of decimal places based on the token's metadata.
-const newValue = /^\d*\.?\d*$/.test(v) ? parseFloat(v) : NaN; +const newValue = /^\d*\.?\d{0,6}$/.test(v) ? parseFloat(v) : NaN;🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 27-28: components/react/inputs/AmountInput.tsx#L27-L28
Added lines #L27 - L28 were not covered by tests
[warning] 36-36: components/react/inputs/AmountInput.tsx#L36
Added line #L36 was not covered by tests
41-53
: Consider extracting styles to a CSS module or Tailwind class.The inline styles in className could be moved to a CSS module or a Tailwind class for better maintainability.
components/react/inputs/__tests__/AmountInput.test.tsx (1)
1-78
: Add tests for additional edge cases.While the current test suite covers basic functionality, consider adding tests for:
- Handling decimal places validation
- Single period input
- Invalid input when previous value is empty
- Maximum value constraints
test('handles single period input correctly', () => { const onValueChange = jest.fn(); render( <TestForm> <AmountInput name="test" value="" onValueChange={onValueChange} /> </TestForm> ); const input = screen.getByPlaceholderText('0.00'); fireEvent.change(input, { target: { value: '.' } }); expect(onValueChange).toHaveBeenCalledWith('.'); }); test('handles invalid input when previous value is empty', () => { const onValueChange = jest.fn(); render( <TestForm> <AmountInput name="test" value="" onValueChange={onValueChange} /> </TestForm> ); const input = screen.getByPlaceholderText('0.00'); fireEvent.change(input, { target: { value: 'abc' } }); expect(onValueChange).toHaveBeenCalledWith(''); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
components/bank/forms/ibcSendForm.tsx
(2 hunks)components/bank/forms/sendForm.tsx
(2 hunks)components/react/inputs/AmountInput.tsx
(1 hunks)components/react/inputs/__tests__/AmountInput.test.tsx
(1 hunks)components/react/inputs/index.ts
(1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
components/react/inputs/AmountInput.tsx
[warning] 27-28: components/react/inputs/AmountInput.tsx#L27-L28
Added lines #L27 - L28 were not covered by tests
[warning] 36-36: components/react/inputs/AmountInput.tsx#L36
Added line #L36 was not covered by tests
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
🔇 Additional comments (5)
components/react/inputs/index.ts (1)
1-1
: LGTM!The export statement follows the established pattern and maintains consistency with other input component exports.
components/react/inputs/AmountInput.tsx (2)
3-6
: LGTM!The props interface is well-defined and follows React TypeScript best practices by extending HTMLInputElement attributes.
8-16
: LGTM!The component is well-documented with clear JSDoc comments explaining its purpose and parameters.
components/bank/forms/sendForm.tsx (1)
201-205
: LGTM!The AmountInput integration with Formik is clean and maintains the existing form functionality.
components/bank/forms/ibcSendForm.tsx (1)
525-529
: LGTM! AmountInput integration looks good.The AmountInput component is properly integrated with Formik's form management through the
onValueChange
prop.
And refactor the two places found to have buggy amounts into this new component.
Fixes #281
Summary by CodeRabbit
New Features
Style