From 3d7053230a5708db0e2052f4cdf9de750827ba78 Mon Sep 17 00:00:00 2001 From: dominictb Date: Mon, 17 Jun 2024 09:19:32 +0700 Subject: [PATCH 1/2] fix: convert distance value to meters if necessary Signed-off-by: dominictb --- src/components/MoneyRequestConfirmationList.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index e08b35dd3866..0d50a0c89d66 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -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; @@ -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 From ca8d71814ac2da88cbf3150a10eecc890bcc6fba Mon Sep 17 00:00:00 2001 From: dominictb Date: Thu, 11 Jul 2024 15:12:42 +0700 Subject: [PATCH 2/2] fix: do not convert distance in case API call is not finished Signed-off-by: dominictb --- src/components/MoneyRequestConfirmationList.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index 2b82042ca3e2..09af8e59621e 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -257,11 +257,11 @@ function MoneyRequestConfirmationList({ const distance = useMemo(() => { const value = TransactionUtils.getDistance(transaction); - if (isMovingTransactionFromTrackExpense && unit) { + if (canUseP2PDistanceRequests && isMovingTransactionFromTrackExpense && unit && !TransactionUtils.isFetchingWaypointsFromServer(transaction)) { return DistanceRequestUtils.convertToDistanceInMeters(value, unit); } return value; - }, [isMovingTransactionFromTrackExpense, unit, transaction]); + }, [isMovingTransactionFromTrackExpense, unit, transaction, canUseP2PDistanceRequests]); const prevDistance = usePrevious(distance); const shouldCalculateDistanceAmount = isDistanceRequest && (iouAmount === 0 || prevRate !== rate || prevDistance !== distance);