[$250] [Exploratory] Email - Can transfer the same balance twice to two accounts and receive 2 emails
If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
Version Number: v9.4.69-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/72092520/folder/54013399/41237085/1720577667?sort=%2Bidentifier Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Windows 10/Chrome App Component: User Settings
Action Performed:
Preconditions: Both accounts with wallet enabled are set up, and in USD by default User B has set up 2 personal bank accounts: xxxx0000 and xxxx1111 Steps
- As User A - Pay User B so they have a positive amount in their wallet
- As User B - Navigate to Wallet and Click “Transfer”
- Select bank accounts: xxxx0000 -> Transfer
- Repeat and select bank accounts: xxxx1111 -> Transfer
Expected Result:
User should only transfer to one bank account
Actual Result:
User can transfer to 2 bank accounts and receive 2 emails about the same balance
Workaround:
Unknown
Platforms:
- [x] Android: App
- [ ] Android: mWeb Chrome
- [x] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [x] Windows: Chrome
- [ ] MacOS: Chrome Safari
Screenshots/Videos
https://github.com/user-attachments/assets/7f00bad8-a6a7-4efc-8561-91eca12e9055
Applause Internal Information Exported by: Julia Ponikarchuk Bug ID: 7249953
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022112523938151067142
- Upwork Job ID: 2112523938151067142
- Last Price Increase: 2026-10-27
While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/00b70febfc5845d810b6d09881b5917821a063b43d9d07db6c76a43240a9e740
Proposal
What is the root cause of that problem?
Nothing in the App clears or re-reads the wallet balance after a successful transfer, so the Transfer button stays enabled on a balance that has already been sent.
The only thing gating a transfer is TransferBalancePage.tsx:148-151, which reads the Onyx-cached userWallet.currentBalance:
const transferAmount = userWallet?.currentBalance ?? 0 - calculatedFee;
const isTransferable = transferAmount > 0;
const isButtonDisabled = !isTransferable || !selectedAccount;
That cached value is never invalidated:
transferWalletBalance()writes only toONYXKEYS.WALLET_TRANSFER(loading/shouldShowSuccess). ItsOnyxUpdatetype is narrowed to that key, so it structurally cannot touchuserWallet.dismissSuccessfulTransferBalancePage()just flipsshouldShowSuccessand callsNavigation.goBack()— no refetch.- The Wallet page's only fetch effect is keyed on
[network.isOffline](WalletPage/index.tsx:407-412). Transfer Balance is an RHP screen layered over a still-mounted Wallet page, so returning from it does not re-rungetPaymentMethods().
So on the second visit the page re-mounts, resetWalletTransferData() clears loading/shouldShowSuccess, the stale balance still reads > 0, and a second TransferWalletBalance fires with the other bankAccountID.
This is not a double-tap race — the button is genuinely disabled while walletTransfer.loading is true. It is two deliberate, sequential submits against a stale balance.
Supporting evidence and what I could not verify
The client is not swallowing a server update. SaveResponseInOnyx.ts:29 applies any onyxData the server returns, with no per-command allowlist, and userWallet is read reactively via useOnyx. If a zeroed currentBalance had reached the client at any point before transfer #2, the button would have disabled itself with no code change. It didn't — so no fresh balance arrived.
availableBalance is declared but never used. UserWallet.ts:17-19 has both availableBalance and currentBalance, but every transfer decision in the App reads currentBalance. If the backend reserves funds by moving availableBalance while currentBalance only settles later, that alone produces this bug.
Secondary defect in the same flow. resetWalletTransferData() unconditionally sets loading: false on every mount. Navigating away mid-request and back re-enables the button before the first response lands, allowing a true concurrent double-submit.
Alternatives I ruled out. A double-tap race (button is disabled via isLoading — Button.tsx:146); a missing in-flight guard (it exists and works); a duplicate-notification-only bug (the reporter's video shows both transfers completing).
Not verified. I could not confirm from production logs whether both requests returned success, nor whether the second transfer actually moved money a second time. Log tooling was unavailable in this run, and the backend command is outside this repo. The App-side conclusion above rests on code reading plus the reported repro.
Adjacent bug worth fixing in the same PR. TransferBalancePage.tsx:149 has an operator-precedence bug: ?? binds looser than -, so userWallet?.currentBalance ?? 0 - calculatedFee parses as userWallet?.currentBalance ?? (0 - calculatedFee). The fee is never subtracted when currentBalance is defined. Harmless today only because the ACH rate and minimum fee are both 0 and the instant option is commented out.
What changes do you think we should make in order to solve the problem?
- Refresh the wallet after a successful transfer. In
dismissSuccessfulTransferBalancePage(), callgetPaymentMethods()(theOpenPaymentsPageread) before navigating back, so the Wallet page and any later visit to Transfer Balance see the real balance instead of the pre-transfer one. - Optimistically zero the balance. Add a
USER_WALLETentry totransferWalletBalance()'ssuccessDatasettingcurrentBalance(andavailableBalance) to0, withfailureDatarestoring the prior value. This closes the window before the refetch returns and makes the button disable itself immediately. - Stop clobbering the in-flight flag. Have
resetWalletTransferData()preserveloadingwhen a request is outstanding, rather than forcing it tofalseon every mount. - Fix the precedence bug on
TransferBalancePage.tsx:149by parenthesising:(userWallet?.currentBalance ?? 0) - calculatedFee. - Add regression tests. There are currently none for this flow — the only transfer-related assertion in the whole suite is a fee-rounding test in
tests/unit/PaymentUtilsTest.ts:36. A test asserting the button is disabled after a successful transfer would have caught this.
⚠️ This fix alone is not sufficient. Steps 1–3 stop the App from offering a second transfer, but the client sends no amount and no idempotency key — the request body is just
{bankAccountID}. Preventing the same balance from actually moving twice requires a server-side balance re-check or lock on the transfer command, which lives outside this repo. Someone with backend access should confirm whether that guard exists and whether the transfer response returns an updated wallet balance. Please escalate that half to an internal engineer.
What alternative solutions did you explore? (Optional)
- Gate on
availableBalanceinstead ofcurrentBalance. Cleaner if the backend already reserves funds there, but the App never reads that field today and I could not confirm the backend populates it on transfer. Worth checking as part of the backend escalation — if it does, this becomes the simplest fix. - Hide the Transfer Balance menu item when the balance is zero.
WalletPage/index.tsx:832-848gates it only on wallet tier. Adding a balance check is a reasonable defence-in-depth addition, but it fixes nothing on its own since it reads the same stale value. - Send an idempotency key with the transfer. The right long-term shape, but it needs a matching backend change, so it can't ship from this repo alone.
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/100290) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @eh2077 (External)
Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.
@eh2077 Eep! 4 days overdue now. Issues have feelings too...
checking
@eh2077 this issue is now 4 weeks old, please consider:
- Finding a contributor to fix the bug
- Closing the issue if BZ has been unable to add the issue to a VIP or Wave project
- If you have any questions, don't hesitate to start a discussion in #expensify-open-source
Thanks!
@eh2077 Huh... This is 4 days overdue. Who can take care of this?
not overdue, add it to my list for tmr
@eh2077 Huh... This is 4 days overdue. Who can take care of this?
trying to reproduce the issue
@eh2077 Huh... This is 4 days overdue. Who can take care of this?
I can't reproduce it, so can't look into melvin's proposal. I'm going to add help wanted to see if any contributor can reproduce it.
🆘 C+ Help Wanted
Proposal
What is the root cause of that problem?
Nothing in the App ever writes USER_WALLET.currentBalance. Only the server does, through response onyxData, and transferWalletBalance writes only ONYXKEYS.WALLET_TRANSFER. So after a transfer the page still holds the old balance, and that cached number is the only thing gating the next transfer:
https://github.com/Expensify/App/blob/e029fad955164435583153ee7f862942711273cb/src/pages/settings/Wallet/TransferBalancePage.tsx#L148-L151
I ran the reported flow on dev web, and against the action in Jest:
- Transferred $50.00 to Plaid Checking 0000. Back on Wallet the balance still read $50.00.
- Opened Transfer balance again and picked Plaid Saving 1111. The button said "Transfer $50.00" and was enabled, and a second
TransferWalletBalancewent out with the otherbankAccountID. - In Jest, with the wallet at 5000 and the command returning 200,
currentBalancewas still 5000 afterwards. Same result with the request paused mid-flight, so navigating away and back (which resetsloading) re-enables submit as well. - When the response echoed the wallet back with 5000 in its
onyxData, it overwrote a client-side optimistic zero, because responseonyxDatais applied first andsuccessDatalast.
https://github.com/Expensify/App/blob/e029fad955164435583153ee7f862942711273cb/src/libs/actions/OnyxUpdates.ts#L71-L81
So an optimistic-only zero isn't enough. The zero has to be reasserted after the response lands.
flowchart TD
A["Transfer $50.00 to xxxx0000"] -->|"no USER_WALLET write anywhere in the App"| B["currentBalance still 5000"]
B -->|"resetWalletTransferData clears loading on mount"| C["Reopen Transfer balance, pick xxxx1111"]
C -->|"transferAmount = 5000 - 0, isTransferable true"| D["Transfer $50.00 enabled on funds already sent"]
D -->|"second TransferWalletBalance, other bankAccountID"| E["Second withdrawal and second email"]
What changes do you think we should make in order to solve the problem?
Treat the withdrawal as an optimistic update with rollback. The command takes no amount and always withdraws the whole balance, so zero is the post-success value. Nothing to guess.
In transferWalletBalance, add USER_WALLET to the OnyxUpdate union, the same way getMakeDefaultPaymentOnyxData in this file already does, then:
optimisticData: merge USER_WALLET {currentBalance: 0, availableBalance: 0}
successData: same merge again, it lands after the response's own onyxData
failureData: merge USER_WALLET back to the balance from the wallet passed in
The previous balance comes in as a parameter. This file has no Onyx subscriptions, and every helper in it takes its data from the caller. TransferBalancePage already has userWallet, so the call becomes transferWalletBalance(selectedAccount, userWallet).
https://github.com/Expensify/App/blob/e029fad955164435583153ee7f862942711273cb/src/libs/actions/PaymentMethods.ts#L344-L390
While there I'd also parenthesise the gate. userWallet?.currentBalance ?? 0 - calculatedFee parses as currentBalance ?? (0 - calculatedFee), so the fee is never subtracted. That's harmless today because ACH fees are 0, but it's the exact line this bug turns on.
With the change, on dev web the wallet dropped to $0.00 right after the first transfer, the second visit showed a disabled "Transfer" button, and only one TransferWalletBalance was sent. On an EXP_ERROR the old balance comes back so user can retry. A new tests/actions/PaymentMethodsTest.ts has 4 cases. The first two fail on main (5000 where 0 is expected), the echo case fails on an optimistic-only version, and all pass with the fix.
The App can't make a double withdrawal impossible on its own: the request body is just {bankAccountID}, with no amount and no idempotency key. This removes the offer, which covers the reported flow. A server-side balance re-check is a separate fix for an internal engineer.
What alternative solutions did you explore? (Optional)
Calling getPaymentMethods() in dismissSuccessfulTransferBalancePage to refetch. I dropped it: that request flips IS_LOADING_PAYMENT_METHODS, and the Wallet page then swaps the balance and the Transfer balance row for a spinner, so pressing Done would flash a loading state.
https://github.com/Expensify/App/blob/e029fad955164435583153ee7f862942711273cb/src/pages/settings/Wallet/WalletPage/index.tsx#L786-L790
Keeping loading in resetWalletTransferData. That reset is the escape hatch for a request that never resolves, and once optimisticData zeroes the balance the navigate-away-and-back window is already closed.
Gating on availableBalance. It's declared on UserWallet but dead in the App, and I can't confirm the server reserves funds there.
https://github.com/user-attachments/assets/16c3c55c-c22f-4258-ad46-4b334fdf18f8
https://github.com/user-attachments/assets/ef289525-cd69-463f-9673-6ef6062bacaa
Proposal
Please re-state the problem that we are trying to solve in this issue.
After transferring the entire wallet balance to one personal bank account, the user can immediately go back to the Wallet page, open the Transfer flow again, pick a second bank account, and submit another transfer of the same balance. Both transfers go through and the user receives two confirmation emails for a single wallet balance, when only one transfer should have been possible.
What is the root cause of that problem?
The client never updates the wallet balance after a successful transfer, so the app keeps offering the old positive balance for a second transfer.
When TransferWalletBalance succeeds, the successData in transferWalletBalance only updates the transfer UI state (loading: false, shouldShowSuccess: true) — it does not touch the user's wallet, so currentBalance under ONYXKEYS.USER_WALLET keeps its pre-transfer value:
https://github.com/Expensify/App/blob/bcf57a81cd22d5a4c2d42571c15933d7f16a4ae5/src/libs/actions/PaymentMethods.ts#L363-L390
The Wallet page also does not re-fetch wallet data when the user returns to it. getPaymentMethods() (the OpenPaymentsPage call that would bring back the authoritative balance) only runs on mount and on the offline-to-online transition, not when the page regains focus:
https://github.com/Expensify/App/blob/bcf57a81cd22d5a4c2d42571c15933d7f16a4ae5/src/pages/settings/Wallet/WalletPage/index.tsx#L399-L404
So after the user dismisses the transfer success screen, they land back on the still-mounted Wallet page showing the stale positive balance. Opening the Transfer flow again computes the transferable amount from that stale currentBalance, which is still positive, so the Transfer button stays enabled and a second TransferWalletBalance request is submitted for a balance that was already transferred:
https://github.com/Expensify/App/blob/bcf57a81cd22d5a4c2d42571c15933d7f16a4ae5/src/pages/settings/Wallet/TransferBalancePage.tsx#L148-L151
The server then processes that second request as well and sends a second confirmation email.
What changes do you think we should make in order to solve the problem?
A wallet balance transfer always transfers the entire available balance, so the client knows the wallet is empty the moment the transfer succeeds. In transferWalletBalance, add a successData update that merges currentBalance: 0 into ONYXKEYS.USER_WALLET, alongside the existing update that shows the success screen.
With that in place, after the first successful transfer the Wallet page shows a zero balance, and reopening the Transfer flow disables the Transfer button because the transferable amount is no longer positive — the same balance can no longer be submitted a second time. The next OpenPaymentsPage fetch (for example on the next app open) reconciles the client value with the server's authoritative balance, so no drift persists.
For completeness, the server should also reject a TransferWalletBalance request when the wallet has no remaining balance (that validation and the duplicate email are backend concerns); the change above fixes the client-side gap that lets the app offer and submit the second transfer in the first place.
Compare branch: https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/100290-zero-balance-after-transfer?expand=1
What alternative solutions did you explore? (Optional)
Re-fetching payment data when the Wallet page regains focus (calling getPaymentMethods() from a focus effect instead of only on mount) would also refresh the balance, but it costs an extra network round trip on every visit to the page and still leaves a stale window until the response arrives, so the direct success-data update is preferable.
Another option is gating the Transfer flow on the transfer state under ONYXKEYS.WALLET_TRANSFER (for example, blocking a new submission once a transfer succeeded), but that state is reset every time the transfer page opens, so it cannot reliably represent "this balance was already transferred" — the balance itself is the right signal.
Job added to Upwork: https://www.upwork.com/jobs/~022112523938151067142
Proposal
Updated: rebased on current main (after #107088, scrollToInput now takes shouldDelayScroll, so passing it straight to onSelectionChange would hand it the event and fail typecheck). The edit scroll now runs only while the keyboard is fully open, and runs immediately and animated.
Please re-state the problem that we are trying to solve in this issue.
On Android and iOS, in Workspace > Rules > Add rule, if the admin swipes the "Or just describe it below" box out of view while the keyboard is open and then types again, the form doesn't bring the box back. The caret stays hidden behind the keyboard or above the screen.
What is the root cause of that problem?
DescribeRuleForm brings the box into view from only three places:
- First focus:
onFocus={scrollToFocusedInput}
https://github.com/Expensify/App/blob/84aec2e0f4dbd1616a8a107ff40aa6561b29af7a/src/pages/workspace/rules/DescribeRuleForm.tsx#L287-L294
- Android reopening the keyboard without a focus change:
useScrollOnKeyboardReopen, which listens forkeyboardDidShow
https://github.com/Expensify/App/blob/84aec2e0f4dbd1616a8a107ff40aa6561b29af7a/src/hooks/useScrollOnKeyboardReopen/index.android.ts#L58-L64
- A refusal:
scrollToEnd
Android's own scroll-to-focused-child is turned off for this form (shouldScrollChildToFocus={false}), so nothing else moves it:
https://github.com/Expensify/App/blob/84aec2e0f4dbd1616a8a107ff40aa6561b29af7a/src/pages/workspace/rules/DescribeRuleForm.tsx#L314-L315
In the repro, the box never loses focus and the keyboard never closes. Scrolling a ScrollView doesn't blur its child. So when typing starts again, there's no focus event and no keyboard show event. None of the three paths run, and the form stays where the swipe left it.
What changes do you think we should make in order to solve the problem?
In DescribeRuleForm, also scroll back to the box when its caret moves while the keyboard is already open:
const {isKeyboardShown, isKeyboardAnimatingRef} = useKeyboardState();
// The box keeps focus and the keyboard stays open while the form scrolls, so editing again sends no focus or keyboard event.
const scrollToEditedInput = () => {
// First focus and the Android keyboard reopen already scroll once the keyboard is open.
if (!isKeyboardShown || isKeyboardAnimatingRef.current) {
return;
}
scrollToInput(false);
};
onFocus={scrollToFocusedInput}
onBlur={resetScrollOnKeyboardReopen}
onSelectionChange={scrollToEditedInput}
Why onSelectionChange
- It fires on every key press and on every tap that moves the caret, which is exactly when editing starts again.
- It doesn't fire when the form scrolls. So a swipe that starts on the box is never pulled back.
onPresswould be: on native,BaseTextInputforwards it toonPressOut, which also fires at the end of a cancelled press or drag (index.native.tsx#L451). FormProvider(L457) andBaseTextInput(L410) already pass it to the RNTextInput, so no shared component changes.
Why the keyboard gate and scrollToInput(false)
isKeyboardShownis set onkeyboardDidShow, after the keyboard has finished opening. On first focus the caret is placed before that, so the gate skips it, and the existing delayed focus scroll stays the only scroll. No double jump (#105661). The Android reopen case is also skipped and left touseScrollOnKeyboardReopen.- When the keyboard is already open, there's nothing to wait for.
scrollTo(y, false)runs one animated scroll right away, instead of queueing anANIMATED_TRANSITIONtimer on every key press:
https://github.com/Expensify/App/blob/84aec2e0f4dbd1616a8a107ff40aa6561b29af7a/src/components/Form/FormWrapper.tsx#L167-L177
- The target is the same as on focus (
inputTopOffsetRef), and the scroll stops at the end of the content. So the whole box comes back, along with Next or the refusal and its buttons. The box has a fixed height and scrolls its own text, so the caret is visible too. If the box is already in place, the scroll does nothing, so normal typing never moves the page.
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
In tests/ui/RulesNewPageDescribeRuleTest.tsx, forward onSelectionChange from the InputWrapper mock and mock useKeyboardState:
- Keyboard open, caret moves without a new focus event →
scrollTo(inputTop, false)is called. - Keyboard not open yet (first focus) → only the existing delayed focus scroll runs, once.
- Keyboard still animating → the caret move doesn't scroll.
Test branch
https://github.com/Expensify/App/compare/main...abbasifaizan70:Expensify:fix/100290-clear-wallet-balance?expand=1
Demo
Before
https://github.com/user-attachments/assets/ef6fc8c1-8268-49b3-8207-cb0c10cda374
After
https://github.com/user-attachments/assets/b37589c9-e8d3-4159-a650-2eda386c8f0f
What alternative solutions did you explore? (Optional)
onValueChange/onChangeText: covers typing, but not a tap that moves the caret.onPress: covers taps, but fires at the end of a drag that starts on the box, which pulls the form back against the admin's swipe.- Measuring the box against the keyboard on every edit: more code for the same result, because a scroll to the same offset already does nothing.
🤖 ProposalPolice™ is tracking duplicate proposals for this issue using an OpenAI Conversation. This comment stores that Conversation's ID and can be safely ignored.
Proposal updated — added compare branch with implementation.