Skip to content

Conversation

jjramirezn
Copy link
Contributor

Added the ValidatedInput component to check if the account number is valid and show feedback to the user before they try to proceed

Copy link
Contributor

coderabbitai bot commented Oct 25, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request focus on the InitialCashoutView component within the Cashout feature. Key modifications include the introduction of a new ValidatedInput component for handling bank account input, which replaces the previous input management. The state management has been updated to track bankAccountNumber and its validation status, while the logic for validating and displaying bank accounts has been refined. The error handling and control flow for enabling the "Proceed" button have also been adjusted to enhance the user experience.

Changes

File Path Change Summary
src/components/Cashout/Components/Initial.view.tsx - Added ValidatedInput for bank account input handling.
- Removed selectedBankAccount and newBankAccount states.
- Introduced new states: bankAccountNumber, isValidBankAccountNumber, and isValidatingBankAccountNumber.
- Refactored validation logic to utilize ValidatedInput.
- Updated handleOnNext to validate bankAccountNumber.
- Integrated error handling within onUpdate callback of ValidatedInput.
- Adjusted rendering logic for linked bank accounts.

Possibly related PRs

Suggested reviewers

  • Hugo0
  • nezz0746

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

vercel bot commented Oct 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
peanut-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 25, 2024 0:54am

Copy link

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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/Cashout/Components/Initial.view.tsx (1)

303-326: Consider UX improvements for the ValidatedInput implementation.

  1. Extract the debounce time as a constant for better maintainability:
+const ACCOUNT_VALIDATION_DEBOUNCE_MS = 750;
 
 <ValidatedInput
     placeholder="IBAN / US account number"
     label="To"
     value={accountNumber}
-    debounceTime={750}
+    debounceTime={ACCOUNT_VALIDATION_DEBOUNCE_MS}
  1. Consider showing a loading indicator during validation to provide better user feedback.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3a2ce36 and 32aa7b3.

📒 Files selected for processing (1)
  • src/components/Cashout/Components/Initial.view.tsx (8 hunks)
🔇 Additional comments (4)
src/components/Cashout/Components/Initial.view.tsx (4)

5-5: LGTM: Clean state management for account validation.

The new imports and state variables are well-structured and appropriately support the ValidatedInput implementation for account number validation.

Also applies to: 17-17, 64-66


87-101: LGTM: Comprehensive disable conditions for the proceed button.

The disable conditions properly account for validation states, ensuring users can only proceed with valid input.


Line range hint 1-377: Overall implementation looks solid with good attention to UX.

The ValidatedInput integration for account number validation is well-implemented with proper:

  • State management
  • Error handling
  • Validation feedback
  • Integration with existing bank account selection

The changes align well with the PR objective of enhancing the cashout user experience.


309-325: Verify error handling for all possible bank account formats.

The error handling looks good, but we should verify that the validation covers all supported bank account formats.

@jjramirezn jjramirezn requested a review from nezz0746 October 25, 2024 11:32
Copy link
Contributor

@panosfilianos panosfilianos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a small naming change would be helpful here. This comes from me playing around w/ wallets currently and seeing there can be many hooks/modules w/ same naming (i.e. account) and it becomes harder/ slower to disambiguate.

wdyt?

onClick={(e) => {
e.stopPropagation()
setSelectedBankAccount(undefined)
setAccountNumber('')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought (non-blocking): imo it's better to have this typed as <string | undefined> bc we can run ifs like if(accountNumber) more cleanly. An empty string is falsy, but it just feels cleaner to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end inputs need a defined value I prefer to have the state of bankAccountNumber and the value on the input to always be the same (as opposed to the state being undefined and the input be empty string)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
src/components/Cashout/Components/Initial.view.tsx (3)

64-66: Consider using more descriptive state variable names.

The state variables could be more descriptive to better reflect their purpose:

  • bankAccountNumberbankAccountIdentifier
  • isValidBankAccountNumberisBankAccountValid
  • isValidatingBankAccountNumberisBankAccountValidating

313-324: Enhance error message specificity.

The current error message "Invalid bank account. Please make sure your account is supported" could be more specific about what makes an account supported (e.g., IBAN format for EU accounts or routing/account number format for US accounts).

 setErrorState({
     showError: true,
     errorMessage:
-        'Invalid bank account. Please make sure your account is supported',
+        'Invalid bank account format. Please enter a valid IBAN for EU accounts or routing/account number for US accounts',
 })

Line range hint 283-293: Add aria-label for accessibility.

The clear button (✕) should have an aria-label for better accessibility.

 <button
     className="text-lg text-black"
+    aria-label="Clear bank account selection"
     onClick={(e) => {
         e.stopPropagation()
         setBankAccountNumber('')
     }}
 >
     ✕
 </button>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 32aa7b3 and 2f2722f.

📒 Files selected for processing (1)
  • src/components/Cashout/Components/Initial.view.tsx (8 hunks)
🧰 Additional context used
📓 Learnings (1)
src/components/Cashout/Components/Initial.view.tsx (1)
Learnt from: jjramirezn
PR: peanutprotocol/peanut-ui#484
File: src/components/Cashout/Components/Initial.view.tsx:273-274
Timestamp: 2024-10-25T11:33:46.776Z
Learning: In the `InitialCashoutView` component (`src/components/Cashout/Components/Initial.view.tsx`), linked bank accounts should not generate error states, and the `ValidatedInput` component will clear any error messages if needed. Therefore, it's unnecessary to manually clear the error state when selecting or clearing linked bank accounts.
🔇 Additional comments (2)
src/components/Cashout/Components/Initial.view.tsx (2)

303-326: Implementation looks solid!

The ValidatedInput integration successfully improves the bank account validation UX with:

  • Proper debouncing of validation
  • Clear error messaging
  • Consistent state management
  • Smooth integration with existing linked accounts functionality

309-325: Verify validation state management.

There's a potential race condition in the validation state management. If multiple validation callbacks are triggered in quick succession (despite debouncing), you might get into an inconsistent state. Consider using a ref to track the latest validation request.

Consider implementing a validation queue or using a ref to track the latest validation request:

const latestValidationId = useRef(0);

// In onUpdate:
const currentId = ++latestValidationId.current;
// ... perform validation ...
if (currentId === latestValidationId.current) {
    // Update state only if this is still the latest validation
    setIsValidBankAccountNumber(isValid);
}

xchainAllowed,
isBelowMinLimit,
isExceedingMaxLimit,
])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: booleans like these variables usually don't need useMemo, you're not getting any performance improvement. Also it includes potential bugs if you're missing a variable in the dependency array the the compute is broken

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.

3 participants