Skip to content

Commit d79fcfc

Browse files
committed
Excluded User Still Sees “Your Split” Label in Split Expense UI
1 parent ccd795a commit d79fcfc

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

src/libs/TransactionPreviewUtils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {TranslationPaths} from '@src/languages/types';
55
import ROUTES from '@src/ROUTES';
66
import type * as OnyxTypes from '@src/types/onyx';
77
import {isEmptyObject} from '@src/types/utils/EmptyObject';
8+
import {getCurrentUserAccountID} from './actions/Report';
89
import {abandonReviewDuplicateTransactions, setReviewDuplicatesKey} from './actions/Transaction';
910
import {convertToDisplayString} from './CurrencyUtils';
1011
import DateUtils from './DateUtils';
@@ -324,8 +325,8 @@ function createTransactionPreviewConditionals({
324325

325326
// When there are no settled transactions in duplicates, show the "Keep this one" button
326327
const shouldShowKeepButton = areThereDuplicates;
327-
const shouldShowSplitShare = isBillSplit && !!requestAmount && requestAmount > 0;
328-
328+
const participantAccountIDs = isMoneyRequestAction(action) && isBillSplit ? (getOriginalMessage(action)?.participantAccountIDs ?? []) : [];
329+
const shouldShowSplitShare = isBillSplit && !!requestAmount && requestAmount > 0 && participantAccountIDs.includes(getCurrentUserAccountID());
329330
/*
330331
Show the merchant for IOUs and expenses only if:
331332
- the merchant is not empty, is custom, or is not related to scanning smartscan;

tests/unit/TransactionPreviewUtils.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ describe('TransactionPreviewUtils', () => {
175175
});
176176

177177
describe('createTransactionPreviewConditionals', () => {
178+
beforeAll(() => {
179+
Onyx.merge(ONYXKEYS.SESSION, {accountID: 999});
180+
});
181+
afterAll(() => {
182+
Onyx.clear([ONYXKEYS.SESSION]);
183+
});
184+
178185
it('should determine RBR visibility according to violation and hold conditions', () => {
179186
const functionArgs = {
180187
...basicProps,
@@ -203,6 +210,15 @@ describe('TransactionPreviewUtils', () => {
203210
transactionDetails: {
204211
amount: 1,
205212
},
213+
action: {
214+
...basicProps.action,
215+
originalMessage: {
216+
participantAccountIDs: [999],
217+
amount: 100,
218+
currency: 'USD',
219+
type: CONST.REPORT.ACTIONS.TYPE.IOU,
220+
},
221+
},
206222
};
207223
const result = createTransactionPreviewConditionals(functionArgs);
208224
expect(result.shouldShowSplitShare).toBeTruthy();
@@ -256,6 +272,35 @@ describe('TransactionPreviewUtils', () => {
256272
const result = createTransactionPreviewConditionals(functionArgs);
257273
expect(result.shouldShowDescription).toBeTruthy();
258274
});
275+
276+
it('should show split share only if user is part of the split bill transaction', async () => {
277+
const functionArgs = {
278+
...basicProps,
279+
isBillSplit: true,
280+
transactionDetails: {amount: 100},
281+
action: {
282+
...basicProps.action,
283+
originalMessage: {
284+
participantAccountIDs: [999],
285+
amount: 100,
286+
currency: 'USD',
287+
type: CONST.REPORT.ACTIONS.TYPE.IOU,
288+
},
289+
},
290+
};
291+
const result = createTransactionPreviewConditionals(functionArgs);
292+
expect(result.shouldShowSplitShare).toBeTruthy();
293+
});
294+
295+
it('should not show split share if user is not a participant', async () => {
296+
const functionArgs = {
297+
...basicProps,
298+
isBillSplit: true,
299+
transactionDetails: {amount: 100},
300+
};
301+
const result = createTransactionPreviewConditionals(functionArgs);
302+
expect(result.shouldShowSplitShare).toBeFalsy();
303+
});
259304
});
260305

261306
describe('getViolationTranslatePath', () => {

0 commit comments

Comments
 (0)