Skip to content

Commit

Permalink
fix: convert distance value to meters if necessary
Browse files Browse the repository at this point in the history
Signed-off-by: dominictb <[email protected]>
  • Loading branch information
dominictb committed Jun 17, 2024
1 parent df9689f commit 3d70532
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 @@ -259,10 +259,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 Down Expand Up @@ -305,6 +302,18 @@ function MoneyRequestConfirmationList({
// A flag for showing the billable field
const shouldShowBillable = policy?.disabledFields?.defaultBillable === false;
const isMovingTransactionFromTrackExpense = IOUUtils.isMovingTransactionFromTrackExpense(action);

const distance = useMemo(() => {
const value = TransactionUtils.getDistance(transaction);
if (isMovingTransactionFromTrackExpense && unit) {
return DistanceRequestUtils.convertToDistanceInMeters(value, unit);
}
return value;
}, [isMovingTransactionFromTrackExpense, unit, transaction]);
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 3d70532

Please sign in to comment.