Skip to content

[TASK-14290] Fix Bug: recognize bank account that was already added #1162

Merged
Zishan-7 merged 4 commits intopeanut-wallet-devfrom
feat/detect-selected-acc
Sep 4, 2025
Merged

[TASK-14290] Fix Bug: recognize bank account that was already added #1162
Zishan-7 merged 4 commits intopeanut-wallet-devfrom
feat/detect-selected-acc

Conversation

@Zishan-7
Copy link
Contributor

@Zishan-7 Zishan-7 commented Sep 2, 2025

No description provided.

@vercel
Copy link

vercel bot commented Sep 2, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
peanut-wallet Ready Ready Preview Comment Sep 4, 2025 2:33pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 2, 2025

Walkthrough

Adds duplicate-account detection to DynamicBankAccountForm: integrates Next.js router and useSavedAccounts, reads setSelectedBankAccount from useWithdrawFlow, and on submit redirects to the withdraw bank page with the existing account if accountNumber or CLABE matches, skipping creation.

Changes

Cohort / File(s) Summary of Changes
Withdraw flow form logic
src/components/AddWithdraw/DynamicBankAccountForm.tsx
- Import and initialize useRouter from next/navigation and useSavedAccounts hook
- Destructure and use setSelectedBankAccount from useWithdrawFlow() (return signature changed)
- On submit, check savedAccounts for matching accountNumber or CLABE; if found, call setSelectedBankAccount and router.push('/withdraw/bank'), aborting account creation
- Adds an early-return duplicate-detection path that bypasses the normal creation flow

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • jjramirezn
  • kushagrasarathe
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/detect-selected-acc

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.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@notion-workspace
Copy link

Copy link
Contributor

@kushagrasarathe kushagrasarathe left a comment

Choose a reason for hiding this comment

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

check comments

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: 2

♻️ Duplicate comments (1)
src/components/AddWithdraw/DynamicBankAccountForm.tsx (1)

17-17: Good move using useSavedAccounts (addresses prior ask).

This aligns with earlier feedback to source saved accounts via the hook. No issues.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 24eb5b3 and 4812c61.

📒 Files selected for processing (1)
  • src/components/AddWithdraw/DynamicBankAccountForm.tsx (3 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
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.
📚 Learning: 2024-10-25T11:33:46.776Z
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.

Applied to files:

  • src/components/AddWithdraw/DynamicBankAccountForm.tsx
📚 Learning: 2025-05-22T15:38:48.586Z
Learnt from: kushagrasarathe
PR: peanutprotocol/peanut-ui#869
File: src/app/(mobile-ui)/withdraw/page.tsx:82-88
Timestamp: 2025-05-22T15:38:48.586Z
Learning: The country-specific withdrawal route exists at src/app/(mobile-ui)/withdraw/[...country]/page.tsx and renders the AddWithdrawCountriesList component with flow="withdraw".

Applied to files:

  • src/components/AddWithdraw/DynamicBankAccountForm.tsx
📚 Learning: 2025-08-13T18:22:01.941Z
Learnt from: Zishan-7
PR: peanutprotocol/peanut-ui#1094
File: src/components/AddWithdraw/DynamicBankAccountForm.tsx:0-0
Timestamp: 2025-08-13T18:22:01.941Z
Learning: In the DynamicBankAccountForm component, the countryName parameter from useParams will always resemble a country title, not a URL slug.

Applied to files:

  • src/components/AddWithdraw/DynamicBankAccountForm.tsx
🧬 Code graph analysis (1)
src/components/AddWithdraw/DynamicBankAccountForm.tsx (2)
src/context/WithdrawFlowContext.tsx (1)
  • useWithdrawFlow (141-147)
src/hooks/useSavedAccounts.tsx (1)
  • useSavedAccounts (10-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Deploy-Preview
🔇 Additional comments (2)
src/components/AddWithdraw/DynamicBankAccountForm.tsx (2)

68-68: Correctly wiring setSelectedBankAccount into the flow.

This enables a smooth handoff to the withdraw step when a duplicate is detected.


119-121: Normalize identifiers and confirm US identifier composition

  • Strip spaces/hyphens and lowercase both sides to avoid IBAN/CLABE mismatches.
  • Verify how US account identifiers are constructed (routing + account) in savedAccounts to ensure correct matching.
-                const existingAccount = savedAccounts.find(
-                    (account) => account.identifier === (data.accountNumber.toLowerCase() || data.clabe.toLowerCase())
-                )
+                const normalize = (s?: string) => (s ?? '').replace(/[\s-]/g, '').toLowerCase()
+                const inputIdentifier = normalize(data.clabe || data.accountNumber)
+                const existingAccount = savedAccounts.find(
+                    (account) => normalize(account.identifier) === inputIdentifier
+                )

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

♻️ Duplicate comments (2)
src/components/AddWithdraw/DynamicBankAccountForm.tsx (2)

141-141: Remove stray console.log.

Keep logs out of submit paths.

-                console.log('Validation still checking, skipping submission')
+                // validation still running; skip submission

156-161: Use route param for country and replace() to avoid history stacking.

Push uses the prop country (e.g., "USA/MX"), but the withdraw path expects the [...country] segment(s). Also prefer replace().

Apply:

-                if (existingAccount) {
-                    setSelectedBankAccount(existingAccount)
-                    router.push(`/withdraw/${country}/bank`)
-                    return
-                }
+                if (existingAccount) {
+                    setSelectedBankAccount(existingAccount)
+                    const countryForPath = Array.isArray(countryNameParams)
+                        ? countryNameParams.join('/')
+                        : String(countryNameParams ?? selectedCountry)
+                    router.replace(`/withdraw/${countryForPath}/bank`)
+                    return
+                }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4812c61 and 2aee1cc.

📒 Files selected for processing (1)
  • src/components/AddWithdraw/DynamicBankAccountForm.tsx (3 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-05-22T15:38:48.586Z
Learnt from: kushagrasarathe
PR: peanutprotocol/peanut-ui#869
File: src/app/(mobile-ui)/withdraw/page.tsx:82-88
Timestamp: 2025-05-22T15:38:48.586Z
Learning: The country-specific withdrawal route exists at src/app/(mobile-ui)/withdraw/[...country]/page.tsx and renders the AddWithdrawCountriesList component with flow="withdraw".

Applied to files:

  • src/components/AddWithdraw/DynamicBankAccountForm.tsx
📚 Learning: 2024-10-25T11:33:46.776Z
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.

Applied to files:

  • src/components/AddWithdraw/DynamicBankAccountForm.tsx
📚 Learning: 2025-08-13T18:22:01.941Z
Learnt from: Zishan-7
PR: peanutprotocol/peanut-ui#1094
File: src/components/AddWithdraw/DynamicBankAccountForm.tsx:0-0
Timestamp: 2025-08-13T18:22:01.941Z
Learning: In the DynamicBankAccountForm component, the countryName parameter from useParams will always resemble a country title, not a URL slug.

Applied to files:

  • src/components/AddWithdraw/DynamicBankAccountForm.tsx
📚 Learning: 2025-08-14T14:42:54.411Z
Learnt from: Zishan-7
PR: peanutprotocol/peanut-ui#1094
File: src/utils/withdraw.utils.ts:181-191
Timestamp: 2025-08-14T14:42:54.411Z
Learning: The countryCodeMap in src/components/AddMoney/consts/index.ts uses uppercase 3-letter country codes as keys (like 'AUT', 'BEL', 'CZE') that map to 2-letter country codes, requiring input normalization to uppercase for proper lookups.

Applied to files:

  • src/components/AddWithdraw/DynamicBankAccountForm.tsx
🧬 Code graph analysis (1)
src/components/AddWithdraw/DynamicBankAccountForm.tsx (2)
src/context/WithdrawFlowContext.tsx (1)
  • useWithdrawFlow (141-147)
src/hooks/useSavedAccounts.tsx (1)
  • useSavedAccounts (10-23)
🔇 Additional comments (5)
src/components/AddWithdraw/DynamicBankAccountForm.tsx (5)

9-9: Router/params import looks good.

Usage is appropriate; see redirect fix below to leverage the catch-all param when building the path.


17-17: Good: useSavedAccounts hook adoption.

Right source of truth for user accounts.


79-79: Router instance creation LGTM.


80-80: Saved accounts retrieval LGTM.


76-76: WithdrawFlowContextProvider includes setSelectedBankAccount; all hook consumers have access—no issues detected.

@Zishan-7 Zishan-7 merged commit 21c6c59 into peanut-wallet-dev Sep 4, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants