1- import type { OnyxCollection , OnyxEntry } from 'react-native-onyx' ;
2- import Onyx from 'react-native-onyx' ;
1+ import type { OnyxEntry } from 'react-native-onyx' ;
32import type { LocaleContextProps } from '@components/LocaleContextProvider' ;
43import CONST from '@src/CONST' ;
5- import ONYXKEYS from '@src/ONYXKEYS' ;
6- import type { LastSelectedDistanceRates , OnyxInputOrEntry , Report , Transaction } from '@src/types/onyx' ;
4+ import type { LastSelectedDistanceRates , OnyxInputOrEntry , Transaction } from '@src/types/onyx' ;
75import type { Unit } from '@src/types/onyx/Policy' ;
86import type Policy from '@src/types/onyx/Policy' ;
97import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
108import { getCurrencySymbol } from './CurrencyUtils' ;
11- import { getDistanceRateCustomUnit , getDistanceRateCustomUnitRate , getPersonalPolicy , getPolicy , getUnitRateValue } from './PolicyUtils' ;
12- import { isPolicyExpenseChat } from './ReportUtils' ;
9+ import { getDistanceRateCustomUnit , getDistanceRateCustomUnitRate , getPersonalPolicy , getUnitRateValue } from './PolicyUtils' ;
1310import { getCurrency , getRateID , isCustomUnitRateIDForP2P } from './TransactionUtils' ;
1411
1512type MileageRate = {
@@ -21,23 +18,6 @@ type MileageRate = {
2118 enabled ?: boolean ;
2219} ;
2320
24- let lastSelectedDistanceRates : OnyxEntry < LastSelectedDistanceRates > = { } ;
25- Onyx . connect ( {
26- key : ONYXKEYS . NVP_LAST_SELECTED_DISTANCE_RATES ,
27- callback : ( value ) => {
28- lastSelectedDistanceRates = value ;
29- } ,
30- } ) ;
31-
32- let allReports : OnyxCollection < Report > ;
33- Onyx . connect ( {
34- key : ONYXKEYS . COLLECTION . REPORT ,
35- waitForCollectionCallback : true ,
36- callback : ( value ) => {
37- allReports = value ;
38- } ,
39- } ) ;
40-
4121const METERS_TO_KM = 0.001 ; // 1 kilometer is 1000 meters
4222const METERS_TO_MILES = 0.000621371 ; // There are approximately 0.000621371 miles in a meter
4323
@@ -298,23 +278,28 @@ function convertToDistanceInMeters(distance: number, unit: Unit): number {
298278/**
299279 * Returns custom unit rate ID for the distance transaction
300280 */
301- function getCustomUnitRateID ( reportID ?: string ) {
281+ function getCustomUnitRateID ( {
282+ reportID,
283+ isPolicyExpenseChat,
284+ policy,
285+ lastSelectedDistanceRates,
286+ } : {
287+ reportID : string | undefined ;
288+ isPolicyExpenseChat : boolean ;
289+ policy : OnyxEntry < Policy > | undefined ;
290+ lastSelectedDistanceRates ?: OnyxEntry < LastSelectedDistanceRates > ;
291+ } ) : string {
302292 let customUnitRateID : string = CONST . CUSTOM_UNITS . FAKE_P2P_ID ;
303293
304294 if ( ! reportID ) {
305295 return customUnitRateID ;
306296 }
307- const report = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ reportID } ` ] ;
308- const parentReport = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ report ?. parentReportID } ` ] ;
309- // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
310- // eslint-disable-next-line deprecation/deprecation
311- const policy = getPolicy ( report ?. policyID ?? parentReport ?. policyID ) ;
312297
313298 if ( isEmptyObject ( policy ) ) {
314299 return customUnitRateID ;
315300 }
316301
317- if ( isPolicyExpenseChat ( report ) || isPolicyExpenseChat ( parentReport ) ) {
302+ if ( isPolicyExpenseChat ) {
318303 const distanceUnit = Object . values ( policy . customUnits ?? { } ) . find ( ( unit ) => unit . name === CONST . CUSTOM_UNITS . NAME_DISTANCE ) ;
319304 const lastSelectedDistanceRateID = lastSelectedDistanceRates ?. [ policy . id ] ;
320305 const lastSelectedDistanceRate = lastSelectedDistanceRateID ? distanceUnit ?. rates [ lastSelectedDistanceRateID ] : undefined ;
0 commit comments