Skip to content

Commit f6cfcb3

Browse files
committed
use transaction currency instead of checking between transactionThreadReport and report
1 parent b5ae144 commit f6cfcb3

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/pages/home/ReportScreen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ function ReportScreen({
291291
return [];
292292
}
293293

294-
const reportActions = Object.values(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`] ?? {});
294+
const reportActions = allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`] ?? [];
295295
return ReportActionsUtils.getSortedReportActionsForDisplay(reportActions);
296296
}, [allReportActions, transactionThreadReportID]);
297297

src/pages/home/report/ReportActionItem.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ import * as User from '@userActions/User';
6262
import CONST from '@src/CONST';
6363
import ONYXKEYS from '@src/ONYXKEYS';
6464
import ROUTES from '@src/ROUTES';
65-
import {isEmptyObject} from '@src/types/utils/EmptyObject';
6665
import AnimatedEmptyStateBackground from './AnimatedEmptyStateBackground';
6766
import MiniReportActionContextMenu from './ContextMenu/MiniReportActionContextMenu';
6867
import * as ReportActionContextMenu from './ContextMenu/ReportActionContextMenu';
@@ -78,6 +77,7 @@ import ReportActionItemSingle from './ReportActionItemSingle';
7877
import ReportActionItemThread from './ReportActionItemThread';
7978
import reportActionPropTypes from './reportActionPropTypes';
8079
import ReportAttachmentsContext from './ReportAttachmentsContext';
80+
import transactionPropTypes from '@components/transactionPropTypes';
8181

8282
const propTypes = {
8383
...windowDimensionsPropTypes,
@@ -129,6 +129,9 @@ const propTypes = {
129129
/** All the report actions belonging to the current report */
130130
reportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)),
131131

132+
/** All the transactions shared wit hthe user */
133+
transactions: PropTypes.objectOf(PropTypes.shape(transactionPropTypes)),
134+
132135
/** Callback to be called on onPress */
133136
onPress: PropTypes.func,
134137
};
@@ -144,6 +147,7 @@ const defaultProps = {
144147
userWallet: {},
145148
parentReportActions: {},
146149
reportActions: {},
150+
transactions: {},
147151
onPress: undefined,
148152
};
149153

@@ -167,13 +171,20 @@ function ReportActionItem(props) {
167171
const originalReport = props.report.reportID === originalReportID ? props.report : ReportUtils.getReport(originalReportID);
168172
const isReportActionLinked = props.linkedReportActionID && props.action.reportActionID && props.linkedReportActionID === props.action.reportActionID;
169173
const transactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(props.reportActions);
174+
let transaction = {};
170175
const transactionThreadReport = useMemo(() => {
171176
if (transactionThreadReportID === '0') {
172177
return {};
173178
}
174-
return props.reports[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? {};
175-
}, [props.reports, transactionThreadReportID]);
179+
const report = props.reports[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? {};
180+
181+
// Get the transaction associated with the report
182+
const transactionID = props.reportActions?.[report.parentReportActionID ?? '']?.originalMessage?.IOUTransactionID ?? 0;
183+
transaction = props.transactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
184+
return report;
185+
}, [props.reports, transactionThreadReportID, props.reportActions, props.transactions]);
176186

187+
const transactionCurrency = !_.isEmpty(transaction) ? (transaction.modifiedCurrency ?? transaction.currency) : props.report.currency;
177188
const reportScrollManager = useReportScrollManager();
178189

179190
const highlightedBackgroundColorIfNeeded = useMemo(
@@ -707,9 +718,9 @@ function ReportActionItem(props) {
707718
if (ReportUtils.isExpenseReport(props.report) || ReportUtils.isIOUReport(props.report)) {
708719
return (
709720
<OfflineWithFeedback pendingAction={props.action.pendingAction}>
710-
{transactionThreadReport && !isEmptyObject(transactionThreadReport) ? (
721+
{transactionThreadReport && !_.isEmpty(transactionThreadReport) ? (
711722
<>
712-
{transactionThreadReport.currency !== props.report.currency && (
723+
{transactionCurrency !== props.report.currency && (
713724
<MoneyReportView
714725
report={props.report}
715726
policy={props.policy}
@@ -721,7 +732,7 @@ function ReportActionItem(props) {
721732
<MoneyRequestView
722733
report={transactionThreadReport}
723734
shouldShowHorizontalRule={!props.shouldHideThreadDividerLine}
724-
shouldShowAnimatedBackground={transactionThreadReport.currency === props.report.currency}
735+
shouldShowAnimatedBackground={transactionCurrency === props.report.currency}
725736
/>
726737
</ShowContextMenuContext.Provider>
727738
</>
@@ -921,6 +932,9 @@ export default compose(
921932
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID || 0}`,
922933
canEvict: false,
923934
},
935+
transactions: {
936+
key: ONYXKEYS.COLLECTION.TRANSACTION,
937+
},
924938
}),
925939
)(
926940
memo(ReportActionItem, (prevProps, nextProps) => {
@@ -958,7 +972,8 @@ export default compose(
958972
_.isEqual(prevProps.report.reportFields, nextProps.report.reportFields) &&
959973
_.isEqual(prevProps.policy, nextProps.policy) &&
960974
_.isEqual(prevParentReportAction, nextParentReportAction) &&
961-
_.isEqual(prevProps.reportActions, nextProps.reportActions)
975+
_.isEqual(prevProps.reportActions, nextProps.reportActions) &&
976+
_.isEqual(prevProps.transactions, nextProps.transactions)
962977
);
963978
}),
964979
);

0 commit comments

Comments
 (0)