[TASK-14290] Fix Bug: recognize bank account that was already added #1162
[TASK-14290] Fix Bug: recognize bank account that was already added #1162Zishan-7 merged 4 commits intopeanut-wallet-devfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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.
📒 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
savedAccountsto 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 + )
There was a problem hiding this comment.
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 preferreplace().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.
📒 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 includessetSelectedBankAccount; all hook consumers have access—no issues detected.
No description provided.