App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-10-28] [$250] Progress not saved when moving through the screens to add banking information in Wallet

Open m-natarajan opened this issue 4 months ago • 98 comments

  • HELD on https://github.com/Expensify/App/pull/95946

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.4.26-6 Reproducible in staging?: Y Reproducible in production?: Y If this was caught during regression testing, add the test name, ID and link from BrowserStack: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: @bfitzexpensify Slack conversation (hyperlinked to channel name): #Expensify Bugs

Action Performed:

  1. Log in to New Expensify and access the Wallet
  2. Add a business bank account or personal deposit account
  3. After any screen that you've entered information on, exit the modal by clicking elsewhere
  4. Re-enter the flow

Expected Result:

Progress should be saved and you should resume at the same point

Actual Result:

Progress is lost and you need to start again

Workaround:

Can the user still use Expensify without this being fixed? Have you informed them of the workaround?

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [x] MacOS: Chrome / Safari

Screenshots/Videos

https://github.com/user-attachments/assets/32c80bc5-5c44-4849-8ad7-0a9a04c0f1a4

https://github.com/user-attachments/assets/bc3b342f-8dc1-4b55-9e59-4d0056fef1b2

https://github.com/user-attachments/assets/391e2436-b3b6-45a8-a61f-1ce0a2e9080f

View all open jobs on GitHub

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @nabi-ebrahimi

m-natarajan avatar Jul 03 '26 13:07 m-natarajan

Proposal

What is the root cause of that problem?

Both bank-account flows in the Wallet deliberately wipe their saved draft on unmount, and neither durably remembers which step you were on. So when you dismiss the modal by clicking away, the entry-point screen unmounts, its cleanup runs, and everything you typed (plus your position in the wizard) is discarded before you re-enter.

There are two independent entry points, each with the same shape of bug:

Personal deposit account (AddPersonalBankAccountPage.tsx)

  • AddPersonalBankAccountPage.tsx:62 registers useEffect(() => clearPersonalBankAccount, []) — the returned function runs on every unmount. Dismissing the modal unmounts the page, so clearPersonalBankAccount nulls both PERSONAL_BANK_ACCOUNT and the form draft PERSONAL_BANK_ACCOUNT_FORM_DRAFT.
  • The step index is plain useState(startFrom) in useSubStep/index.ts:26, so on remount it resets to 0.

Business bank account / VBBA (ReimbursementAccountPage.tsx)

  • ReimbursementAccountPage.tsx:160-166 has an unmount cleanup that unconditionally calls clearReimbursementAccountDraft() + clearReimbursementAccount(), emptying the form draft and resetting achData to DEFAULT_DATA (which has no currentStep). The mount effect clears the draft again on re-entry (lines 250-253).
  • The sub-step position is reconstructed from the draft (e.g. BusinessInfo.tsx:106), but since the draft was just cleared, it resolves to step 0 with blank fields.

The net effect matches the report exactly: any data not yet submitted to the backend is gone, and the flow restarts from the beginning.

What changes do you think we should make in order to solve the problem?

Stop discarding in-progress state on a plain dismiss, and make the position resumable:

  1. Guard the unmount cleanup so it only clears drafts when the flow is genuinely completed or explicitly cancelled, not on every unmount. Both AddPersonalBankAccountPage.tsx:62 and ReimbursementAccountPage.tsx:160-166 should keep the draft alive when the modal is merely dismissed mid-flow.
  2. Persist the resume position. Instead of useSubStep's ephemeral useState, derive the starting step from the surviving draft values on re-entry (the getInitialSubStepFor* helpers already do this — they just need a non-empty draft to read from). For VBBA the intended source of truth is achData.currentStep; the gap is that partial, unsubmitted step data has no backing position, so preserving the draft is what closes it.

Because entered values already flow into the persisted *_FORM_DRAFT Onyx keys, simply not wiping them on dismiss restores both the field data and (via the existing startFrom reconstruction) the wizard position.

What alternative solutions did you explore? (Optional)

Explicitly persisting a dedicated "current step" Onyx draft key per flow would also work, but it's redundant given the existing getInitialSubStepFor* reconstruction — the minimal fix is to keep the draft rather than add new state.

Confidence & verification notes
  • Confidence: High. This is a deterministic client-side lifecycle bug fully explained by the code; production logs would not add signal. If desired, browser verification (drive Wallet → enter a step → dismiss → re-enter, inspecting the PERSONAL_BANK_ACCOUNT_FORM_DRAFT / REIMBURSEMENT_ACCOUNT_FORM_DRAFT Onyx keys before/after) would confirm the clear-on-dismiss behavior.
  • Alternative considered & ruled out: "data is intentionally not persisted." Rejected — the Expected Result explicitly states progress should be saved, and the drafts are written during the flow; they're only lost to the unmount cleanup.
  • One nuance: steps whose data was already submitted to the backend (e.g. BankInfo via connectBankAccountManually) can rehydrate from the server; the clearly-lost data is anything typed but not yet submitted.

No obvious duplicate open issue found in a quick scan of Expensify/App.


Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/95279) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.

MelvinBot avatar Jul 03 '26 13:07 MelvinBot

Proposal

Please re-state the problem that we are trying to solve in this issue.

Closing the bank-account setup modal after completing one or more steps loses the entered data, so reopening the flow starts from the beginning instead of resuming progress.

What is the root cause of that problem?

AccountFlowEntryPoint in src/pages/settings/Wallet/InternationalDepositAccount/subPages/AccountFlowEntryPoint.tsx calls clearPersonalBankAccount() unconditionally on mount. Additionally, AddPersonalBankAccountPage in src/pages/AddPersonalBankAccountPage.tsx registers the same action as an unmount cleanup. Therefore, dismissing and reopening the modal clears the Onyx-backed draft before PersonalInfoPage can restore its values and determine the appropriate step.

What changes do you think we should make in order to solve the problem?

Remove the unconditional mount/unmount clearing from AccountFlowEntryPoint and AddPersonalBankAccountPage. Preserve the existing draft when the modal is dismissed, and clear it only after successful completion or when the user explicitly starts over. This lets the existing draft-backed form and step-selection logic restore the entered values and resume at the first incomplete step.

Add a regression test that enters data, dismisses the modal, reopens the flow, and verifies that the saved values and current progress are restored.

What alternative solutions did you explore? (Optional)

Persisting a separate route index was considered, but it is unnecessary because the flow already stores draft values and can derive the correct step from them; the draft is simply being cleared at the wrong lifecycle transitions.

kitvasyl avatar Jul 03 '26 13:07 kitvasyl

Note: This isn't a duplicate — the proposal it was flagged against was posted before the Help Wanted label (2026-07-03T13:45:51Z, before 2026-07-03T13:45:57Z), so it isn't a valid earlier proposal.

Proposal

What is the root cause of that problem?

Both flows already auto-save progress as Onyx form drafts and can resume from them — e.g. the personal deposit flow computes its starting sub-step from the saved draft:

https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/InternationalDepositAccount/InternationalDepositAccountContent.tsx#L93

The draft survives dismissing the RHP. Progress is lost only because the entry points wipe the drafts every time they are used, so re-entering the flow always starts from scratch:

  • Personal deposit account: openPersonalBankAccountSetupView (the only way in from Wallet / the purpose page) unconditionally calls clearInternationalBankAccount() (nulls the international form draft and CORPAY_FIELDS) and then nulls PERSONAL_BANK_ACCOUNT and its form draft before navigating:

https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/libs/actions/BankAccounts.ts#L139

https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/libs/actions/BankAccounts.ts#L155-L157

  • Business bank account: on the country-selection step, onConfirm unconditionally calls clearReimbursementAccount() and clearReimbursementAccountDraft() before navigating, wiping the saved reimbursement-account draft the user must pass through to re-enter:

https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/BankAccountPurposePage/substeps/CountrySelection.tsx#L64-L73

So the causal chain is: user exits the modal → draft is still in Onyx → user re-enters through these entry points → entry point resets the drafts to null → the resume logic (getInitialSubstep / ReimbursementAccountPage's draft-based step restore) sees an empty draft → flow restarts at step one.

What changes do you think we should make in order to solve the problem?

Make the entry points non-destructive, since the flows already clean up after themselves — the personal flow clears its drafts on finish and when the user backs out of the first page (handleFinishStep / handleBackButtonPress in InternationalDepositAccountContent):

https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/InternationalDepositAccount/InternationalDepositAccountContent.tsx#L123-L127

  1. In openPersonalBankAccountSetupView, only clear when there is no in-progress draft: read the existing INTERNATIONAL_BANK_ACCOUNT_FORM_DRAFT; if it has values, skip clearInternationalBankAccount() and the Onyx.set(..., null) calls (keeping the merge of exitReportID/policyID/source context) so getInitialSubstep resumes at the saved step.

  2. In CountrySelection.onConfirm, only call clearReimbursementAccount()/clearReimbursementAccountDraft() when the selected country differs from the country already stored in the reimbursement-account draft (a genuine restart); when it matches, just navigate so the existing draft/achData resume logic in ReimbursementAccountPage kicks in.

What alternative solutions did you explore? (Optional)

Instead of skip-if-draft-exists, show a "Continue setup / Start over" prompt on re-entry (the pattern ReimbursementAccountPage already uses via its continue-setup button) and only clear the drafts when the user picks "Start over". Slightly more UX work, but makes the reset explicit.

lorretheboy avatar Jul 03 '26 13:07 lorretheboy

Proposal

Please re-state the problem that we are trying to solve in this issue.

When a user starts adding a business bank account or personal deposit account from Wallet, fills in a screen, and then exits the modal (e.g. by clicking outside it) instead of finishing the flow, their progress is lost. Re-entering the flow always restarts from the very first step instead of resuming where they left off.

What is the root cause of that problem?

ReimbursementAccountPage.tsx is the shell for both the USD and non-USD bank account setup flows opened from Wallet. It determines which step to show on load by reading achData.currentStep from Onyx — this is what's supposed to let the flow resume after the modal is reopened.

However, the component has an unmount cleanup effect that unconditionally wipes both the saved step and the entire form draft, and this effect fires on every unmount, including the ordinary case where the user just closes the RHP modal or navigates away mid-flow without finishing or explicitly asking to start over. https://github.com/Expensify/App/blob/abfc508f4e6324639594c671533cfcb999946930/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx#L160-L166

clearReimbursementAccountDraft() does a hard Onyx.set (not merge) of the form draft to {}, erasing every field the user typed, and clearReimbursementAccount() resets achData back to its default ({state: 'SETUP'}), which deletes achData.currentStep — the exact value getInitialCurrentStep() relies on to resume. https://github.com/Expensify/App/blob/abfc508f4e6324639594c671533cfcb999946930/src/libs/actions/ReimbursementAccount/index.ts#L38-L44

Because achData.currentStep no longer exists after the unmount cleanup runs, getInitialCurrentStep() falls back to CONST.BANK_ACCOUNT.STEP.COUNTRY on the next visit, so the flow always restarts from scratch even though the intent of this code (per its own comment) was to resume from the saved step. https://github.com/Expensify/App/blob/abfc508f4e6324639594c671533cfcb999946930/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx#L143-L156

Resetting the draft/account data is already handled correctly and explicitly elsewhere in the codebase for the cases where it's actually meant to happen — e.g. when the user changes the setup country/currency in CountrySelection.tsx, and via the dedicated requestResetBankAccount/resetUSDBankAccount/resetNonUSDBankAccount actions for an explicit "start over" request. The blanket clear-on-unmount in ReimbursementAccountPage.tsx duplicates that intent unconditionally and destroys legitimate in-progress data.

What changes do you think we should make in order to solve the problem?

Remove the unconditional clearing of the draft and ACH data from the page's unmount cleanup, since progress should persist across mount/unmount by default. Resetting for the currency/country-change case and the explicit "reset bank account" case is already handled elsewhere and is unaffected by this change.

https://github.com/Expensify/App/blob/abfc508f4e6324639594c671533cfcb999946930/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx#L160-L166

useEffect(() => {
    return () => {
        getPaymentMethods();
    };
}, []);

With the draft and achData.currentStep no longer wiped on modal close, re-entering the flow will correctly resume via the existing getInitialCurrentStep() logic and the previously entered form field values will still be present in ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM_DRAFT.

abbasifaizan70 avatar Jul 03 '26 13:07 abbasifaizan70

🚨 Edited by proposal-police: This proposal was edited at 2026-07-03 14:00:53 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

When you open the Wallet and start adding a deposit bank account, enter something on one of the screens, then dismiss the flow and come back, you land on the very first screen again instead of where you left off. Your progress looks lost even though most of it was actually saved.

What is the root cause of that problem?

There are two separate flows behind this and they behave differently, which is why the report is a little slippery.

The personal-info portion already restores correctly. Each SubStep input writes to the wallet draft on every keystroke, and on re-entry PersonalInfo.tsx:69 calls getInitialSubstepForPersonalInfo(values) to jump you back to the first incomplete substep. The draft is only cleared at completion, not on dismiss. So legal name / DoB / address / phone / SSN all come back.

The part that drops you is the "add bank account" step at the front of the flow. In EnablePayments.tsx:115 the visible step is forced to ADD_BANK_ACCOUNT whenever !hasExpensifyPaymentMethod(paymentCardList, bankAccountList, hasActivatedWallet). That helper (PaymentUtils.ts) only returns true once there is an open US personal bank account server-side, so on every re-entry before the account is fully added it snaps you back to ADD_BANK_ACCOUNT. From there AddBankAccount.tsx uses startFrom: isBankAccountAlreadyAdded ? confirmationPageIndex : 0, and index 0 is SetupMethod, which just relaunches Plaid (openPersonalBankAccountSetupWithPlaid). Plaid is external OAuth, not a resumable form draft, so there is genuinely nothing to restore at that screen and it always looks like a fresh start.

One caveat worth being honest about: PR #92779 (v9.4.19) refactored this flow specifically to persist and restore progress, so which exact screen a tester sees "reset" depends on how far they got. I want to confirm the precise dropped screen on a live build before locking the fix, since a static read of the personal substeps shows them restoring.

What changes do you think we should make in order to solve the problem?

Give the front ADD_BANK_ACCOUNT step the same draft-based resume the personal-info step already has, so the redirect doesn't yank a user out of a step they were mid-way through. Concretely, gate the forced ADD_BANK_ACCOUNT redirect in EnablePayments.tsx (and the startFrom: 0 in AddBankAccount.tsx) on whether there's in-progress draft state for that step, rather than only on hasExpensifyPaymentMethod returning true after the server marks the account open. The pattern to follow is the one already in getInitialSubstepForPersonalInfo — derive the resume point from the draft instead of from server-confirmed completion. I'd pin the exact screen with a repro first, then apply the minimal guard there.

What alternative solutions did you explore? (Optional)

I considered treating this as "the draft is never saved in the forward flow" (submit hook gated on isEditing), but the per-input shouldSaveDraft save already covers that, so it's not the cause. I also looked at "the draft is wiped on exit" — it isn't, the reset only fires at completion in the FeesAndTerms step. The business bank account (VBA) flow is a separate server-driven path that restores from achData.currentStep, so it needs its own check if it turns out to reset too.

shivang-goliyan avatar Jul 03 '26 13:07 shivang-goliyan

🚨 Edited by proposal-police: This proposal was edited at 2026-08-24 11:08:21 UTC.

Proposal

What is the root cause of that problem?

Wallet re-entry is treated as a fresh bank-account setup. Multiple reset points clear the draft and navigation state needed to resume an unfinished flow.

For business bank accounts, Wallet sends Workspace Admins through the bank-account-purpose flow [WalletPage/index.tsx#L264-L274](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/pages/settings/Wallet/WalletPage/index.tsx#L264-L274). After “Make payments” is selected, CountrySelection.onConfirm() unconditionally clears REIMBURSEMENT_ACCOUNT and REIMBURSEMENT_ACCOUNT_FORM_DRAFT [CountrySelection.tsx#L66-L76](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/pages/settings/Wallet/BankAccountPurposePage/substeps/CountrySelection.tsx#L66-L76). ReimbursementAccountPage clears the same state again when the RHP unmounts [ReimbursementAccountPage.tsx#L184-L194](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx#L184-L194). Consequently, clicking outside the RHP is handled like abandoning the setup.

The standalone Wallet business route also lacks the identity used by the Workspace flow to reload backend progress. It calls navigateToBankAccountRoute() without a policyID or bankAccountID [CountrySelection.tsx#L71-L75](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/pages/settings/Wallet/BankAccountPurposePage/substeps/CountrySelection.tsx#L71-L75). The generated route can contain backTo, but no account-identifying parameter [ROUTES.ts#L1940-L1955](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/ROUTES.ts#L1940-L1955), and ReimbursementAccountPage.fetchData() returns early when both identifiers are absent [ReimbursementAccountPage.tsx#L245-L260](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx#L245-L260). After the local state is cleared, the Wallet route cannot recover it from the backend.

The personal flow has additional reset points. Wallet calls openPersonalBankAccountSetupView() [BankAccountPurpose.tsx#L30-L36](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/pages/settings/Wallet/BankAccountPurposePage/substeps/BankAccountPurpose.tsx#L30-L36), which clears Plaid state, Corpay fields, INTERNATIONAL_BANK_ACCOUNT_FORM_DRAFT, PERSONAL_BANK_ACCOUNT, and PERSONAL_BANK_ACCOUNT_FORM_DRAFT before navigating [BankAccounts.ts#L105-L169](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/libs/actions/BankAccounts.ts#L105-L169).

The US personal flow clears the state a second time in AccountFlowEntryPoint [AccountFlowEntryPoint.tsx#L47-L61](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/pages/settings/Wallet/InternationalDepositAccount/subPages/AccountFlowEntryPoint.tsx#L47-L61). Runtime testing showed this reset executes while PERSONAL_BANK_ACCOUNT is loaded but PERSONAL_BANK_ACCOUNT_FORM_DRAFT is still loading, exposing a hydration race.

Preserving the US draft alone would not restore the correct page. AddPersonalBankAccountPage does not pass startFrom to useSubPage() [AddPersonalBankAccountPage/index.tsx#L144-L158](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/pages/AddPersonalBankAccountPage/index.tsx#L144-L158), so a route without subPage defaults to page 0 [useSubPage/index.tsx#L15-L34](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/hooks/useSubPage/index.tsx#L15-L34). Testing confirmed that manual and Plaid flows dismissed at phone-number reopened at manual and plaid.

Values entered on the active page may also be lost before Next is pressed. For example, AddressStep defaults shouldSaveDraft to false and copies the address to the personal-bank-account draft only on submission [AddressStep.tsx#L35-L42](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/pages/AddPersonalBankAccountPage/substeps/AddressStep.tsx#L35-L42) [AddressStep.tsx#L114-L145](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/pages/AddPersonalBankAccountPage/substeps/AddressStep.tsx#L114-L145). Restoring the page without preserving its active form values would therefore only partially fix the issue.

The international personal flow already calculates its resume page from the draft and Corpay field definitions [InternationalDepositAccountContent.tsx#L86-L99](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/pages/settings/Wallet/InternationalDepositAccount/InternationalDepositAccountContent.tsx#L86-L99). Testing confirmed it advanced to startFrom: 4, but returned to startFrom: 0 after the opener cleared its state.

Refetching Corpay fields during resume would also clear the preserved draft unless adjusted: fetchCorpayFields() currently uses Onyx.METHOD.SET to replace INTERNATIONAL_BANK_ACCOUNT_FORM_DRAFT with only country and currency [BankAccounts.ts#L1496-L1528](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/libs/actions/BankAccounts.ts#L1496-L1528). In addition, getInitialSubstep() returns page 0 while the Corpay field map is empty [utils.ts#L117-L133](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/pages/settings/Wallet/InternationalDepositAccount/utils.ts#L117-L133), so route initialization must wait until both the draft and field definitions are ready.

What changes do you think we should make in order to solve the problem?

Introduce an explicit Wallet resume mode instead of using the same destructive initialization for every entry. Store minimal non-sensitive metadata with the active draft: Wallet origin, personal/business purpose, country/currency, personal setup type, current page, and policyID/bankAccountID when available. Resume only when this metadata matches the unfinished Wallet setup; otherwise start fresh.

When Wallet detects a compatible unfinished setup, it should navigate directly to it or display a clear Continue setup action. Successful completion, confirmed Start over, explicit abandonment, or selecting an incompatible purpose, country, currency, workspace, or account should clear the previous draft.

For business accounts:

  • Make the ReimbursementAccountPage unmount cleanup conditional so incidental RHP dismissal and intermediate back navigation preserve a matching Wallet setup.
  • Reuse the preserved policyID or bankAccountID when available so backend-synchronized progress can be fetched.
  • Preserve early local progress when no backend identifier exists yet.
  • In CountrySelection.onConfirm(), clear only when the selected context differs from the preserved setup.
  • Resume USD accounts from achData.currentStep and non-USD accounts through getStartPageForContinueSetup() [getStartPageForContinueSetup.ts#L21-L96](https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/pages/ReimbursementAccount/NonUSD/utils/getStartPageForContinueSetup.ts#L21-L96).

For US personal accounts:

  • Add a shouldPreserveExistingSetup option to openPersonalBankAccountSetupView() and enable it for Wallet re-entry and its verification continuation.
  • Make the AccountFlowEntryPoint reset conditional and wait for the personal draft, resume metadata, and relevant Plaid state to hydrate before deciding whether to clear.
  • Replace entry-specific metadata such as exitReportID, policyID, source, and onSuccessFallbackRoute with the current context instead of retaining stale destinations.
  • Persist the resolved current subpage on every navigation change, excluding the success page.
  • Use a valid URL subpage first, then the saved subpage, and finally a draft-derived startFrom fallback.
  • Audit active forms and save current-page values while editing, including the address form, so dismissal before Next does not lose them.

For international personal accounts:

  • Preserve the compatible INTERNATIONAL_BANK_ACCOUNT_FORM_DRAFT.
  • Add a resume mode to fetchCorpayFields() that refetches field definitions without replacing the existing draft.
  • Keep the loading screen visible until both the draft and refetched fields are ready.
  • Only then run getInitialSubstep() and initialize useSubPage().
  • Continue using the existing destructive behavior when the selected country changes.

Plaid and other sensitive draft data should be retained only for the matching unfinished Wallet setup and cleared after completion, Start over, explicit abandonment, logout/account changes, or setup mismatch. If a required RAM-only Plaid session is unavailable after a cold start, return to the Plaid connection page while retaining compatible non-token progress.

The meaningful difference from earlier proposals is that this covers every confirmed reset and resume failure: business country/unmount cleanup, the personal opener, the second US entry-point reset, the hydration race, active-page values before Next, exact US subpage restoration, destructive Corpay refetch, and hydration-gated international resume.

What alternative solutions did you explore? (Optional)

I considered fixing the business route only by supplying a policyID or bankAccountID. That would improve backend recovery but would not preserve early local progress or fix the country-selection and unmount clears.

I considered changing only openPersonalBankAccountSetupView(). That would leave the second reset and hydration race in AccountFlowEntryPoint, would not restore the US subpage, and would not protect the international draft from fetchCorpayFields().

I considered deriving the US page only from completed fields. That can select the wrong page when fields are prefilled or the active page has not been submitted. Persisting the current page and using draft derivation only as fallback is deterministic.

A fully server-synchronized personal draft would support cross-device resume but requires new backend commands and a product/security decision. The reported Wallet dismissal behavior can be fixed in the App by preserving one compatible active Wallet draft and clearing it at explicit lifecycle boundaries.

Fixed Demo:

part 1:

https://github.com/user-attachments/assets/388f7015-d5ce-4a21-9803-2bbe2d878b40

part 2:

https://github.com/user-attachments/assets/be10ec1e-dd50-4d71-834a-3f4db9af42e3

nabi-ebrahimi avatar Jul 03 '26 13:07 nabi-ebrahimi

Please re-state the problem that we are trying to solve in this issue.

On Web (Windows Chrome, macOS Chrome/Safari), when a user opens Wallet → Add a bank account (personal deposit or business), fills in one or more screens, and then exits the RHP modal by clicking outside it, all previously entered data is lost. On re-entering the flow the user starts from the first step with empty fields. Expected: the progress they entered should persist and the flow should resume where they left off.

What is the root cause of that problem?

There are two independent reset points that together guarantee the draft is always wiped on re-entry:

Reset 1 — unmount cleanup in the page component. src/pages/AddPersonalBankAccountPage.tsx:62 registers useEffect(() => clearPersonalBankAccount, []). The return value of that effect is clearPersonalBankAccount itself (used as the cleanup function), so every time the modal is dismissed — including mid-flow abandons — clearPersonalBankAccount (src/libs/actions/BankAccounts.ts:324-329) runs and calls Onyx.set(ONYXKEYS.PERSONAL_BANK_ACCOUNT, null) plus Onyx.set(ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM_DRAFT, null), wiping whatever the substeps had written via updateAddPersonalBankAccountDraft.

Reset 2 — unconditional wipe in the flow entry action. Even if Reset 1 were removed, re-entering the flow calls openPersonalBankAccountSetupView (src/libs/actions/BankAccounts.ts:131-168). That function always executes:

Onyx.set(ONYXKEYS.PERSONAL_BANK_ACCOUNT, Object.keys(personalBankAccountState).length > 0 ? personalBankAccountState : null);
Onyx.set(ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM_DRAFT, null);

The comment in the source explicitly states: "Use set instead of merge so each new flow starts with only the fields we explicitly pass, not leftover fields from a previous flow." This means every navigation into the flow unconditionally discards any in-progress draft — regardless of whether the unmount effect fires.

Both resets must be addressed; fixing only one still loses all progress.

What changes do you think we should make in order to solve the problem?

Change 1 — Guard the unmount cleanup in AddPersonalBankAccountPage.

src/pages/AddPersonalBankAccountPage.tsx:62 must not clear state on a mid-flow dismiss. The cleanup should only run when the flow is truly abandoned (no success shown, no explicit continue). Gate it on shouldShowSuccess:

// Before (line 62):
useEffect(() => clearPersonalBankAccount, []);

// After:
useEffect(() => {
    return () => {
        if (!personalBankAccount?.shouldShowSuccess) {
            // Do NOT clear here — let draft persist for re-entry.
            // Explicit abandonment clears via exitFlow → clearPersonalBankAccount.
        }
    };
}, [personalBankAccount?.shouldShowSuccess]);

The simplest minimal change is to remove the cleanup return value entirely from the effect:

useEffect(() => {
    // Intentionally empty — cleanup on explicit exit is handled by exitFlow and
    // the success paths in FeesAndTerms / AddBankAccount / AccountFlowEntryPoint.
}, []);

Explicit success paths already call clearPersonalBankAccount directly: exitFlow at line 58, completion paths in FeesAndTerms.tsx:41, AddBankAccount.tsx:119. Those are unaffected by removing the unmount cleanup.

Change 2 — Preserve an in-progress draft in openPersonalBankAccountSetupView.

src/libs/actions/BankAccounts.ts:131-168 must distinguish a resume (user returning mid-flow) from a fresh start (no prior draft or explicit new-flow intent). The simplest approach: check whether a form draft already exists before wiping it.

function openPersonalBankAccountSetupView({
    exitReportID,
    policyID,
    source,
    shouldSetUpUSBankAccount = false,
    isUserValidated = true,
    onSuccessFallbackRoute,
    forceReset = false,  // pass true from explicit "start over" entry points
}: OpenPersonalBankAccountSetupViewProps) {
    clearInternationalBankAccount().then(() => {
        const personalBankAccountState: Partial<PersonalBankAccount> = {};
        // ... build personalBankAccountState as before ...

        // Only reset the draft when this is an explicit new flow, not a resume.
        if (forceReset || Object.keys(personalBankAccountState).length === 0) {
            Onyx.set(ONYXKEYS.PERSONAL_BANK_ACCOUNT, personalBankAccountState ?? null);
            Onyx.set(ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM_DRAFT, null);
        } else {
            // Merge routing/context fields without destroying the form draft.
            Onyx.merge(ONYXKEYS.PERSONAL_BANK_ACCOUNT, personalBankAccountState);
        }
        // ... navigation as before ...
    });
}

Call sites that intend to start a fresh flow (e.g. a "change bank account" action that explicitly replaces an existing account) should pass forceReset: true. The default Wallet → Add Bank Account path passes no extra parameters and will preserve any existing draft.

Change 3 — Verify the business-account sibling.

Confirm that src/pages/EnablePayments/Wallet/AddBankAccount/AddBankAccount.tsx does not register an equivalent unconditional unmount clear. If it does, apply the same guard from Change 1. The business account flow uses different Onyx keys but the pattern is identical.

Change 4 — Stale-draft edge case.

If a user abandons the flow and later explicitly starts a fresh one, the old draft will be preserved by default under Change 2. To handle this, expose a "Start over" affordance within the flow (e.g. a button or menu option on the first step when a draft is detected) that calls clearPersonalBankAccount() then re-enters with forceReset: true. This is preferable to eagerly clearing on every entry.

Change 5 — Regression verification.

Manual verification steps:

  1. Enter data on at least two substeps → dismiss modal by clicking outside → re-open Wallet → Add bank account → confirm fields are pre-populated and substep index is preserved.
  2. Complete the flow successfully → re-open → confirm a fresh empty form (success path correctly cleared via exitFlow).
  3. Abandon mid-flow → tap "Start over" (if exposed) → confirm a fresh form.
  4. Open a second flow from a different entry point (e.g. from a report) → confirm no stale draft from a prior personal-wallet flow bleeds in.

What alternative solutions did you explore? (Optional)

Session storage / local persistence. Storing draft state in AsyncStorage or sessionStorage independently of Onyx would avoid the reset-on-entry problem but adds a second source of truth and complicates the success-path cleanup. Not recommended.

Delay the clear until navigation settles. Wrapping clearPersonalBankAccount in a setTimeout inside the unmount effect could race the re-entry navigation but is inherently fragile and doesn't address the openPersonalBankAccountSetupView reset at all.

Guard only on shouldShowSuccess. The original unmount cleanup could be converted to if (shouldShowSuccess) clearPersonalBankAccount() to only clear after a confirmed success. This is cleaner than removing the effect entirely but still doesn't address Reset 2 in openPersonalBankAccountSetupView, so it must be paired with Change 2.

aswin-s avatar Jul 03 '26 13:07 aswin-s

🚨 Edited by proposal-police: This proposal was edited at 2026-07-03 13:49:29 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

When adding a bank account from Wallet (business or personal deposit), dismissing the modal mid-flow loses all entered progress. Re-entering restarts from the beginning instead of resuming.

What is the root cause of that problem?

Both flows already persist progress in Onyx drafts as you type, and both already contain working resume logic. The structural bug: the Wallet entry/exit points treat every entry as a brand-new flow and unconditionally destroy that persisted state. There are three wipe sites:

  1. Business flow — wiped at dismissal. ReimbursementAccountPage clears the draft and local account state in its unmount cleanup, so the moment the RHP closes, progress is gone: https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx#L160-L166 — the same page that resumes via achData?.currentStep (https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx#L154) and has a "continue setup" path (hasInProgressVBBA, https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx#L197-L199).

  2. Business flow — wiped again at re-entry. The purpose page's country step clears everything on every Next press, even when the selected country matches the in-progress draft: https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/BankAccountPurposePage/substeps/CountrySelection.tsx#L64-L72 calls clearReimbursementAccount() + clearReimbursementAccountDraft() (https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/libs/actions/ReimbursementAccount/index.ts#L38-L44).

  3. Personal deposit flow — wiped at re-entry. "Get reimbursed" calls openPersonalBankAccountSetupView({}) (https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/BankAccountPurposePage/substeps/BankAccountPurpose.tsx#L35), which always runs clearInternationalBankAccount() — nulling CORPAY_FIELDS and INTERNATIONAL_BANK_ACCOUNT_FORM_DRAFT — then nulls PERSONAL_BANK_ACCOUNT_FORM_DRAFT: https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/libs/actions/BankAccounts.ts#L131-L157. Dismissing this flow itself preserves the draft (it clears only on finish or back-from-first-page), and resume is fully built: getInitialSubstep walks the draft to the first incomplete page (https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/InternationalDepositAccount/utils.ts#L117-L134) and feeds startFrom (https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/InternationalDepositAccount/InternationalDepositAccountContent.tsx#L93) — but it always receives an empty draft because the entry point just erased it.

This explains every detail: "any screen you've entered information on" (drafts save per keystroke, then get bulk-wiped), both flows (each has its own wipe site), all platforms (shared TS code).

What changes do you think we should make in order to solve the problem?

Make each wipe conditional on "the context actually changed" instead of firing on every entry/exit:

  1. ReimbursementAccountPage.tsx#L160-L166: remove the two clear calls from the unmount cleanup (keep getPaymentMethods()). To keep its cross-workspace hygiene, clear on mount only when the loaded account belongs to a different policy — the page already computes that signal, isPreviousPolicy (https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx#L139).

  2. CountrySelection.tsx (purpose page): skip the clears when the draft already targets the selected country, and preselect it:

const [draft] = useOnyx(ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM_DRAFT);
const onConfirm = () => {
    if (draft?.country === selectedCountry) { // in-progress flow → resume
        navigateToBankAccountRoute({backTo: ROUTES.SETTINGS_BANK_ACCOUNT_PURPOSE});
        return;
    }
    // existing clear + seed + navigate (unchanged) for a new/changed country
};

ReimbursementAccountPage then resumes from achData.currentStep and the draft.

  1. BankAccounts.ts openPersonalBankAccountSetupView: when INTERNATIONAL_BANK_ACCOUNT_FORM_DRAFT already holds user data (module-scope Onyx.connect, the standard actions pattern), skip clearInternationalBankAccount() and the form-draft nulls, but keep the Onyx.set(ONYXKEYS.PERSONAL_BANK_ACCOUNT, ...) context reset. getInitialSubstep then resumes at the first incomplete page, and CORPAY_FIELDS survives so fieldsMap is populated. This single convergence point fixes all five callers (BankAccountPurpose, WalletPage, ChooseTransferAccountPage, BaseKYCWall, ReimbursementQueuedContent).

Regression safety: the intentional clears on finish and explicit back-out (InternationalDepositAccountContent.tsx#L124/#L149), the workspace "Start over" reset, and the per-entry PERSONAL_BANK_ACCOUNT context reset from the KYC fix in PR #92154 are untouched, so completed or explicitly-abandoned flows still start fresh.

Why the obvious spot-fix fails: deleting the clears in CountrySelection.onConfirm (the natural grep hit) does nothing — the unmount cleanup at ReimbursementAccountPage.tsx#L160-L166 already destroyed the draft the moment the modal was dismissed, so there is nothing left to resume; and it leaves the personal deposit path untouched, whose draft is erased at entry by openPersonalBankAccountSetupView. All three wipe sites must be covered or the symptom persists on at least one path.

What alternative solutions did you explore? (Optional)

  • Patch only one flow: incomplete — the issue reproduces on both, and the business flow alone has two independent wipe sites.
  • A "Continue setup / Start over" prompt on BankAccountPurposePage when a draft exists, mirroring the workspace continue-setup button: nicer UX, can layer on top, but still requires stopping the wipes above.
  • Resume from server-side achData only: fails for mid-step data (fields entered but not yet submitted live only in the local draft) and the international flow has no server-side progress until final submit.

ahmdshrif avatar Jul 03 '26 13:07 ahmdshrif

🚨 Edited by proposal-police: This proposal was edited at 2026-07-03 14:32:04 UTC.

Proposal

What is the root cause of that problem?

Wallet treats ordinary add-bank-account re-entry as a new setup and clears the Onyx state that the setup forms use to resume progress.

For personal deposit accounts, openPersonalBankAccountSetupView() first clears Plaid/Corpay/international-bank-account draft state, then replaces PERSONAL_BANK_ACCOUNT and sets PERSONAL_BANK_ACCOUNT_FORM_DRAFT to null before navigating to the add-bank-account route. https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/libs/actions/BankAccounts.ts#L111-L167

Wallet calls that helper directly for non-admin Add bank account presses, and the Bank account purpose page calls it for the Get reimbursed option, so re-entering through Wallet deletes the saved setup type and any draft personal-account data. https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/WalletPage/index.tsx#L261-L270 https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/BankAccountPurposePage/substeps/BankAccountPurpose.tsx#L31-L36

The personal entry page also calls clearPersonalBankAccount() on mount after Onyx loads, and that helper clears PERSONAL_BANK_ACCOUNT_FORM_DRAFT, so direct navigation back to the entry screen is another reset path. https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/InternationalDepositAccount/subPages/AccountFlowEntryPoint.tsx#L52-L61 https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/libs/actions/BankAccounts.ts#L329-L333

For business bank accounts, dismissing the modal unmounts ReimbursementAccountPage, and its cleanup always clears both REIMBURSEMENT_ACCOUNT_FORM_DRAFT and REIMBURSEMENT_ACCOUNT. That removes the saved current step and entered data before the user even re-enters the flow. https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx#L160-L166

The Wallet country-confirmation path then clears the same business-bank state again before routing to the reimbursement account flow, while the reimbursement account opener only preserves draft/current-step data when called with shouldPreserveDraft. https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/BankAccountPurposePage/substeps/CountrySelection.tsx#L64-L72 https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx#L217-L240 https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/libs/actions/BankAccounts.ts#L1253-L1312

Those reset paths are why users land back at the initial purpose/country/account-detail screens instead of the step shown before dismissal, even though the personal and reimbursement bank-account substeps already save draft values. https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/InternationalDepositAccount/PersonalInfo/substeps/ManualBankAccountDetailsStep.tsx#L56-L93 https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/ReimbursementAccount/USD/BankInfo/subSteps/Manual.tsx#L61-L100

What changes do you think we should make in order to solve the problem?

Make Wallet bank-account setup distinguish resume from reset.

For personal deposit accounts, add a resume path for Wallet re-entry that navigates to the existing personal add-bank-account route without calling clearInternationalBankAccount(), clearPersonalBankAccount(), or nulling PERSONAL_BANK_ACCOUNT_FORM_DRAFT when a personal/international bank-account draft is present. Keep an explicit fresh-start/reset path for first entry with no draft, successful completion, first-screen back-out/start-over, and flows that intentionally need a clean setup.

Guard the mount-time clear in AccountFlowEntryPoint so it only runs for explicit fresh-start/direct-reset intents, not ordinary Wallet re-entry.

For business bank accounts, stop clearing REIMBURSEMENT_ACCOUNT and REIMBURSEMENT_ACCOUNT_FORM_DRAFT on ordinary modal dismissal. Reserve that clear for successful completion, explicit reset/start-over, or choosing a genuinely new setup/country before any saved progress should be resumed.

When Wallet opens an in-progress business-bank flow, route directly to the reimbursement account flow with the current step/substep/draft preserved instead of sending the user back through the purpose/country path that clears state. The existing shouldPreserveDraft and local current-step plumbing can be reused or extended for this Wallet resume intent.

Test coverage:

  • Update the existing openPersonalBankAccountSetupView tests to cover both explicit reset and Wallet resume behavior, verifying that resume does not clear PERSONAL_BANK_ACCOUNT_FORM_DRAFT or INTERNATIONAL_BANK_ACCOUNT_FORM_DRAFT.
  • Update the country-selection tests to verify that ordinary business-bank resume does not call clearReimbursementAccount() or clearReimbursementAccountDraft(), while explicit new setup/reset still clears them.
  • Add a regression test for dismissing and re-entering the Wallet personal deposit flow after entering manual account details, asserting that the same step and draft values are restored.
  • Add a regression test for dismissing and re-entering the Wallet business bank account flow after entering account details, asserting that the reimbursement account route opens from the saved current step instead of the purpose/country start.

What alternative solutions did you explore? (Optional)

I considered only storing the last modal route before dismissal, but that would not restore field values once the flow cleanup clears the drafts. The safer fix is to preserve the existing Onyx draft/current-step state for ordinary dismissal/re-entry and keep clears limited to explicit reset or completion paths.

KJ21-ENG avatar Jul 03 '26 13:07 KJ21-ENG

Triggered auto assignment to Contributor-plus team member for initial proposal review - @mkhutornyi (External)

melvin-bot[bot] avatar Jul 03 '26 13:07 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

Progress not saved when moving through the screens to add banking information in Wallet

What is the root cause of that problem?

I traced this to the path that handles the issue-specific state:

  • src/pages/workspace/expensifyCard/WorkspaceExpensifyCardVerifyWorkAccountPage.tsx:29 (WorkspaceExpensifyCardVerifyWorkAccountPage): type WorkspaceExpensifyCardVerifyWorkAccountPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.EXPENSIFY_CARD_VERIFY_WORK_EMAIL>;
  • src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx:42 (WorkspaceExpensifyCardBankAccounts): type WorkspaceExpensifyCardBankAccountsProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.EXPENSIFY_CARD_BANK_ACCOUNT>;
  • src/pages/workspace/expensifyCard/WorkspaceExpensifyCardAddWorkEmailPage.tsx:45 (WorkspaceExpensifyCardAddWorkEmailPage): type WorkspaceExpensifyCardAddWorkEmailPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.EXPENSIFY_CARD_ADD_WORK_EMAIL>;
  • The local evidence matches this recurring failure shape: NewDot and OldDot read different default account/card fields. Here, src/pages/workspace/expensifyCard/WorkspaceExpensifyCardVerifyWorkAccountPage.tsx:29 and src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx:42 do not agree on the same the issue-specific state value, so the user-visible path can show a missing or stale state even though nearby data already has the needed context.

What changes do you think we should make in order to solve the problem?

  • Update src/pages/workspace/expensifyCard/WorkspaceExpensifyCardVerifyWorkAccountPage.tsx:29 to derive the issue-specific state from the card/accounting data source that owns this flow before the value is consumed.
  • Carry the same normalized value through src/pages/workspace/expensifyCard/WorkspaceExpensifyCardBankAccounts.tsx:42; that follows the safer family move to add fallback at the export/mapping layer, so the write/optimistic/read paths agree instead of only changing the visible component.
  • Keep the change inside the Payments, Wallet, Bank, Billing, Cards surface and avoid changing money movement, bank/card/account settings.

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

  1. Add or update a regression in tests/unit/Payment*.ts for the exact issue flow: Progress not saved when moving through the screens to add banking information in Wallet.
  2. Cover the counter-case near src/pages/workspace/expensifyCard/WorkspaceExpensifyCardVerifyWorkAccountPage.tsx:29 so valid existing the issue-specific state behavior still works.
  3. Manually repeat the issue steps after the patch and confirm the visible state/action is no longer stale.

What alternative solutions did you explore? (Optional)

  • I would not add a broad new condition outside these referenced paths; the safer fix is to keep the issue-specific state consistent at the first read/write boundary shown above.

Job added to Upwork: https://www.upwork.com/jobs/~022073040575320684584

melvin-bot[bot] avatar Jul 03 '26 13:07 melvin-bot[bot]

⚠️ @lorretheboy Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

github-actions[bot] avatar Jul 03 '26 13:07 github-actions[bot]

Proposal

What is the root cause of that problem?

When a user opens Wallet and starts adding a personal deposit account or a business bank account, they move through a set of sub screens (name, address, verification, and so on). The field values a user types are saved automatically by FormProvider into Onyx draft keys, so the entered data itself is not really lost.

What is actually lost is the user's position in the multi step flow. Both wallet bank account flows drive their sub screens through the useSubStep hook, which tracks the active screen in local React state (screenIndex via useState) rather than in Onyx:

src/hooks/useSubStep/index.ts

https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/Expensify.tsx#L55-L58

Because screenIndex lives only in component state, dismissing the RHP modal unmounts the page. When the user re enters the flow, the page (for example AddPersonalBankAccountPage.tsx for personal deposit, and the ReimbursementAccount flow for business) remounts and useSubStep re initializes screenIndex to 0. That is why the user always resumes at the very first screen even though their draft data is still stored, which reads to the user as "progress not saved."

What changes do you think we should make in order to solve the problem?

  1. Persist the current sub step index so it survives a remount, instead of keeping it only in useState. In useSubStep/index.ts, useSubStep already accepts a startFrom argument used to seed screenIndex. We should have the wallet flows compute startFrom from a persisted value rather than always passing 0.

  2. For the personal deposit flow in AddPersonalBankAccountPage.tsx, store the active step alongside the existing personal bank account Onyx data (the same key that already holds the draft field values), and pass it into useSubStep as startFrom on mount. Update it in the onNext handler when the user advances.

const startFrom = personalBankAccount?.subStep ?? 0;
const {componentToRender, isEditing, screenIndex, moveTo, nextScreen, prevScreen} = useSubStep({bodyContent, startFrom, onFinished});
  1. Whenever screenIndex changes, write it back to Onyx so re entry resumes at the same screen:
useEffect(() => {
    BankAccounts.setPersonalBankAccountSubStep(screenIndex);
}, [screenIndex]);
  1. Apply the same persisted startFrom pattern to the business bank account (ReimbursementAccount) sub step flow so both wallet entry points behave consistently.

This fixes the root cause because the flow position is no longer tied to a component instance that gets destroyed when the modal closes; it is read from Onyx on remount, so the user resumes exactly where they left off.

What alternative solutions did you explore? (Optional)

Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

samranahm avatar Jul 03 '26 13:07 samranahm

Proposal

What is the root cause of that problem?

Both Wallet "add bank account" flows (business bank account and personal deposit account) persist their in-progress data in Onyx, so they could be resumed. The bug is that each flow registers a component-unmount cleanup that unconditionally clears that persisted data. Dismissing the RHP by clicking outside it unmounts the flow's screen, so these cleanups fire even when the user only stepped away — destroying the progress that would otherwise let the flow resume.

Personal deposit account — AddPersonalBankAccountPage registers a blanket unmount cleanup:

https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/AddPersonalBankAccountPage.tsx#L62

useEffect(() => clearPersonalBankAccount, []) returns clearPersonalBankAccount as the cleanup, so on any unmount it nulls PERSONAL_BANK_ACCOUNT and wipes the form draft + chosen setup type:

https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/libs/actions/BankAccounts.ts#L329-L334

On re-entry there's nothing left to restore, so it starts over. This is compounded because the sub-step host tracks the current screen in local React state only — useSubStep initializes screenIndex from startFrom, and PersonalInfoPage calls it with no startFrom, so it always restarts at sub-step 0:

  • https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/hooks/useSubStep/index.ts#L26
  • https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/InternationalDepositAccount/PersonalInfo/PersonalInfo.tsx#L82-L86

Business bank account (VBA) — ReimbursementAccountPage has the same anti-pattern in its unmount cleanup:

https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx#L160-L166

On unmount it runs clearReimbursementAccountDraft() + clearReimbursementAccount(), so any information typed on the current step but not yet submitted is discarded when the modal is dismissed.

Proof this is the cause (contrast): the International deposit flow does not clear on unmount, and it computes its starting sub-step from the persisted draft via getInitialSubstep, so it resumes correctly:

  • https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/InternationalDepositAccount/InternationalDepositAccountContent.tsx#L93
  • https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/settings/Wallet/InternationalDepositAccount/InternationalDepositAccountContent.tsx#L131

The two broken flows differ from the working one in exactly these two respects: they wipe on unmount, and they don't derive the starting step from persisted data.

What changes do you think we should make in order to solve the problem?

Apply the pattern the International flow already uses correctly — stop clearing on a plain unmount, and derive the starting step from persisted data.

  1. Personal deposit account — remove the unconditional unmount cleanup at AddPersonalBankAccountPage.tsx:62. Genuine termination is already handled explicitly: exitFlow's goBack() branch calls clearPersonalBankAccount(), and the flow's entry points re-seed fresh state on a new start:

    https://github.com/Expensify/App/blob/8c7284a3c43fa15e33e236ba3fac09ce8bed3801/src/pages/AddPersonalBankAccountPage.tsx#L47-L60

    Then pass a computed startFrom into useSubStep in PersonalInfoPage (mirroring getInitialSubstep/startFrom in the International flow) so re-entry resumes at the correct sub-step instead of index 0.

  2. Business bank account (VBA) — guard the unmount cleanup at ReimbursementAccountPage.tsx:160-166 so it only clears on genuine flow completion/explicit exit, not on an unintended modal dismiss. This preserves the in-progress REIMBURSEMENT_ACCOUNT_FORM_DRAFT (the server already preserves completed steps, so the "Continue setup" entry works — the only thing lost today is the unsubmitted draft on the current step).

This is the right layer because the persistence already exists; the only thing breaking "resume where you left off" is the over-eager unmount cleanups plus the personal flow's local-only step index.

What alternative solutions did you explore? (Optional)

Instead of removing the personal-flow unmount cleanup, gate it on a terminal condition (e.g. only clear when shouldShowSuccess or an explicit exit occurred), so it still cleans up on real completion but preserves progress on an incidental dismiss.

Abdulloh0109 avatar Jul 03 '26 13:07 Abdulloh0109

⚠️ @KJ21-ENG Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

github-actions[bot] avatar Jul 03 '26 13:07 github-actions[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

When adding banking information through Wallet, dismissing the RHP modal mid-flow and re-opening it drops the user back to the first sub-step with all fields appearing empty — even though the underlying draft data was never erased from Onyx.

What is the root cause of that problem?

There are two independent defects that must both be fixed; fixing only the first still leaves the user starting over.

Defect 1 — premature draft clearing on unmount. AddPersonalBankAccountPage.tsx:62 registers useEffect(() => clearPersonalBankAccount, []), so every RHP dismiss (not just explicit exits) triggers clearPersonalBankAccount, which sets ONYXKEYS.PERSONAL_BANK_ACCOUNT and ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM_DRAFT to null, destroying everything the sub-steps wrote via updateAddPersonalBankAccountDraft.

Defect 2 — resume position derived from the wrong source (the deeper problem). Even if Defect 1 were fixed, the flow would still restart at sub-step zero. UpdatePersonalBankAccountPage.tsx computes its starting position via getFirstPageName, which queries only backend-confirmed steps:

// src/pages/settings/Wallet/UpdatePersonalBankAccountPage.tsx:98-103
function getFirstPageName(bankAccountList?, bankAccountID?): string {
    const completedSteps = bankAccountID
        ? getCompletedStepsForBankAccount(bankAccountList, bankAccountID)
        : [];
    const skipPageNames = new Set(getPageNamesForCompletedSteps(completedSteps));
    return PAGE_NAMES.find((name) => !skipPageNames.has(name)) ?? PAGE_NAME.LEGAL_NAME;
}

The personal deposit flow makes no server call between sub-steps — it only submits at final completion — so getCompletedStepsForBankAccount always returns an empty array mid-flow, and getFirstPageName always returns LEGAL_NAME (index 0). The inputs do write to PERSONAL_BANK_ACCOUNT_FORM_DRAFT and HOME_ADDRESS_FORM_DRAFT as the user types, so the data survives in Onyx; it is only the cursor position that is thrown away, because UpdatePersonalBankAccountPage never consults those drafts when computing startFrom.

This is the opposite of the business bank account flow: BusinessInfo.tsx calls getInitialSubStepForBusinessInfo(values), a helper that walks each field in the persisted draft and returns the index of the first missing value (src/pages/ReimbursementAccount/USD/utils/getInitialSubStepForBusinessInfo.ts:13-51). The personal flow has no equivalent, so in-progress position is always discarded.

What changes do you think we should make in order to solve the problem?

Fix both defects:

1. AddPersonalBankAccountPage.tsx:62 — remove the unconditional unmount clearPersonalBankAccount call. Clearing should only occur on explicit success/abandon paths already wired elsewhere (exitFlow, FeesAndTerms, AddBankAccount).

2. UpdatePersonalBankAccountPage.tsx — add a draft-aware resume helper mirroring the business flow:

function getInitialPageIndexFromDraft(personalBankAccountDraft, homeAddressDraft): number {
    if (!personalBankAccountDraft?.legalFirstName || !personalBankAccountDraft?.legalLastName) return 0;
    if (!homeAddressDraft?.addressLine1) return 1;
    return 2;
}

Then replace lines 220–227:

const backendIndex = formPages.findIndex(
    (p) => p.pageName === getFirstPageName(bankAccountList, personalBankAccount?.bankAccountID)
);
const draftIndex = getInitialPageIndexFromDraft(personalBankAccountDraft, homeAddressDraft);
const startFrom = Math.max(backendIndex >= 0 ? backendIndex : 0, draftIndex);
useSubPage({ ..., startFrom });

personalBankAccountDraft and homeAddressDraft are already subscribed via useOnyx in this component, requiring no new Onyx connections. Math.max preserves the existing "skip backend-confirmed steps" behavior while also advancing past any sub-step for which draft data already exists, so the two signals can never regress against each other.

What alternative solutions did you explore? (Optional)

Storing a raw sub-step index in Onyx on each navigation was rejected. The draft already encodes the resume point implicitly through field presence — exactly the pattern the business flow relies on — so a separate index key would create a second source of truth that could drift out of sync with what the user actually entered.

trasnake87 avatar Jul 03 '26 13:07 trasnake87

⚠️ @samranahm Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

github-actions[bot] avatar Jul 03 '26 13:07 github-actions[bot]

⚠️ @Abdulloh0109 Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

github-actions[bot] avatar Jul 03 '26 13:07 github-actions[bot]

Proposal [Updated]

Updated my proposal above with a more complete root-cause analysis and the full set of affected call sites.

ahmdshrif avatar Jul 03 '26 13:07 ahmdshrif