Skip to content

Keep the KYC continuation route when the bank account flow is left mid-setup - #97305

Open
mukhrr wants to merge 2 commits into
Expensify:mainfrom
mukhrr:fix/94659
Open

Keep the KYC continuation route when the bank account flow is left mid-setup#97305
mukhrr wants to merge 2 commits into
Expensify:mainfrom
mukhrr:fix/94659

Conversation

@mukhrr

@mukhrr mukhrr commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

When you pay someone from a 1:1 chat and pick "Pay with personal account", the KYC wall seeds PERSONAL_BANK_ACCOUNT with an onSuccessFallbackRoute (and exitReportID where relevant) so the app knows where to continue once a bank account exists.

AddPersonalBankAccountPage cleared that whole Onyx key on unmount:

useEffect(() => clearPersonalBankAccount, []);

Backing out of the Plaid step calls Navigation.goBack, which unmounts the page and wipes the key along with the continuation route. Re-entering through AccountFlowEntryPoint just navigates, it never re-seeds it, so on the second, successful attempt exitFlow(true) can no longer satisfy shouldContinue && onSuccessFallbackRoute and falls through to goBack(). That drops you back on the Add bank account entry point instead of starting KYC.

The fix keeps the routing data across an unmount that isn't a deliberate exit. A ref tracks the latest onSuccessFallbackRoute / exitReportID and hands it to clearPersonalBankAccount(preservedData) in the cleanup, and a second ref makes sure a deliberate exit still clears everything, so a stale route can't leak into the next flow regardless of render ordering.

clearPersonalBankAccount already accepts preservedData, so nothing in the action layer changes. AccountFlowEntryPoint does the same preservation on entry, so this is consistent with the existing pattern.

Fixed Issues

$ #94659
PROPOSAL: #94659 (comment)

Tests

  1. Sign in with a validated account that has no personal bank account added
  2. Start a 1:1 conversation with another user
  3. Press the + button and select "Pay [User]"
  4. On the amount screen tap the currency selector, choose USD, enter any amount and continue
  5. Click "Pay with personal account"
  6. Start the bank account flow and exit/cancel it before entering credentials
  7. Start the bank account flow again and complete the setup
  8. Click Continue on the "Bank account added" page
  9. Verify the KYC verification flow is triggered, and you are not sent back to the Add bank account entry point

Check that a deliberate exit still clears the flow:

  1. Go to Settings > Wallet > Add bank account and complete the setup
  2. Click Continue on the "Bank account added" page
  3. Verify you land back on the Wallet page and no KYC flow is triggered
  • Verify that no errors appear in the JS console

Offline tests

Adding a bank account needs the API (Plaid and AddPersonalBankAccount), so there is no offline path through this flow. This change only touches in-memory routing state kept across an unmount, so offline behavior is unchanged.

QA Steps

Same as tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
android_app.mp4
Android: mWeb Chrome
android_web.mp4
iOS: Native
ios_app.mp4
iOS: mWeb Safari
ios_web.mp4
MacOS: Chrome / Safari
web.mp4

…d-setup

Cancelling the personal bank account flow unmounted AddPersonalBankAccountPage,
whose cleanup cleared the whole PERSONAL_BANK_ACCOUNT key. That dropped the
onSuccessFallbackRoute seeded by the Pay/KYC entry point, so completing the flow
on a second attempt fell back to goBack() instead of continuing to KYC.

Preserve the routing data across an unmount that isn't a deliberate exit.

Fixes Expensify#94659
@mukhrr
mukhrr requested review from a team as code owners July 29, 2026 03:50
@melvin-bot
melvin-bot Bot requested review from dmkt9 and flaviadefaria July 29, 2026 03:50
@melvin-bot

melvin-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

@dmkt9 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed request for a team July 29, 2026 03:50
};

useEffect(() => clearPersonalBankAccount, []);
useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❌ PERF-6 (docs)

This useEffect has no dependency array, so it runs on every render purely to write a value derived from personalBankAccount into flowRoutingDataRef. It performs no external side effect — it just recomputes derived state — which is exactly the "you might not need an Effect" case: a derived value should be computed directly in the component body rather than synced into a ref via an effect that fires every render.

Compute the routing data inline and keep the ref updated during the same render path that guards hasExitedFlowRef, e.g.:

const {onSuccessFallbackRoute, exitReportID} = personalBankAccount ?? {};
const flowRoutingData = !onSuccessFallbackRoute && !exitReportID ? undefined : {onSuccessFallbackRoute, exitReportID};
if (!hasExitedFlowRef.current) {
    flowRoutingDataRef.current = flowRoutingData;
}

This removes the extra effect while still capturing the latest routing data for the unmount cleanup.


Reviewed at: fe77cd7 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fe77cd7c12

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

return;
}
const {onSuccessFallbackRoute, exitReportID} = personalBankAccount ?? {};
flowRoutingDataRef.current = !onSuccessFallbackRoute && !exitReportID ? undefined : {onSuccessFallbackRoute, exitReportID};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear stale report redirects after success exits

When an add-bank-account flow that has exitReportID reaches the success screen, the success/back branches call dismissModalWithReport() without setting hasExitedFlowRef, so this new preservation path writes {exitReportID} back to PERSONAL_BANK_ACCOUNT during unmount. That leaves a stale report redirect behind; a later EnablePayments add-bank-account attempt can start with openPersonalBankAccountSetupWithPlaid() (which only merges the setup type when no ID is passed) and AddBankAccount.exitFlow() prioritizes any existing exitReportID, dismissing to the old report instead of Wallet/KYC. Treat the exitReportID success dismissal as an exited flow, or only preserve it while the user is still mid-setup.

Useful? React with 👍 / 👎.

Preserving onSuccessFallbackRoute and exitReportID on unmount also re-seeded
them after a flow that had already finished, so a later add-bank-account
attempt could dismiss to a stale report instead of the wallet.

Reaching exitFlow always means leaving on purpose, so mark the flow exited
before any branch runs rather than only in the fallback one.

Also scope the routing-data effect to personalBankAccount so it stops
running on every render.
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/pages/AddPersonalBankAccountPage.tsx 92.10% <88.88%> (+92.10%) ⬆️
... and 13 files with indirect coverage changes

@mukhrr

mukhrr commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

@dmkt9 kindly bump. thanks

@mukhrr

mukhrr commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

oh wait..

#95946 refactored the personal bank account flow into AddPersonalBankAccountPage/index.tsx and dropped the useEffect(() => clearPersonalBankAccount, []) that ran on unmount. That unmount cleanup was the root cause: cancelling the first attempt unmounted the page and wiped the whole PERSONAL_BANK_ACCOUNT key, onSuccessFallbackRoute included, so exitFlow had nothing left to continue to. Clearing now only happens on the real exit paths inside exitFlow.

Retested on staging: after cancelling the bank account flow, onSuccessFallbackRoute survives, and completing the second attempt triggers KYC as expected.

REC-20260802181601.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant