diff --git a/src/libs/TransactionPreviewUtils.ts b/src/libs/TransactionPreviewUtils.ts index 1f7888a2fd5a..e6edd217ecca 100644 --- a/src/libs/TransactionPreviewUtils.ts +++ b/src/libs/TransactionPreviewUtils.ts @@ -5,6 +5,7 @@ import type {TranslationPaths} from '@src/languages/types'; import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; +import {getCurrentUserAccountID} from './actions/Report'; import {abandonReviewDuplicateTransactions, setReviewDuplicatesKey} from './actions/Transaction'; import {convertToDisplayString} from './CurrencyUtils'; import DateUtils from './DateUtils'; @@ -324,8 +325,8 @@ function createTransactionPreviewConditionals({ // When there are no settled transactions in duplicates, show the "Keep this one" button const shouldShowKeepButton = areThereDuplicates; - const shouldShowSplitShare = isBillSplit && !!requestAmount && requestAmount > 0; - + const participantAccountIDs = isMoneyRequestAction(action) && isBillSplit ? (getOriginalMessage(action)?.participantAccountIDs ?? []) : []; + const shouldShowSplitShare = isBillSplit && !!requestAmount && requestAmount > 0 && participantAccountIDs.includes(getCurrentUserAccountID()); /* Show the merchant for IOUs and expenses only if: - the merchant is not empty, is custom, or is not related to scanning smartscan; diff --git a/tests/unit/TransactionPreviewUtils.test.ts b/tests/unit/TransactionPreviewUtils.test.ts index 786a1912c723..800b37e5a829 100644 --- a/tests/unit/TransactionPreviewUtils.test.ts +++ b/tests/unit/TransactionPreviewUtils.test.ts @@ -175,6 +175,13 @@ describe('TransactionPreviewUtils', () => { }); describe('createTransactionPreviewConditionals', () => { + beforeAll(() => { + Onyx.merge(ONYXKEYS.SESSION, {accountID: 999}); + }); + afterAll(() => { + Onyx.clear([ONYXKEYS.SESSION]); + }); + it('should determine RBR visibility according to violation and hold conditions', () => { const functionArgs = { ...basicProps, @@ -203,6 +210,15 @@ describe('TransactionPreviewUtils', () => { transactionDetails: { amount: 1, }, + action: { + ...basicProps.action, + originalMessage: { + participantAccountIDs: [999], + amount: 100, + currency: 'USD', + type: CONST.REPORT.ACTIONS.TYPE.IOU, + }, + }, }; const result = createTransactionPreviewConditionals(functionArgs); expect(result.shouldShowSplitShare).toBeTruthy(); @@ -256,6 +272,35 @@ describe('TransactionPreviewUtils', () => { const result = createTransactionPreviewConditionals(functionArgs); expect(result.shouldShowDescription).toBeTruthy(); }); + + it('should show split share only if user is part of the split bill transaction', () => { + const functionArgs = { + ...basicProps, + isBillSplit: true, + transactionDetails: {amount: 100}, + action: { + ...basicProps.action, + originalMessage: { + participantAccountIDs: [999], + amount: 100, + currency: 'USD', + type: CONST.REPORT.ACTIONS.TYPE.IOU, + }, + }, + }; + const result = createTransactionPreviewConditionals(functionArgs); + expect(result.shouldShowSplitShare).toBeTruthy(); + }); + + it('should not show split share if user is not a participant', () => { + const functionArgs = { + ...basicProps, + isBillSplit: true, + transactionDetails: {amount: 100}, + }; + const result = createTransactionPreviewConditionals(functionArgs); + expect(result.shouldShowSplitShare).toBeFalsy(); + }); }); describe('getViolationTranslatePath', () => {