Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display the message for last requests with foreign currency that are created in offline mode #34011

Merged
merged 14 commits into from
Jan 24, 2024
Merged
15 changes: 2 additions & 13 deletions src/components/ReportActionItem/MoneyRequestAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ const propTypes = {
/** The ID of the associated request report */
requestReportID: PropTypes.string.isRequired,

/** Is this IOUACTION the most recent? */
isMostRecentIOUReportAction: PropTypes.bool.isRequired,

/** Popover context menu anchor, used for showing context menu */
contextMenuAnchor: refPropTypes,

Expand Down Expand Up @@ -81,7 +78,6 @@ function MoneyRequestAction({
action,
chatReportID,
requestReportID,
isMostRecentIOUReportAction,
contextMenuAnchor,
checkIfContextMenuActive,
chatReport,
Expand Down Expand Up @@ -119,15 +115,8 @@ function MoneyRequestAction({
let shouldShowPendingConversionMessage = false;
const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(action);
const isReversedTransaction = ReportActionsUtils.isReversedTransaction(action);
if (
!_.isEmpty(iouReport) &&
!_.isEmpty(reportActions) &&
chatReport.iouReportID &&
isMostRecentIOUReportAction &&
action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD &&
network.isOffline
) {
shouldShowPendingConversionMessage = IOUUtils.isIOUReportPendingCurrencyConversion(iouReport);
if (!_.isEmpty(iouReport) && !_.isEmpty(reportActions) && chatReport.iouReportID && action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD && network.isOffline) {
shouldShowPendingConversionMessage = IOUUtils.isTransactionPendingCurrencyConversion(iouReport, (action && action.originalMessage && action.originalMessage.IOUTransactionID) || 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting on || 0...

The relevant function argument is typed: transactionID: string

So I think that either the argument type or the passed value is not correct

}

return isDeletedParentAction || isReversedTransaction ? (
Expand Down
10 changes: 6 additions & 4 deletions src/libs/IOUUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ function updateIOUOwnerAndTotal(iouReport: OnyxEntry<Report>, actorAccountID: nu
}

/**
* Returns whether or not an IOU report contains money requests in a different currency
* Returns whether or not a transaction of IOU report contains money requests in a different currency
* that are either created or cancelled offline, and thus haven't been converted to the report's currency yet
*/
function isIOUReportPendingCurrencyConversion(iouReport: Report): boolean {
function isTransactionPendingCurrencyConversion(iouReport: Report, transactionID: string): boolean {
const reportTransactions: Transaction[] = TransactionUtils.getAllReportTransactions(iouReport.reportID);
const pendingRequestsInDifferentCurrency = reportTransactions.filter((transaction) => transaction.pendingAction && TransactionUtils.getCurrency(transaction) !== iouReport.currency);
const pendingRequestsInDifferentCurrency = reportTransactions.filter(
(transaction) => transaction.pendingAction && transaction.transactionID === transactionID && TransactionUtils.getCurrency(transaction) !== iouReport.currency,
);
return pendingRequestsInDifferentCurrency.length > 0;
}

Expand All @@ -127,4 +129,4 @@ function isValidMoneyRequestType(iouType: string): boolean {
return moneyRequestType.includes(iouType);
}

export {calculateAmount, updateIOUOwnerAndTotal, isIOUReportPendingCurrencyConversion, isValidMoneyRequestType, navigateToStartMoneyRequestStep, navigateToStartStepIfScanFileCannotBeRead};
export {calculateAmount, updateIOUOwnerAndTotal, isTransactionPendingCurrencyConversion, isValidMoneyRequestType, navigateToStartMoneyRequestStep, navigateToStartStepIfScanFileCannotBeRead};
7 changes: 1 addition & 6 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ const propTypes = {
/** Should the comment have the appearance of being grouped with the previous comment? */
displayAsGroup: PropTypes.bool.isRequired,

/** Is this the most recent IOU Action? */
isMostRecentIOUReportAction: PropTypes.bool.isRequired,

/** Should we display the new marker on top of the comment? */
shouldDisplayNewMarker: PropTypes.bool.isRequired,

Expand Down Expand Up @@ -346,10 +343,9 @@ function ReportActionItem(props) {
const iouReportID = originalMessage.IOUReportID ? originalMessage.IOUReportID.toString() : '0';
children = (
<MoneyRequestAction
chatReportID={props.report.reportID}
chatReportID={originalMessage.IOUReportID ? props.report.chatReportID : props.report.reportID}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just add a comment explaining this check so the next person knows why we needed to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ensure that this is in proper English. You can use freely available tools like ChatGPT 3.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try this

If originalMessage.iouReportID is set, this is a 1:1 money request in a DM chat whose reportID is props.report.chatReportID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the comment.

requestReportID={iouReportID}
action={props.action}
isMostRecentIOUReportAction={props.isMostRecentIOUReportAction}
isHovered={hovered}
contextMenuAnchor={popoverAnchorRef}
checkIfContextMenuActive={toggleContextMenuFromActiveReportAction}
Expand Down Expand Up @@ -815,7 +811,6 @@ export default compose(
(prevProps, nextProps) =>
prevProps.displayAsGroup === nextProps.displayAsGroup &&
prevProps.draftMessage === nextProps.draftMessage &&
prevProps.isMostRecentIOUReportAction === nextProps.isMostRecentIOUReportAction &&
prevProps.shouldDisplayNewMarker === nextProps.shouldDisplayNewMarker &&
_.isEqual(prevProps.emojiReactions, nextProps.emojiReactions) &&
_.isEqual(prevProps.action, nextProps.action) &&
Expand Down
1 change: 0 additions & 1 deletion src/pages/home/report/ReportActionItemParentAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ function ReportActionItemParentAction(props) {
report={props.report}
action={parentReportAction}
displayAsGroup={false}
isMostRecentIOUReportAction={false}
shouldDisplayNewMarker={props.shouldDisplayNewMarker}
index={props.index}
/>
Expand Down
8 changes: 1 addition & 7 deletions src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ const propTypes = {
/** Sorted actions prepared for display */
sortedReportActions: PropTypes.arrayOf(PropTypes.shape(reportActionPropTypes)).isRequired,

/** The ID of the most recent IOU report action connected with the shown report */
mostRecentIOUReportActionID: PropTypes.string,

/** The report metadata loading states */
isLoadingInitialReportActions: PropTypes.bool,

Expand Down Expand Up @@ -73,7 +70,6 @@ const propTypes = {

const defaultProps = {
onScroll: () => {},
mostRecentIOUReportActionID: '',
isLoadingInitialReportActions: false,
isLoadingOlderReportActions: false,
isLoadingNewerReportActions: false,
Expand Down Expand Up @@ -128,7 +124,6 @@ function ReportActionsList({
sortedReportActions,
windowHeight,
onScroll,
mostRecentIOUReportActionID,
isSmallScreenWidth,
personalDetailsList,
currentUserPersonalDetails,
Expand Down Expand Up @@ -414,12 +409,11 @@ function ReportActionsList({
report={report}
linkedReportActionID={linkedReportActionID}
displayAsGroup={ReportActionsUtils.isConsecutiveActionMadeByPreviousActor(sortedReportActions, index)}
mostRecentIOUReportActionID={mostRecentIOUReportActionID}
shouldHideThreadDividerLine={shouldHideThreadDividerLine}
shouldDisplayNewMarker={shouldDisplayNewMarker(reportAction, index)}
/>
),
[report, linkedReportActionID, sortedReportActions, mostRecentIOUReportActionID, shouldHideThreadDividerLine, shouldDisplayNewMarker],
[report, linkedReportActionID, sortedReportActions, shouldHideThreadDividerLine, shouldDisplayNewMarker],
);

// Native mobile does not render updates flatlist the changes even though component did update called.
Expand Down
16 changes: 1 addition & 15 deletions src/pages/home/report/ReportActionsListItemRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ const propTypes = {
/** Should the comment have the appearance of being grouped with the previous comment? */
displayAsGroup: PropTypes.bool.isRequired,

/** The ID of the most recent IOU report action connected with the shown report */
mostRecentIOUReportActionID: PropTypes.string,

/** If the thread divider line should be hidden */
shouldHideThreadDividerLine: PropTypes.bool.isRequired,

Expand All @@ -36,20 +33,10 @@ const propTypes = {
};

const defaultProps = {
mostRecentIOUReportActionID: '',
linkedReportActionID: '',
};

function ReportActionsListItemRenderer({
reportAction,
index,
report,
displayAsGroup,
mostRecentIOUReportActionID,
shouldHideThreadDividerLine,
shouldDisplayNewMarker,
linkedReportActionID,
}) {
function ReportActionsListItemRenderer({reportAction, index, report, displayAsGroup, shouldHideThreadDividerLine, shouldDisplayNewMarker, linkedReportActionID}) {
const shouldDisplayParentAction =
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED &&
ReportUtils.isChatThread(report) &&
Expand Down Expand Up @@ -78,7 +65,6 @@ function ReportActionsListItemRenderer({
reportAction.actionName,
)
}
isMostRecentIOUReportAction={reportAction.reportActionID === mostRecentIOUReportActionID}
index={index}
/>
);
Expand Down
4 changes: 0 additions & 4 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import usePrevious from '@hooks/usePrevious';
import compose from '@libs/compose';
import getIsReportFullyVisible from '@libs/getIsReportFullyVisible';
import Performance from '@libs/Performance';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import {isUserCreatedPolicyRoom} from '@libs/ReportUtils';
import {didUserLogInDuringSession} from '@libs/SessionUtils';
import {ReactionListContext} from '@pages/home/ReportScreenContext';
Expand Down Expand Up @@ -87,8 +86,6 @@ function ReportActionsView(props) {
const didSubscribeToReportTypingEvents = useRef(false);
const isFirstRender = useRef(true);
const hasCachedActions = useInitialValue(() => _.size(props.reportActions) > 0);
const mostRecentIOUReportActionID = useInitialValue(() => ReportActionsUtils.getMostRecentIOURequestActionID(props.reportActions));

const prevNetworkRef = useRef(props.network);
const prevAuthTokenType = usePrevious(props.session.authTokenType);

Expand Down Expand Up @@ -257,7 +254,6 @@ function ReportActionsView(props) {
report={props.report}
onLayout={recordTimeToMeasureItemLayout}
sortedReportActions={props.reportActions}
mostRecentIOUReportActionID={mostRecentIOUReportActionID}
loadOlderChats={loadOlderChats}
loadNewerChats={loadNewerChats}
isLoadingInitialReportActions={props.isLoadingInitialReportActions}
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/IOUUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function initCurrencyList() {
}

describe('IOUUtils', () => {
describe('isIOUReportPendingCurrencyConversion', () => {
describe('isTransactionPendingCurrencyConversion', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
Expand All @@ -34,7 +34,7 @@ describe('IOUUtils', () => {
[`${ONYXKEYS.COLLECTION.TRANSACTION}${aedPendingTransaction.transactionID}`]: aedPendingTransaction,
}).then(() => {
// We requested money offline in a different currency, we don't know the total of the iouReport until we're back online
expect(IOUUtils.isIOUReportPendingCurrencyConversion(iouReport)).toBe(true);
expect(IOUUtils.isTransactionPendingCurrencyConversion(iouReport, aedPendingTransaction.transactionID)).toBe(true);
});
});

Expand All @@ -54,7 +54,7 @@ describe('IOUUtils', () => {
},
}).then(() => {
// We requested money online in a different currency, we know the iouReport total and there's no need to show the pending conversion message
expect(IOUUtils.isIOUReportPendingCurrencyConversion(iouReport)).toBe(false);
expect(IOUUtils.isTransactionPendingCurrencyConversion(iouReport, aedPendingTransaction.transactionID)).toBe(false);
});
});
});
Expand Down
Loading