From 7ebd717b99913504d6acd0e336f059886afcd410 Mon Sep 17 00:00:00 2001 From: Mukher Date: Wed, 18 Nov 2026 08:22:22 +0500 Subject: [PATCH 1/4] Only offer personal US bank accounts as wallet transfer destinations Auth rejects TransferWalletBalance to a business bank account, but the transfer picker, the single-account auto-select and the selected account all read the unfiltered bank account list. Reuse the open personal US rule from hasExpensifyPaymentMethod so a business account is never offered. --- src/libs/PaymentUtils.ts | 30 +++++++---- .../Wallet/ChooseTransferAccountPage.tsx | 3 +- .../settings/Wallet/TransferBalancePage.tsx | 7 +-- tests/unit/PaymentUtilsTest.ts | 53 ++++++++++++++++++- 4 files changed, 77 insertions(+), 16 deletions(-) diff --git a/src/libs/PaymentUtils.ts b/src/libs/PaymentUtils.ts index 1251f0341fbd..b06b286be5b8 100644 --- a/src/libs/PaymentUtils.ts +++ b/src/libs/PaymentUtils.ts @@ -72,20 +72,29 @@ type BusinessBankAccountOption = { methodID: number | undefined; }; +/** + * Auth only pays a wallet balance out to an open personal US bank account, business accounts are rejected. + */ +function isWalletTransferBankAccount(bankAccountJSON: BankAccount): boolean { + const bankAccount = new BankAccountModel(bankAccountJSON); + + return ( + bankAccount.getPendingAction() !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && + bankAccount.isOpen() && + bankAccount.getType() === CONST.BANK_ACCOUNT.TYPE.PERSONAL && + bankAccount.getCountry() === CONST.COUNTRY.US + ); +} + +function getWalletTransferBankAccounts(bankAccountList: Record): Record { + return Object.fromEntries(Object.entries(bankAccountList).filter(([, bankAccount]) => isWalletTransferBankAccount(bankAccount))); +} + /** * Check to see if user has either a debit card or personal US bank account added that can be used with a wallet. */ function hasExpensifyPaymentMethod(fundList: Record, bankAccountList: Record, shouldIncludeDebitCard = true): boolean { - const validBankAccount = Object.values(bankAccountList).some((bankAccountJSON) => { - const bankAccount = new BankAccountModel(bankAccountJSON); - - return ( - bankAccount.getPendingAction() !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && - bankAccount.isOpen() && - bankAccount.getType() === CONST.BANK_ACCOUNT.TYPE.PERSONAL && - bankAccount?.getCountry() === CONST.COUNTRY.US - ); - }); + const validBankAccount = Object.values(bankAccountList).some(isWalletTransferBankAccount); // Hide any billing cards that are not P2P debit cards for now because you cannot make them your default method, or delete them const validDebitCard = Object.values(fundList).some((card) => card?.accountData?.additionalData?.isP2PDebitCard ?? false); @@ -357,6 +366,7 @@ function getActivePaymentType( export { hasExpensifyPaymentMethod, + getWalletTransferBankAccounts, getPaymentMethodDescription, formatPaymentMethods, getBusinessBankAccountOptions, diff --git a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx index d3bb5dd7d444..dbaa3c85a327 100644 --- a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx +++ b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx @@ -15,6 +15,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import {getLastFourDigits} from '@libs/BankAccountUtils'; import Navigation from '@libs/Navigation/Navigation'; +import {getWalletTransferBankAccounts} from '@libs/PaymentUtils'; import {openPersonalBankAccountSetupView} from '@userActions/BankAccounts'; import {saveWalletTransferAccountTypeAndID} from '@userActions/PaymentMethods'; @@ -68,7 +69,7 @@ function ChooseTransferAccountPage() { const [draftAccountID, setDraftAccountID] = useState(); const currentSelectedAccountID = draftAccountID ?? selectedAccountID; - const options = Object.values(bankAccountsList ?? {}).map((bankAccount, index): BankAccountListItem => { + const options = Object.values(getWalletTransferBankAccounts(bankAccountsList ?? {})).map((bankAccount, index): BankAccountListItem => { const bankName = (bankAccount.accountData?.additionalData?.bankName ?? '') as BankName; const bankAccountNumber = bankAccount.accountData?.accountNumber ?? ''; const bankAccountID = bankAccount.accountData?.bankAccountID ?? bankAccount.methodID; diff --git a/src/pages/settings/Wallet/TransferBalancePage.tsx b/src/pages/settings/Wallet/TransferBalancePage.tsx index 7ddf802646cf..7faabe5f3e0b 100644 --- a/src/pages/settings/Wallet/TransferBalancePage.tsx +++ b/src/pages/settings/Wallet/TransferBalancePage.tsx @@ -25,7 +25,7 @@ import { } from '@libs/actions/PaymentMethods'; import {getLatestErrorMessage} from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; -import {calculateWalletTransferBalanceFee, formatPaymentMethods, hasExpensifyPaymentMethod} from '@libs/PaymentUtils'; +import {calculateWalletTransferBalanceFee, formatPaymentMethods, getWalletTransferBankAccounts, hasExpensifyPaymentMethod} from '@libs/PaymentUtils'; import variables from '@styles/variables'; @@ -54,6 +54,7 @@ function TransferBalancePage() { const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); const [fundList] = useOnyx(ONYXKEYS.FUND_LIST); const paymentCardList = fundList ?? {}; + const transferBankAccountList = getWalletTransferBankAccounts(bankAccountList ?? {}); const paymentTypes = [ // Temporarily disable P2P debit card, see https://github.com/Expensify/App/pull/46323 @@ -80,7 +81,7 @@ function TransferBalancePage() { * Get the selected/default payment method account for wallet transfer */ function getSelectedPaymentMethodAccount(): PaymentMethod | undefined { - const paymentMethods = formatPaymentMethods(bankAccountList ?? {}, paymentCardList, styles, translate); + const paymentMethods = formatPaymentMethods(transferBankAccountList, paymentCardList, styles, translate); const defaultAccount = paymentMethods.find((method) => method.isDefault); const selectedAccount = paymentMethods.find( @@ -93,7 +94,7 @@ function TransferBalancePage() { saveWalletTransferMethodType(filterPaymentMethodType); // If we only have a single option for the given paymentMethodType do not force the user to make a selection - const combinedPaymentMethods = formatPaymentMethods(bankAccountList ?? {}, paymentCardList, styles, translate); + const combinedPaymentMethods = formatPaymentMethods(transferBankAccountList, paymentCardList, styles, translate); const filteredMethods = combinedPaymentMethods.filter((paymentMethod) => paymentMethod.accountType === filterPaymentMethodType); if (filteredMethods.length === 1) { diff --git a/tests/unit/PaymentUtilsTest.ts b/tests/unit/PaymentUtilsTest.ts index 4a1ecef8ca40..84aa090c5a17 100644 --- a/tests/unit/PaymentUtilsTest.ts +++ b/tests/unit/PaymentUtilsTest.ts @@ -2,7 +2,7 @@ import type {BankAccountMenuItem} from '@components/Search/types'; import {approveMoneyRequest} from '@libs/actions/IOU/ReportWorkflow'; import Navigation from '@libs/Navigation/Navigation'; -import {getActivePaymentType, getBusinessBankAccountOptions, isSecondaryActionAPaymentOption, selectPaymentType} from '@libs/PaymentUtils'; +import {getActivePaymentType, getBusinessBankAccountOptions, getWalletTransferBankAccounts, isSecondaryActionAPaymentOption, selectPaymentType} from '@libs/PaymentUtils'; import type {SelectPaymentTypeParams} from '@libs/PaymentUtils'; import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils'; @@ -10,7 +10,7 @@ import CONST from '@src/CONST'; import {calculateWalletTransferBalanceFee} from '@src/libs/PaymentUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {Report} from '@src/types/onyx'; +import type {BankAccount, Report} from '@src/types/onyx'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; import type PaymentMethod from '@src/types/onyx/PaymentMethod'; @@ -644,4 +644,53 @@ describe('PaymentUtils', () => { expect(resultWithUnknownDefault.map((option) => option.methodID)).toEqual([1, 2]); }); }); + + describe('getWalletTransferBankAccounts', () => { + const createBankAccount = (bankAccountID: number, type: string, overrides: Partial = {}): BankAccount => ({ + accountType: CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT, + methodID: bankAccountID, + accountData: { + bankAccountID, + type, + state: CONST.BANK_ACCOUNT.STATE.OPEN, + additionalData: {country: CONST.COUNTRY.US}, + }, + ...overrides, + }); + + it('keeps only open personal US accounts', () => { + // Given a personal account next to a business account, the wallet pseudo-account, a closed personal account and a non-US personal account + const personal = createBankAccount(1, CONST.BANK_ACCOUNT.TYPE.PERSONAL); + const bankAccountList: Record = { + 1: personal, + 2: createBankAccount(2, CONST.BANK_ACCOUNT.TYPE.BUSINESS), + 3: createBankAccount(3, CONST.BANK_ACCOUNT_TYPES.WALLET), + 4: createBankAccount(4, CONST.BANK_ACCOUNT.TYPE.PERSONAL, { + accountData: {bankAccountID: 4, type: CONST.BANK_ACCOUNT.TYPE.PERSONAL, state: CONST.BANK_ACCOUNT.STATE.PENDING}, + }), + 5: createBankAccount(5, CONST.BANK_ACCOUNT.TYPE.PERSONAL, { + accountData: {bankAccountID: 5, type: CONST.BANK_ACCOUNT.TYPE.PERSONAL, state: CONST.BANK_ACCOUNT.STATE.OPEN, additionalData: {country: 'GB'}}, + }), + }; + + // When the wallet transfer destinations are picked, since Auth rejects a transfer to anything but an open personal US account + const result = getWalletTransferBankAccounts(bankAccountList); + + // Then only the personal account remains, so the business one can't be offered or auto-selected + expect(result).toEqual({1: personal}); + }); + + it('drops a personal account pending deletion', () => { + // Given a personal account the user just deleted offline + const bankAccountList: Record = { + 1: createBankAccount(1, CONST.BANK_ACCOUNT.TYPE.PERSONAL, {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}), + }; + + // When the wallet transfer destinations are picked + const result = getWalletTransferBankAccounts(bankAccountList); + + // Then it is not offered, matching hasExpensifyPaymentMethod which hides the transfer view in that state + expect(result).toEqual({}); + }); + }); }); From 6365c479c28105cd8a684f5de5c5e920e8f73526 Mon Sep 17 00:00:00 2001 From: Mukher Date: Wed, 18 Nov 2026 10:34:51 +0500 Subject: [PATCH 2/4] Fix CI failures in wallet transfer change Call getWalletTransferBankAccounts inside the functions that use it so React Compiler keeps caching TransferBalancePage, and build the test bank accounts with explicit fields and string keys for typecheck and lint. --- .../settings/Wallet/TransferBalancePage.tsx | 5 +- tests/unit/PaymentUtilsTest.ts | 50 +++++++++---------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/pages/settings/Wallet/TransferBalancePage.tsx b/src/pages/settings/Wallet/TransferBalancePage.tsx index 7faabe5f3e0b..f04a8319dc0b 100644 --- a/src/pages/settings/Wallet/TransferBalancePage.tsx +++ b/src/pages/settings/Wallet/TransferBalancePage.tsx @@ -54,7 +54,6 @@ function TransferBalancePage() { const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); const [fundList] = useOnyx(ONYXKEYS.FUND_LIST); const paymentCardList = fundList ?? {}; - const transferBankAccountList = getWalletTransferBankAccounts(bankAccountList ?? {}); const paymentTypes = [ // Temporarily disable P2P debit card, see https://github.com/Expensify/App/pull/46323 @@ -81,7 +80,7 @@ function TransferBalancePage() { * Get the selected/default payment method account for wallet transfer */ function getSelectedPaymentMethodAccount(): PaymentMethod | undefined { - const paymentMethods = formatPaymentMethods(transferBankAccountList, paymentCardList, styles, translate); + const paymentMethods = formatPaymentMethods(getWalletTransferBankAccounts(bankAccountList ?? {}), paymentCardList, styles, translate); const defaultAccount = paymentMethods.find((method) => method.isDefault); const selectedAccount = paymentMethods.find( @@ -94,7 +93,7 @@ function TransferBalancePage() { saveWalletTransferMethodType(filterPaymentMethodType); // If we only have a single option for the given paymentMethodType do not force the user to make a selection - const combinedPaymentMethods = formatPaymentMethods(transferBankAccountList, paymentCardList, styles, translate); + const combinedPaymentMethods = formatPaymentMethods(getWalletTransferBankAccounts(bankAccountList ?? {}), paymentCardList, styles, translate); const filteredMethods = combinedPaymentMethods.filter((paymentMethod) => paymentMethod.accountType === filterPaymentMethodType); if (filteredMethods.length === 1) { diff --git a/tests/unit/PaymentUtilsTest.ts b/tests/unit/PaymentUtilsTest.ts index 84aa090c5a17..ac69df1d7c3c 100644 --- a/tests/unit/PaymentUtilsTest.ts +++ b/tests/unit/PaymentUtilsTest.ts @@ -646,45 +646,45 @@ describe('PaymentUtils', () => { }); describe('getWalletTransferBankAccounts', () => { - const createBankAccount = (bankAccountID: number, type: string, overrides: Partial = {}): BankAccount => ({ + type BankAccountOptions = { + type: string; + state?: string; + country?: string; + pendingAction?: BankAccount['pendingAction']; + }; + + const createBankAccount = (bankAccountID: number, {type, state = CONST.BANK_ACCOUNT.STATE.OPEN, country = CONST.COUNTRY.US, pendingAction}: BankAccountOptions): BankAccount => ({ accountType: CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT, + bankCurrency: CONST.CURRENCY.USD, methodID: bankAccountID, - accountData: { - bankAccountID, - type, - state: CONST.BANK_ACCOUNT.STATE.OPEN, - additionalData: {country: CONST.COUNTRY.US}, - }, - ...overrides, + pendingAction, + accountData: {bankAccountID, type, state, additionalData: {country}}, }); + const toBankAccountList = (bankAccounts: BankAccount[]): Record => + Object.fromEntries(bankAccounts.map((bankAccount) => [String(bankAccount.methodID), bankAccount])); + it('keeps only open personal US accounts', () => { - // Given a personal account next to a business account, the wallet pseudo-account, a closed personal account and a non-US personal account - const personal = createBankAccount(1, CONST.BANK_ACCOUNT.TYPE.PERSONAL); - const bankAccountList: Record = { - 1: personal, - 2: createBankAccount(2, CONST.BANK_ACCOUNT.TYPE.BUSINESS), - 3: createBankAccount(3, CONST.BANK_ACCOUNT_TYPES.WALLET), - 4: createBankAccount(4, CONST.BANK_ACCOUNT.TYPE.PERSONAL, { - accountData: {bankAccountID: 4, type: CONST.BANK_ACCOUNT.TYPE.PERSONAL, state: CONST.BANK_ACCOUNT.STATE.PENDING}, - }), - 5: createBankAccount(5, CONST.BANK_ACCOUNT.TYPE.PERSONAL, { - accountData: {bankAccountID: 5, type: CONST.BANK_ACCOUNT.TYPE.PERSONAL, state: CONST.BANK_ACCOUNT.STATE.OPEN, additionalData: {country: 'GB'}}, - }), - }; + // Given a personal account next to a business account, the wallet pseudo-account, a pending personal account and a non-US personal account + const personal = createBankAccount(1, {type: CONST.BANK_ACCOUNT.TYPE.PERSONAL}); + const bankAccountList = toBankAccountList([ + personal, + createBankAccount(2, {type: CONST.BANK_ACCOUNT.TYPE.BUSINESS}), + createBankAccount(3, {type: CONST.BANK_ACCOUNT_TYPES.WALLET}), + createBankAccount(4, {type: CONST.BANK_ACCOUNT.TYPE.PERSONAL, state: CONST.BANK_ACCOUNT.STATE.PENDING}), + createBankAccount(5, {type: CONST.BANK_ACCOUNT.TYPE.PERSONAL, country: 'GB'}), + ]); // When the wallet transfer destinations are picked, since Auth rejects a transfer to anything but an open personal US account const result = getWalletTransferBankAccounts(bankAccountList); // Then only the personal account remains, so the business one can't be offered or auto-selected - expect(result).toEqual({1: personal}); + expect(result).toEqual(toBankAccountList([personal])); }); it('drops a personal account pending deletion', () => { // Given a personal account the user just deleted offline - const bankAccountList: Record = { - 1: createBankAccount(1, CONST.BANK_ACCOUNT.TYPE.PERSONAL, {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}), - }; + const bankAccountList = toBankAccountList([createBankAccount(1, {type: CONST.BANK_ACCOUNT.TYPE.PERSONAL, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE})]); // When the wallet transfer destinations are picked const result = getWalletTransferBankAccounts(bankAccountList); From 49213276fdac5197dfaa3769c6cbf788d4203175 Mon Sep 17 00:00:00 2001 From: Mukher Date: Wed, 18 Nov 2026 10:57:58 +0500 Subject: [PATCH 3/4] Add bankCountry to test bank accounts --- tests/unit/PaymentUtilsTest.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/PaymentUtilsTest.ts b/tests/unit/PaymentUtilsTest.ts index ac69df1d7c3c..f1f3cb8815ba 100644 --- a/tests/unit/PaymentUtilsTest.ts +++ b/tests/unit/PaymentUtilsTest.ts @@ -656,6 +656,7 @@ describe('PaymentUtils', () => { const createBankAccount = (bankAccountID: number, {type, state = CONST.BANK_ACCOUNT.STATE.OPEN, country = CONST.COUNTRY.US, pendingAction}: BankAccountOptions): BankAccount => ({ accountType: CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT, bankCurrency: CONST.CURRENCY.USD, + bankCountry: CONST.COUNTRY.US, methodID: bankAccountID, pendingAction, accountData: {bankAccountID, type, state, additionalData: {country}}, From 90ae6735591552ba3f7b5e03b7e85f169945b19d Mon Sep 17 00:00:00 2001 From: Mukher Date: Mon, 23 Nov 2026 18:58:43 +0500 Subject: [PATCH 4/4] Clarify which wallet transfer checks come from Auth --- src/libs/PaymentUtils.ts | 2 +- tests/unit/PaymentUtilsTest.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/PaymentUtils.ts b/src/libs/PaymentUtils.ts index b06b286be5b8..47c47895a322 100644 --- a/src/libs/PaymentUtils.ts +++ b/src/libs/PaymentUtils.ts @@ -73,7 +73,7 @@ type BusinessBankAccountOption = { }; /** - * Auth only pays a wallet balance out to an open personal US bank account, business accounts are rejected. + * Auth rejects a wallet transfer to a bank account that is not open or not personal. The US check matches hasExpensifyPaymentMethod. */ function isWalletTransferBankAccount(bankAccountJSON: BankAccount): boolean { const bankAccount = new BankAccountModel(bankAccountJSON); diff --git a/tests/unit/PaymentUtilsTest.ts b/tests/unit/PaymentUtilsTest.ts index f1f3cb8815ba..289defc3e117 100644 --- a/tests/unit/PaymentUtilsTest.ts +++ b/tests/unit/PaymentUtilsTest.ts @@ -676,7 +676,7 @@ describe('PaymentUtils', () => { createBankAccount(5, {type: CONST.BANK_ACCOUNT.TYPE.PERSONAL, country: 'GB'}), ]); - // When the wallet transfer destinations are picked, since Auth rejects a transfer to anything but an open personal US account + // When the wallet transfer destinations are picked, since Auth rejects accounts that are not open or not personal and hasExpensifyPaymentMethod only counts US ones const result = getWalletTransferBankAccounts(bankAccountList); // Then only the personal account remains, so the business one can't be offered or auto-selected