Skip to content

Commit b6c9fce

Browse files
committed
Fix displaying sender/receiver for split money request preview
1 parent deeddcb commit b6c9fce

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function TransactionPreviewContent({
4444
report,
4545
transaction,
4646
violations,
47+
transactionRawAmount,
4748
offlineWithFeedbackOnClose,
4849
containerStyles,
4950
transactionPreviewWidth,
@@ -148,16 +149,14 @@ function TransactionPreviewContent({
148149
};
149150
}
150151

151-
// For IOU, we want the unprocessed amount because it is important whether the amount was positive or negative
152-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
153-
const transactionRawAmount = (transaction?.modifiedAmount || transaction?.amount) ?? 0;
152+
// For IOU or Split, we want the unprocessed amount because it is important whether the amount was positive or negative
154153
const payerAndReceiver = getIOUPayerAndReceiver(managerID, ownerAccountID, personalDetails, transactionRawAmount);
155154

156155
return {
157156
from: payerAndReceiver.from,
158157
to: payerAndReceiver.to,
159158
};
160-
}, [managerID, ownerAccountID, personalDetails, shouldShowPayerAndReceiver, transaction?.amount, transaction?.modifiedAmount]);
159+
}, [managerID, ownerAccountID, personalDetails, shouldShowPayerAndReceiver, transactionRawAmount]);
161160

162161
const shouldShowIOUHeader = !!from && !!to;
163162

src/components/ReportActionItem/TransactionPreview/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ function TransactionPreview(props: TransactionPreviewProps) {
8686
transactionPreview = originalTransaction;
8787
}
8888

89+
// See description of `transactionRawAmount` prop for more context
90+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
91+
const transactionRawAmount = (transaction?.modifiedAmount || transaction?.amount) ?? 0;
92+
8993
const iouAction = isBillSplit && originalTransaction ? (getIOUActionForReportID(chatReportID, originalTransaction.transactionID) ?? action) : action;
9094

9195
const shouldDisableOnPress = isBillSplit && isEmptyObject(transaction);
@@ -112,6 +116,7 @@ function TransactionPreview(props: TransactionPreviewProps) {
112116
chatReport={chatReport}
113117
personalDetails={personalDetails}
114118
transaction={transactionPreview}
119+
transactionRawAmount={transactionRawAmount}
115120
report={report}
116121
violations={violations}
117122
offlineWithFeedbackOnClose={offlineWithFeedbackOnClose}
@@ -135,6 +140,7 @@ function TransactionPreview(props: TransactionPreviewProps) {
135140
chatReport={chatReport}
136141
personalDetails={personalDetails}
137142
transaction={originalTransaction}
143+
transactionRawAmount={transactionRawAmount}
138144
report={report}
139145
violations={violations}
140146
offlineWithFeedbackOnClose={offlineWithFeedbackOnClose}

src/components/ReportActionItem/TransactionPreview/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ type TransactionPreviewContentProps = {
102102
/** Holds the transaction data entry from Onyx */
103103
transaction: OnyxEntry<Transaction>;
104104

105+
/** The original amount value on the transaction. This is used to deduce who is the sender and who is the receiver of the money request
106+
* In case of Splits the property `transaction` is actually an original transaction (for the whole split) and it does not have the data required to deduce who is the sender */
107+
transactionRawAmount: number;
108+
105109
/** Represents the action entry from Onyx */
106110
action: OnyxEntry<ReportAction>;
107111

0 commit comments

Comments
 (0)