Skip to content

Commit

Permalink
Merge pull request #43819 from dominictb/fix/42959-distance-track
Browse files Browse the repository at this point in the history
fix: convert distance value to meters if necessary
  • Loading branch information
thienlnam authored Jul 11, 2024
2 parents 3fd1644 + ca8d718 commit 9138d8b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,7 @@ function MoneyRequestConfirmationList({

const {unit, rate} = mileageRate ?? {};

const distance = TransactionUtils.getDistance(transaction);
const prevRate = usePrevious(rate);
const prevDistance = usePrevious(distance);
const shouldCalculateDistanceAmount = isDistanceRequest && (iouAmount === 0 || prevRate !== rate || prevDistance !== distance);

const currency = (mileageRate as MileageRate)?.currency ?? policyCurrency;

Expand All @@ -261,6 +258,18 @@ function MoneyRequestConfirmationList({
const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy, isDistanceRequest) && !isTypeInvoice;

const isMovingTransactionFromTrackExpense = IOUUtils.isMovingTransactionFromTrackExpense(action);

const distance = useMemo(() => {
const value = TransactionUtils.getDistance(transaction);
if (canUseP2PDistanceRequests && isMovingTransactionFromTrackExpense && unit && !TransactionUtils.isFetchingWaypointsFromServer(transaction)) {
return DistanceRequestUtils.convertToDistanceInMeters(value, unit);
}
return value;
}, [isMovingTransactionFromTrackExpense, unit, transaction, canUseP2PDistanceRequests]);
const prevDistance = usePrevious(distance);

const shouldCalculateDistanceAmount = isDistanceRequest && (iouAmount === 0 || prevRate !== rate || prevDistance !== distance);

const hasRoute = TransactionUtils.hasRoute(transaction, isDistanceRequest);
const isDistanceRequestWithPendingRoute = isDistanceRequest && (!hasRoute || !rate) && !isMovingTransactionFromTrackExpense;
const formattedAmount = isDistanceRequestWithPendingRoute
Expand Down

0 comments on commit 9138d8b

Please sign in to comment.