Skip to content

[TASK-14062] persist dynamic bank account form state#1157

Merged
Zishan-7 merged 5 commits intopeanut-wallet-devfrom
feat/persist-dynamicBankAccountFormState
Sep 4, 2025
Merged

[TASK-14062] persist dynamic bank account form state#1157
Zishan-7 merged 5 commits intopeanut-wallet-devfrom
feat/persist-dynamicBankAccountFormState

Conversation

@Zishan-7
Copy link
Contributor

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

No description provided.

@notion-workspace
Copy link

@vercel
Copy link

vercel bot commented Sep 1, 2025

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

Project Deployment Preview Comments Updated (UTC)
peanut-wallet Canceled Canceled Sep 4, 2025 2:13pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 1, 2025

Walkthrough

Adds a new Redux slice (bankForm) to persist/clear DynamicBankAccountForm data, wires it into the store and constants, preloads persisted data into the form, saves trimmed form values on successful submit, and clears persisted form state on back navigation.

Changes

Cohort / File(s) Summary
Redux slice & types
src/redux/slices/bank-form-slice.ts, src/redux/types/bank-form.types.ts
New bankForm slice and types. Exposes bankFormActions with setFormData, updateFormField, clearFormData. State holds `formData: Partial
Redux plumbing
src/redux/store.ts, src/redux/constants/index.ts
Registers bankForm reducer in root store; adds BANK_FORM_SLICE constant. Root state now includes bankForm.
Form persistence integration
src/components/AddWithdraw/DynamicBankAccountForm.tsx
Loads state.bankForm.formData to prefill form, trims names on submit, and dispatches bankFormActions.setFormData with sanitized fields after successful submission.
Navigation clears persisted state
src/components/AddWithdraw/AddWithdrawCountriesList.tsx, src/components/Claim/Link/views/BankFlowManager.view.tsx
Calls dispatch(bankFormActions.clearFormData()) on back navigation to clear persisted DynamicBankAccountForm data before view change.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • kushagrasarathe
  • jjramirezn
✨ 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/persist-dynamicBankAccountFormState

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.

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

🧹 Nitpick comments (8)
src/redux/types/bank-form.types.ts (1)

1-7: Prefer type-only import and decouple UI-layer types.

Use import type to avoid unintended runtime imports, and consider moving IBankAccountDetails to a shared types module to prevent cross-layer coupling.

Apply:

-import { IBankAccountDetails } from '@/components/AddWithdraw/DynamicBankAccountForm'
+import type { IBankAccountDetails } from '@/components/AddWithdraw/DynamicBankAccountForm'

Optional (separate change): create src/types/bank-account.types.ts for IBankAccountDetails and import from there to avoid Redux↔UI dependency.

src/components/AddWithdraw/DynamicBankAccountForm.tsx (2)

76-78: Avoid tight coupling to state shape; add a selector.

Directly reaching into state.bankForm.formData couples this component to slice placement. Prefer a selector to decouple and centralize typing.

Example selector (place under src/redux/selectors/bankForm.ts):

import { RootState } from '@/redux/store'
export const selectBankFormData = (state: RootState) => state.bankForm.formData

Then in this component:

-const persistedFormData = useAppSelector((state) => state.bankForm.formData)
+const persistedFormData = useAppSelector(selectBankFormData)

99-100: defaultValues won’t refresh after mount; reset on persisted changes if needed.

If persistedFormData can change after first render (e.g., navigating back), call reset when it changes; otherwise fields may show stale values.

// add to useForm destructure
const { control, handleSubmit, setValue, getValues, reset, formState: { ... } } = useForm<IBankAccountDetails>(...)

// rehydrate on persisted changes
useEffect(() => {
  if (persistedFormData) reset({ ...getValues(), ...persistedFormData })
  // eslint-disable-next-line react-hooks/exhaustive-deps
}, [persistedFormData])
src/redux/slices/bank-form-slice.ts (5)

17-29: Type flexibility and safety for updateFormField.

  • value is typed as string, which is fine today but ties reducer to string-only fields. Consider inferring from key for future-proofing.

Example:

-            action: PayloadAction<{
-                field: keyof IBankAccountDetails
-                value: string
-            }>
+            action: PayloadAction<{
+                field: keyof IBankAccountDetails
+                value: IBankAccountDetails[keyof IBankAccountDetails]
+            }>

4-4: Decouple slice from component-level types.

Importing IBankAccountDetails from a component path creates UI↔state coupling and risks circular deps. Move the type to a shared domain types module (e.g., src/types/bank.ts) and import from there.


30-32: Clear vs. empty object—be explicit about intent.

If “no data” is semantically different from “some fields empty”, null is fine. If not, using {} simplifies merges and avoids null checks elsewhere. Keep as-is if other code relies on null.


36-37: Export selectors to reduce component coupling.

Provide selectBankFormData (and others if needed) alongside actions to standardize access.

Example (add below reducer):

// selectors
export const selectBankFormData = (state: RootState) => state.bankForm.formData

1-38: PII in Redux—confirm it’s ephemeral and not persisted.

You’re storing account numbers, CLABE, routing numbers, etc. Ensure:

  • No redux-persist/localStorage for this slice.
  • No logging of actions/state in production.
  • Data is cleared on route leave/back (as PR notes).
📜 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 a314777 and 8b893e4.

📒 Files selected for processing (7)
  • src/components/AddWithdraw/AddWithdrawCountriesList.tsx (3 hunks)
  • src/components/AddWithdraw/DynamicBankAccountForm.tsx (5 hunks)
  • src/components/Claim/Link/views/BankFlowManager.view.tsx (3 hunks)
  • src/redux/constants/index.ts (1 hunks)
  • src/redux/slices/bank-form-slice.ts (1 hunks)
  • src/redux/store.ts (2 hunks)
  • src/redux/types/bank-form.types.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📚 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/Claim/Link/views/BankFlowManager.view.tsx
  • src/components/AddWithdraw/AddWithdrawCountriesList.tsx
📚 Learning: 2025-05-15T14:47:26.891Z
Learnt from: jjramirezn
PR: peanutprotocol/peanut-ui#857
File: src/hooks/useWebSocket.ts:77-82
Timestamp: 2025-05-15T14:47:26.891Z
Learning: The useWebSocket hook in src/hooks/useWebSocket.ts is designed to provide raw history entries, while the components using it (such as HomeHistory.tsx) are responsible for implementing deduplication logic based on UUID to prevent duplicate entries when combining WebSocket data with other data sources.

Applied to files:

  • src/components/Claim/Link/views/BankFlowManager.view.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/AddWithdrawCountriesList.tsx
  • 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/AddWithdrawCountriesList.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 (5)
src/redux/types/bank-form.types.ts (1)
src/components/AddWithdraw/DynamicBankAccountForm.tsx (1)
  • IBankAccountDetails (24-39)
src/components/Claim/Link/views/BankFlowManager.view.tsx (2)
src/redux/hooks.ts (1)
  • useAppDispatch (5-5)
src/redux/slices/bank-form-slice.ts (1)
  • bankFormActions (36-36)
src/components/AddWithdraw/AddWithdrawCountriesList.tsx (2)
src/redux/hooks.ts (1)
  • useAppDispatch (5-5)
src/redux/slices/bank-form-slice.ts (1)
  • bankFormActions (36-36)
src/components/AddWithdraw/DynamicBankAccountForm.tsx (2)
src/redux/hooks.ts (2)
  • useAppDispatch (5-5)
  • useAppSelector (6-6)
src/redux/slices/bank-form-slice.ts (1)
  • bankFormActions (36-36)
src/redux/slices/bank-form-slice.ts (3)
src/redux/types/bank-form.types.ts (1)
  • IBankFormState (5-7)
src/redux/constants/index.ts (1)
  • BANK_FORM_SLICE (7-7)
src/components/AddWithdraw/DynamicBankAccountForm.tsx (1)
  • IBankAccountDetails (24-39)
⏰ 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 (9)
src/redux/constants/index.ts (1)

7-7: LGTM: Consistent slice name constant.

Name follows existing pattern and is distinct. No issues.

src/redux/store.ts (1)

8-8: Reducer wiring and selectors verifiedbankForm is registered in configureStore, included in RootState (src/redux/types/index.ts), and referenced in selectors (e.g. DynamicBankAccountForm.tsx:77).

src/components/AddWithdraw/AddWithdrawCountriesList.tsx (3)

32-34: LGTM: Typed Redux hooks/actions import.

Imports are correct and scoped.


47-47: LGTM: Single dispatch instance.

Good placement; avoids re-creating in handlers.


236-238: Right call: Clear persisted form data on back from form.

Prevents stale prefill when returning to list. Matches PR intent.

src/components/Claim/Link/views/BankFlowManager.view.tsx (2)

31-33: LGTM: Dispatch wiring for form-state management.

Imports and useAppDispatch() initialization are correct.

Also applies to: 70-70


443-449: Clear form state before step transition—good safeguard.

Ensures DynamicBankAccountForm mounts clean without stale data.

src/components/AddWithdraw/DynamicBankAccountForm.tsx (2)

17-18: Redux hooks/actions import looks correct.

Imports align with store wiring and action export.


65-65: Dispatch instance initialized appropriately.

No issues.

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.

@Zishan-7 approving for fast tracking, lgtm, but why use redux? context not working?

also check codderrabbit comments if actionable, and resolve merge conflicts

@Zishan-7
Copy link
Contributor Author

Zishan-7 commented Sep 2, 2025

but why use redux? context not working?

I thought there are already a lot of states in WithdrawFlowContext, so better to create a separate redux store for this @kushagrasarathe

@vercel vercel bot temporarily deployed to Preview – peanut-wallet September 4, 2025 14:13 Inactive
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

🧹 Nitpick comments (2)
src/components/AddWithdraw/DynamicBankAccountForm.tsx (2)

82-84: Guard persisted defaults by country (and flow) to avoid cross-country/flow prefill.

If a user switches countries or flows, stale values may prefill invalid fields. Gate application of persisted defaults.

Apply this minimal guard:

-                ...persistedFormData, // Redux persisted data takes precedence
+                ...(persistedFormData && persistedFormData.country === country
+                    ? persistedFormData
+                    : {}), // only preload when matching country

Optionally, also gate by flow if tracked in the slice:

-                ...(persistedFormData && persistedFormData.country === country
-                    ? persistedFormData
-                    : {}),
+                ...(persistedFormData
+                    && persistedFormData.country === country
+                    && (('flow' in persistedFormData ? (persistedFormData as any).flow === flow : true))
+                    ? persistedFormData
+                    : {}),

Also applies to: 106-106


201-211: Deduplicate spinner toggles; rely on a single place.

You set isSubmitting(false) in both branches and again in finally. Prefer one location for clarity and to avoid double state churn.

-                    setIsSubmitting(false)
                 } else {
                     // Save form data to Redux after successful submission
                     const formDataToSave = {
                         ...data,
                         country,
                         firstName: data.firstName.trim(),
                         lastName: data.lastName.trim(),
                     }
                     dispatch(bankFormActions.setFormData(formDataToSave))
-                    setIsSubmitting(false)

Keep the finally block as the single source of truth.

📜 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 19863b9 and ec5377f.

📒 Files selected for processing (2)
  • src/components/AddWithdraw/DynamicBankAccountForm.tsx (5 hunks)
  • src/components/Claim/Link/views/BankFlowManager.view.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Claim/Link/views/BankFlowManager.view.tsx
🧰 Additional context used
🧠 Learnings (2)
📚 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/redux/hooks.ts (2)
  • useAppDispatch (5-5)
  • useAppSelector (6-6)
src/redux/slices/bank-form-slice.ts (1)
  • bankFormActions (36-36)
🔇 Additional comments (1)
src/components/AddWithdraw/DynamicBankAccountForm.tsx (1)

17-18: Clarify Redux usage for bankForm slice and persistence strategy
The bankForm reducer is registered in src/redux/store.ts but no redux-persist configuration was found—state remains in-memory and is lost on refresh. Confirm this aligns with requirements, or if the form state only needs to live within the Add/Withdraw flow, consider using a flow-scoped context (e.g. WithdrawFlowContext) instead of Redux.

@Zishan-7 Zishan-7 merged commit 19aaced into peanut-wallet-dev Sep 4, 2025
4 of 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