From 384326783139d4708fb02b4df260691d48b406ad Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 10 Nov 2025 16:40:52 +0700 Subject: [PATCH 01/10] refactor: Update transaction handling in Search component and remove unused transactionType field from SearchTransaction type --- src/components/Search/index.tsx | 3 ++- src/types/onyx/SearchResults.ts | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 9ae0110fd7bd..fa436dbb391f 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -33,6 +33,7 @@ import Log from '@libs/Log'; import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import type {PlatformStackNavigationProp} from '@libs/Navigation/PlatformStackNavigation/types'; import Performance from '@libs/Performance'; +import {getIOUActionForTransactionID} from '@libs/ReportActionsUtils'; import {canEditFieldOfMoneyRequest, selectFilteredReportActions} from '@libs/ReportUtils'; import {buildCannedSearchQuery, buildSearchQueryJSON, buildSearchQueryString} from '@libs/SearchQueryUtils'; import { @@ -627,7 +628,7 @@ function Search({ const backTo = Navigation.getActiveRoute(); // If we're trying to open a transaction without a transaction thread, let's create the thread and navigate the user - if (isTransactionItem && item.transactionThreadReportID === CONST.REPORT.UNREPORTED_REPORT_ID) { + if (isTransactionItem && getIOUActionForTransactionID() === CONST.REPORT.UNREPORTED_REPORT_ID) { createAndOpenSearchTransactionThread(item, hash, backTo); return; } diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index de1adab7c3ce..a3bd7752b7f8 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -271,9 +271,6 @@ type SearchTransaction = { /** The transaction category */ category: string; - /** The type of request */ - transactionType: ValueOf; - /** The type of report the transaction is associated with */ reportType: string; From df3d22eab8c89a9988493e205b30900671cfdf44 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 10 Nov 2025 16:46:22 +0700 Subject: [PATCH 02/10] fix UTs --- tests/unit/ReportUtilsTest.ts | 1 - tests/unit/Search/SearchUIUtilsTest.ts | 12 ------------ tests/unit/Search/handleActionButtonPressTest.ts | 2 -- tests/unit/TransactionGroupListItemTest.tsx | 1 - 4 files changed, 16 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index baba72c4b8da..39972d553fa6 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -1657,7 +1657,6 @@ describe('ReportUtils', () => { amount: 1000, currency: 'USD', merchant: 'Test Merchant', - transactionType: 'cash', action: 'submit', created: testDate, modifiedMerchant: 'Test Merchant', diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index a21f27c56f8a..7bc14008c8ca 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -397,7 +397,6 @@ const searchResults: OnyxTypes.SearchResults = { tag: '', transactionID, transactionThreadReportID: '456', - transactionType: 'cash', receipt: undefined, taxAmount: undefined, mccGroup: undefined, @@ -439,7 +438,6 @@ const searchResults: OnyxTypes.SearchResults = { tag: '', transactionID: transactionID2, transactionThreadReportID: '456', - transactionType: 'cash', receipt: undefined, taxAmount: undefined, mccGroup: undefined, @@ -481,7 +479,6 @@ const searchResults: OnyxTypes.SearchResults = { tag: '', transactionID: transactionID3, transactionThreadReportID: '8287398995021380', - transactionType: 'cash', receipt: undefined, taxAmount: undefined, description: '', @@ -524,7 +521,6 @@ const searchResults: OnyxTypes.SearchResults = { tag: '', transactionID: transactionID4, transactionThreadReportID: '1014872441234902', - transactionType: 'cash', description: '', receipt: undefined, taxAmount: undefined, @@ -834,7 +830,6 @@ const transactionsListItems = [ }, transactionID: '1', transactionThreadReportID: '456', - transactionType: 'cash', receipt: undefined, taxAmount: undefined, description: '', @@ -901,7 +896,6 @@ const transactionsListItems = [ }, transactionID: '2', transactionThreadReportID: '456', - transactionType: 'cash', receipt: undefined, taxAmount: undefined, description: '', @@ -952,7 +946,6 @@ const transactionsListItems = [ tag: '', transactionID: '3', transactionThreadReportID: '8287398995021380', - transactionType: 'cash', from: { accountID: 18439984, avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_3.png', @@ -1020,7 +1013,6 @@ const transactionsListItems = [ tag: '', transactionID: '4', transactionThreadReportID: '1014872441234902', - transactionType: 'cash', from: { accountID: 18439984, avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_3.png', @@ -1149,7 +1141,6 @@ const transactionReportGroupListItems = [ }, transactionID: '1', transactionThreadReportID: '456', - transactionType: 'cash', receipt: undefined, taxAmount: undefined, mccGroup: undefined, @@ -1259,7 +1250,6 @@ const transactionReportGroupListItems = [ }, transactionID: '2', transactionThreadReportID: '456', - transactionType: 'cash', receipt: undefined, taxAmount: undefined, mccGroup: undefined, @@ -2400,7 +2390,6 @@ describe('SearchUIUtils', () => { tag: '', transactionID: '1805965960759424086', transactionThreadReportID: '4139222832581831', - transactionType: 'cash', pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, convertedAmount: -5000, convertedCurrency: 'USD', @@ -2533,7 +2522,6 @@ describe('SearchUIUtils', () => { tag: '', transactionID: '1805965960759424086', transactionThreadReportID: '4139222832581831', - transactionType: 'cash', convertedAmount: -5000, convertedCurrency: 'USD', }, diff --git a/tests/unit/Search/handleActionButtonPressTest.ts b/tests/unit/Search/handleActionButtonPressTest.ts index 1076c6c92014..4d0c07d3bdc0 100644 --- a/tests/unit/Search/handleActionButtonPressTest.ts +++ b/tests/unit/Search/handleActionButtonPressTest.ts @@ -111,7 +111,6 @@ const mockReportItemWithHold = { tag: '', transactionID: '1049531721038862176', transactionThreadReportID: '2957345659269055', - transactionType: 'cash', from: { accountID: 1206, avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', @@ -201,7 +200,6 @@ const mockReportItemWithHold = { tag: '', transactionID: '5345995386715609966', transactionThreadReportID: '740282333335072', - transactionType: 'cash', from: { accountID: 1206, avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png', diff --git a/tests/unit/TransactionGroupListItemTest.tsx b/tests/unit/TransactionGroupListItemTest.tsx index 28b2b8ae830f..20e8b424a3c1 100644 --- a/tests/unit/TransactionGroupListItemTest.tsx +++ b/tests/unit/TransactionGroupListItemTest.tsx @@ -59,7 +59,6 @@ const mockTransaction: TransactionListItemType = { tag: '', transactionID: '1', transactionThreadReportID: '2925191332104975', - transactionType: 'cash', action: 'approve', allActions: ['approve'], formattedFrom: 'Main Applause QA', From 704b67e997056772ec47acd6873fbf62b79424b0 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 10 Nov 2025 17:13:17 +0700 Subject: [PATCH 03/10] fix type --- src/components/Search/index.tsx | 2 +- .../TransactionItemRow/DataCells/TypeCell.tsx | 18 +++------ src/components/TransactionItemRow/index.tsx | 3 -- src/libs/TransactionUtils/index.ts | 38 +++++++++++++++++++ src/types/onyx/SearchResults.ts | 4 -- tests/unit/Search/SearchUIUtilsTest.ts | 2 - 6 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index fa436dbb391f..56ca234bac44 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -628,7 +628,7 @@ function Search({ const backTo = Navigation.getActiveRoute(); // If we're trying to open a transaction without a transaction thread, let's create the thread and navigate the user - if (isTransactionItem && getIOUActionForTransactionID() === CONST.REPORT.UNREPORTED_REPORT_ID) { + if (isTransactionItem && item.transactionThreadReportID === CONST.REPORT.UNREPORTED_REPORT_ID) { createAndOpenSearchTransactionThread(item, hash, backTo); return; } diff --git a/src/components/TransactionItemRow/DataCells/TypeCell.tsx b/src/components/TransactionItemRow/DataCells/TypeCell.tsx index f22d335ec155..74e51b73c3d9 100644 --- a/src/components/TransactionItemRow/DataCells/TypeCell.tsx +++ b/src/components/TransactionItemRow/DataCells/TypeCell.tsx @@ -3,24 +3,15 @@ import Icon from '@components/Icon'; import * as Expensicons from '@components/Icon/Expensicons'; import TextWithTooltip from '@components/TextWithTooltip'; import useLocalize from '@hooks/useLocalize'; +import useOnyx from '@hooks/useOnyx'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import {isExpensifyCardTransaction, isPending} from '@libs/TransactionUtils'; +import {getTransactionType, isExpensifyCardTransaction, isPending} from '@libs/TransactionUtils'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; +import ONYXKEYS from '@src/ONYXKEYS'; import type TransactionDataCellProps from './TransactionDataCellProps'; -// If the transaction is cash, it has the type CONST.EXPENSE.TYPE.CASH_CARD_NAME. -// If there is no credit card name, it means it couldn't be a card transaction, -// so we assume it's cash. Any other type is treated as a card transaction. -// same in getTypeText -const getType = (cardName?: string) => { - if (!cardName || cardName.includes(CONST.EXPENSE.TYPE.CASH_CARD_NAME)) { - return CONST.SEARCH.TRANSACTION_TYPE.CASH; - } - return CONST.SEARCH.TRANSACTION_TYPE.CARD; -}; - const getTypeIcon = (type?: string) => { switch (type) { case CONST.SEARCH.TRANSACTION_TYPE.CARD: @@ -47,8 +38,9 @@ const getTypeText = (type?: string): TranslationPaths => { function TypeCell({transactionItem, shouldUseNarrowLayout, shouldShowTooltip}: TransactionDataCellProps) { const {translate} = useLocalize(); + const [cardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true}); const theme = useTheme(); - const type = transactionItem.transactionType ?? getType(transactionItem.cardName); + const type = getTransactionType(transactionItem, cardList); const isPendingExpensifyCardTransaction = isExpensifyCardTransaction(transactionItem) && isPending(transactionItem); const typeIcon = isPendingExpensifyCardTransaction ? Expensicons.CreditCardHourglass : getTypeIcon(type); const typeText = isPendingExpensifyCardTransaction ? 'iou.pending' : getTypeText(type); diff --git a/src/components/TransactionItemRow/index.tsx b/src/components/TransactionItemRow/index.tsx index ce8d1b05a3a1..a3863162daa5 100644 --- a/src/components/TransactionItemRow/index.tsx +++ b/src/components/TransactionItemRow/index.tsx @@ -75,9 +75,6 @@ type TransactionWithOptionalSearchFields = TransactionWithOptionalHighlight & { /** information about whether to show the description, that is provided on Reports page */ shouldShowDescription?: boolean; - /** Type of transaction */ - transactionType?: ValueOf; - /** Precomputed violations */ violations?: TransactionViolation[]; diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index da4424cb4280..d409248f0c71 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -49,6 +49,7 @@ import type {IOUType} from '@src/CONST'; import IntlStore from '@src/languages/IntlStore'; import ONYXKEYS from '@src/ONYXKEYS'; import type { + CardList, OnyxInputOrEntry, Policy, PolicyCategories, @@ -269,6 +270,42 @@ function getExpenseType(transaction: OnyxEntry): ValueOf, cardList?: CardList): ValueOf { + if (!transaction) { + return CONST.SEARCH.TRANSACTION_TYPE.CARD; + } + + const customUnitName = transaction?.comment?.customUnit?.name; + + if (customUnitName === CONST.CUSTOM_UNITS.NAME_DISTANCE) { + return CONST.SEARCH.TRANSACTION_TYPE.DISTANCE; + } + + if (customUnitName === CONST.CUSTOM_UNITS.NAME_PER_DIEM_INTERNATIONAL) { + return CONST.SEARCH.TRANSACTION_TYPE.PER_DIEM; + } + + const cardID = transaction?.cardID; + if (cardID && cardList?.[cardID]?.cardName === '__CASH__') { + return CONST.SEARCH.TRANSACTION_TYPE.CASH; + } + + if (transaction?.cardName && transaction?.cardName?.includes(CONST.EXPENSE.TYPE.CASH_CARD_NAME)) { + return CONST.SEARCH.TRANSACTION_TYPE.CASH; + } + + return CONST.SEARCH.TRANSACTION_TYPE.CARD; +} + function isManualRequest(transaction: Transaction): boolean { // This is used during the expense creation flow before the transaction has been saved to the server if (lodashHas(transaction, 'iouRequestType')) { @@ -2048,6 +2085,7 @@ export { getDescription, getRequestType, getExpenseType, + getTransactionType, isManualRequest, isScanRequest, getAmount, diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index a3bd7752b7f8..fa3ebc660da8 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -440,9 +440,6 @@ type SearchWithdrawalIDGroup = { debitPosted: string; }; -/** Types of searchable transactions */ -type SearchTransactionType = ValueOf; - /** * A utility type that creates a record where all keys are strings that start with a specified prefix. */ @@ -478,7 +475,6 @@ export type { ListItemDataType, SearchTask, SearchTransaction, - SearchTransactionType, SearchTransactionAction, SearchPersonalDetails, SearchDataTypes, diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 7bc14008c8ca..bca12b11352b 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -1809,7 +1809,6 @@ describe('SearchUIUtils', () => { [`transactions_${distanceTransactionID}`]: { ...searchResults.data[`transactions_${transactionID}`], transactionID: distanceTransactionID, - transactionType: CONST.SEARCH.TRANSACTION_TYPE.DISTANCE, iouRequestType: CONST.IOU.REQUEST_TYPE.DISTANCE, }, }, @@ -1835,7 +1834,6 @@ describe('SearchUIUtils', () => { [`transactions_${distanceTransactionID}`]: { ...searchResults.data[`transactions_${transactionID}`], transactionID: distanceTransactionID, - transactionType: CONST.SEARCH.TRANSACTION_TYPE.DISTANCE, iouRequestType: CONST.IOU.REQUEST_TYPE.DISTANCE, }, }, From 765e6c5fa53da6e3fc18d07f8d45b5e213719943 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 10 Nov 2025 17:24:32 +0700 Subject: [PATCH 04/10] add UTs --- src/components/Search/index.tsx | 1 - src/libs/TransactionUtils/index.ts | 2 +- tests/unit/TransactionUtilsTest.ts | 53 ++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 56ca234bac44..9ae0110fd7bd 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -33,7 +33,6 @@ import Log from '@libs/Log'; import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import type {PlatformStackNavigationProp} from '@libs/Navigation/PlatformStackNavigation/types'; import Performance from '@libs/Performance'; -import {getIOUActionForTransactionID} from '@libs/ReportActionsUtils'; import {canEditFieldOfMoneyRequest, selectFilteredReportActions} from '@libs/ReportUtils'; import {buildCannedSearchQuery, buildSearchQueryJSON, buildSearchQueryString} from '@libs/SearchQueryUtils'; import { diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index d409248f0c71..d55c1d4b9b14 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -299,7 +299,7 @@ function getTransactionType(transaction: OnyxEntry, cardList?: Card return CONST.SEARCH.TRANSACTION_TYPE.CASH; } - if (transaction?.cardName && transaction?.cardName?.includes(CONST.EXPENSE.TYPE.CASH_CARD_NAME)) { + if (transaction?.cardName?.includes(CONST.EXPENSE.TYPE.CASH_CARD_NAME)) { return CONST.SEARCH.TRANSACTION_TYPE.CASH; } diff --git a/tests/unit/TransactionUtilsTest.ts b/tests/unit/TransactionUtilsTest.ts index 0eb538d2ea26..c65b2f442c88 100644 --- a/tests/unit/TransactionUtilsTest.ts +++ b/tests/unit/TransactionUtilsTest.ts @@ -10,6 +10,7 @@ import type {ReportCollectionDataSet} from '@src/types/onyx/Report'; import type {TransactionCustomUnit} from '@src/types/onyx/Transaction'; import * as TransactionUtils from '../../src/libs/TransactionUtils'; import type {Policy, Report, Transaction} from '../../src/types/onyx'; +import type {CardList} from '../../src/types/onyx/Card'; import createRandomPolicy, {createCategoryTaxExpenseRules} from '../utils/collections/policies'; import {createRandomReport} from '../utils/collections/reports'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -399,6 +400,58 @@ describe('TransactionUtils', () => { }); }); + describe('getTransactionType', () => { + it('returns card when the transaction is null', () => { + expect(TransactionUtils.getTransactionType(null as unknown as Transaction)).toBe(CONST.SEARCH.TRANSACTION_TYPE.CARD); + }); + + it('returns distance when the transaction has a distance custom unit', () => { + const transaction = generateTransaction({ + comment: { + customUnit: { + name: CONST.CUSTOM_UNITS.NAME_DISTANCE, + }, + }, + }); + + expect(TransactionUtils.getTransactionType(transaction)).toBe(CONST.SEARCH.TRANSACTION_TYPE.DISTANCE); + }); + + it('returns per diem when the transaction has an international per diem custom unit', () => { + const transaction = generateTransaction({ + comment: { + customUnit: { + name: CONST.CUSTOM_UNITS.NAME_PER_DIEM_INTERNATIONAL, + }, + }, + }); + + expect(TransactionUtils.getTransactionType(transaction)).toBe(CONST.SEARCH.TRANSACTION_TYPE.PER_DIEM); + }); + + it('returns cash when the transaction cardID maps to a cash card in the card list', () => { + const cardID = 101; + const cardList = { + [cardID]: { + cardName: '__CASH__', + }, + } as unknown as CardList; + const transaction = generateTransaction({ + cardID, + }); + + expect(TransactionUtils.getTransactionType(transaction, cardList)).toBe(CONST.SEARCH.TRANSACTION_TYPE.CASH); + }); + + it('returns cash when the transaction card name includes the cash card name substring', () => { + const transaction = generateTransaction({ + cardName: `Example ${CONST.EXPENSE.TYPE.CASH_CARD_NAME}`, + }); + + expect(TransactionUtils.getTransactionType(transaction)).toBe(CONST.SEARCH.TRANSACTION_TYPE.CASH); + }); + }); + describe('shouldShowRTERViolationMessage', () => { it('should return true if transaction is receipt being scanned', () => { const transaction = generateTransaction({ From 479a9da28bae456c5edcfbcf4d935dd010bc3809 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 10 Nov 2025 18:28:04 +0700 Subject: [PATCH 05/10] fix UTs --- tests/unit/Search/SearchUIUtilsTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index bca12b11352b..de7d8ee784a4 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -1821,7 +1821,7 @@ describe('SearchUIUtils', () => { expect(distanceTransaction).toBeDefined(); expect(distanceTransaction?.iouRequestType).toBe(CONST.IOU.REQUEST_TYPE.DISTANCE); - const expectedPropertyCount = 57; + const expectedPropertyCount = 56; expect(Object.keys(distanceTransaction ?? {}).length).toBe(expectedPropertyCount); }); @@ -1848,7 +1848,7 @@ describe('SearchUIUtils', () => { expect(distanceTransaction).toBeDefined(); expect(distanceTransaction?.iouRequestType).toBe(CONST.IOU.REQUEST_TYPE.DISTANCE); - const expectedPropertyCount = 57; + const expectedPropertyCount = 56; expect(Object.keys(distanceTransaction ?? {}).length).toBe(expectedPropertyCount); }); From c7295f4c385e21918b9c3ac7cff83df631944ec2 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 10 Nov 2025 23:41:33 +0700 Subject: [PATCH 06/10] fix UTs --- tests/unit/ReportUtilsTest.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 39972d553fa6..04c33fc9eb22 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -1657,7 +1657,6 @@ describe('ReportUtils', () => { amount: 1000, currency: 'USD', merchant: 'Test Merchant', - action: 'submit', created: testDate, modifiedMerchant: 'Test Merchant', } as SearchTransaction; From e533206a769775d377d19c6061eca6ee6b7b0b5e Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 12 Nov 2025 15:34:51 +0700 Subject: [PATCH 07/10] fix some minor comment --- src/CONST/index.ts | 3 +++ src/libs/TransactionUtils/index.ts | 6 +----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 4840da1ed82f..0e205c9c5d6f 100755 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -3442,6 +3442,9 @@ const CONST = { LAST_BUSINESS_DAY_OF_MONTH: 'LAST_BUSINESS_DAY_OF_MONTH', CUSTOM_DAY_OF_MONTH: 'CUSTOM_DAY_OF_MONTH', }, + CARD_NAME: { + CASH: '__CASH__', + }, CARD_LIST_THRESHOLD: 8, DEFAULT_EXPORT_TYPE: 'default', EXPORT_CARD_TYPES: { diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index d55c1d4b9b14..cffca7b48aa6 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -280,10 +280,6 @@ function getExpenseType(transaction: OnyxEntry): ValueOf, cardList?: CardList): ValueOf { - if (!transaction) { - return CONST.SEARCH.TRANSACTION_TYPE.CARD; - } - const customUnitName = transaction?.comment?.customUnit?.name; if (customUnitName === CONST.CUSTOM_UNITS.NAME_DISTANCE) { @@ -295,7 +291,7 @@ function getTransactionType(transaction: OnyxEntry, cardList?: Card } const cardID = transaction?.cardID; - if (cardID && cardList?.[cardID]?.cardName === '__CASH__') { + if (cardID && cardList?.[cardID]?.cardName === CONST.COMPANY_CARDS.CARD_NAME.CASH) { return CONST.SEARCH.TRANSACTION_TYPE.CASH; } From c272dd0923faacc68cf6e47894eec20dba99e53d Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 13 Nov 2025 17:23:04 +0700 Subject: [PATCH 08/10] minor update --- src/libs/TransactionUtils/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index cffca7b48aa6..09a50d9ec629 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -295,7 +295,7 @@ function getTransactionType(transaction: OnyxEntry, cardList?: Card return CONST.SEARCH.TRANSACTION_TYPE.CASH; } - if (transaction?.cardName?.includes(CONST.EXPENSE.TYPE.CASH_CARD_NAME)) { + if (!transaction?.cardName || transaction?.cardName?.includes(CONST.EXPENSE.TYPE.CASH_CARD_NAME)) { return CONST.SEARCH.TRANSACTION_TYPE.CASH; } From 55586efa3500bde056c5587199e8e29d34a22574 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 13 Nov 2025 17:49:51 +0700 Subject: [PATCH 09/10] fix UTs --- tests/unit/TransactionUtilsTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/TransactionUtilsTest.ts b/tests/unit/TransactionUtilsTest.ts index c65b2f442c88..bd64495c7311 100644 --- a/tests/unit/TransactionUtilsTest.ts +++ b/tests/unit/TransactionUtilsTest.ts @@ -402,7 +402,7 @@ describe('TransactionUtils', () => { describe('getTransactionType', () => { it('returns card when the transaction is null', () => { - expect(TransactionUtils.getTransactionType(null as unknown as Transaction)).toBe(CONST.SEARCH.TRANSACTION_TYPE.CARD); + expect(TransactionUtils.getTransactionType(null as unknown as Transaction)).toBe(CONST.SEARCH.TRANSACTION_TYPE.CASH); }); it('returns distance when the transaction has a distance custom unit', () => { From 05e0c3c5ba676e0271db050274c48e67bbf709d9 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 19 Nov 2025 21:17:39 +0700 Subject: [PATCH 10/10] add UTs --- tests/unit/Search/SearchUIUtilsTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index d71b17dd08de..441bb1dd5c50 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -1794,7 +1794,7 @@ describe('SearchUIUtils', () => { expect(distanceTransaction).toBeDefined(); expect(distanceTransaction?.iouRequestType).toBe(CONST.IOU.REQUEST_TYPE.DISTANCE); - const expectedPropertyCount = 52; + const expectedPropertyCount = 51; expect(Object.keys(distanceTransaction ?? {}).length).toBe(expectedPropertyCount); }); @@ -1827,7 +1827,7 @@ describe('SearchUIUtils', () => { expect(distanceTransaction).toBeDefined(); expect(distanceTransaction?.iouRequestType).toBe(CONST.IOU.REQUEST_TYPE.DISTANCE); - const expectedPropertyCount = 52; + const expectedPropertyCount = 51; expect(Object.keys(distanceTransaction ?? {}).length).toBe(expectedPropertyCount); });