[Due for payment 2026-11-13] [$175] Distance - Map shows km instead of miles
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Version Number: v9.5.10-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from TestRail: https://github.com/Expensify/Expensify/issues/616079 Email or phone of affected tester (no customers): N/A Issue reported by: Applause Internal Team
Action Performed:
- Account → Preferences → Payment currency → USD.
- In a 1:1 chat tap + → Track distance → Map, enter a Start and a Stop, and submit the expense.
- Verify the expense shows its distance in mi.
- Account → Preferences → Payment currency → EUR.
- Open the expense → Distance, change the Stop waypoint, and tap Save.
- Wait for the expense to sync, then verify its Distance row shows km.
- Tap Distance again.
- Check the label on the green route line on the map.
Expected Result:
The route label shows km, matching the expense.
Actual Result:
The route label shows mi while the expense shows km.
Workaround:
N/A
Platforms:
- [ ] Android: App
- [ ] Android: mWeb Chrome
- [ ] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [x] Windows: Chrome
- [x] MacOS: Chrome / Safari
Screenshots/Videos
https://github.com/user-attachments/assets/f517c68f-cefd-4777-a1bd-9677a89bd82f
Original report video
https://github.com/user-attachments/assets/39b01d8f-eab0-448f-aff1-80f808801474
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022110814145839046697
- Upwork Job ID: 2110814145839046697
- Last Price Increase: 2026-10-15
Issue Owner
Current Issue Owner: @mallenexpensify
⚠️ Preliminary analysis (low confidence): treat this as a starting point, not a conclusion.
I think the map label is reading the unit from the wrong source. The label's unit is set in DistanceRequestFooter.tsx:69-72. There are two ways it could show km here:
- Workspace fallback. If the draft does not carry the P2P rate ID, line 69 uses
getDefaultMileageRate(policy ?? activePolicy). In a DMpolicyis undefined, so the label takes the active workspace's unit (km). The confirmation page usesgetRate, which has noactivePolicyfallback, so it would show mi. - Backend P2P rate. If the draft does carry
FAKE_P2P_ID, the unit comes from the storedGetDefaultP2PMileageRateresponse (DistanceRequestUtils.ts:302-314). If that response returns km, the confirmation page and the saved expense would show km too. That would be a backend issue.
From the code, a 1:1 DM should take path 2. "Track distance" in a DM starts a SUBMIT request, and getCustomUnitRateID seeds FAKE_P2P_ID. I couldn't confirm which path fires because the web test session failed to load, so I couldn't reproduce the bug.
To confirm: repeat the steps and check the unit on the confirmation page.
- Confirmation shows mi: it's path 1. Fix the footer so it uses
DistanceRequestUtils.getRate({transaction, policy, personalPolicyOutputCurrency: personalPolicy?.outputCurrency}), as the native GPS page does. Then remove theactivePolicylookup. - Confirmation shows km: check the Onyx key
defaultP2PMileageRate. If itsunitiskmfor a USD account, the fix belongs in the backend, and an internal engineer needs to look at it.
Investigation details
- The DM + menu item "Track distance" (
quickAction.recordDistance) callsstartDistanceRequest(CONST.IOU.TYPE.SUBMIT, …)(AttachmentPickerWithMenuItems.tsx:251-262). That clears the draft and fetches the P2P rate (MoneyRequest.ts:567-568). initMoneyRequestsetscustomUnitRateIDfromgetCustomUnitRateIDwhen the flow isn't global create (MoneyRequest.ts:415-428). For a DM that returnsFAKE_P2P_ID.- The footer is the only distance-unit calculation that falls back to
activePolicy. The confirmation page (useDistanceRequestState.ts:81-93) and the amount calculation (useDistanceRequestData.ts:52-58) do not use it. - The footer passes the unit to
MapView, then toDirectionsanduseDistanceUnit(unit), then toDistanceSymbol(Directions.tsx:11). - The
policy ?? activePolicyfallback came from feat: Add distance label on map route in January 2025. Because the fallback is old, a recent regression would more likely come from the P2P rate response or the draft setup.
Next Steps: Reply with @MelvinBot <your feedback> to refine this analysis.
view run · no recording available
Triggered auto assignment to Contributor-plus team member for initial proposal review - @mkhutornyi (External)
Job added to Upwork: https://www.upwork.com/jobs/~022110814145839046697
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user sets the distance rate unit to Kilometers on a workspace, navigates to a 1:1 direct message (DM), and creates a distance request (+ -> Track distance -> Map), the unit displayed on the map route line is shown as kilometers (km) instead of miles (mi).
What is the root cause of that problem?
In src/components/DistanceRequest/DistanceRequestFooter.tsx:69-72:
DistanceRequestFooterfalls back toactivePolicywhenpolicyis undefined:
const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(policy ?? activePolicy);
const policyCurrency = (policy ?? activePolicy ?? personalPolicy)?.outputCurrency ?? CONST.CURRENCY.USD;
const mileageRate = isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(policyCurrency, transaction) : defaultMileageRate;
- In a 1:1 DM chat,
policyisundefined(personal chat, not workspace). - On a newly initialized draft transaction (
startDistanceRequest),isCustomUnitRateIDForP2P(transaction)evaluates tofalsebecausecustomUnitRateIDis not yet set. mileageRatefalls back todefaultMileageRate, which reads the unit fromactivePolicy(active workspace), incorrectly displayingkmon the map route.
What changes do you think we should make in order to solve the problem?
In src/components/DistanceRequest/DistanceRequestFooter.tsx:
- Remove
activePolicyIDandactivePolicy. - Use
DistanceRequestUtils.getRateto resolvemileageRateand unit, matchingIOURequestStepDistanceGPS:
const mileageRate = DistanceRequestUtils.getRate({
transaction,
policy,
personalPolicyOutputCurrency: personalPolicy?.outputCurrency,
});
const {unit} = mileageRate ?? {};
What alternative solutions did you explore? (Optional)
None.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0170d6b02e9440e604
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/janithad
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user has an active workspace with Distance rates unit configured to Kilometers (km), and navigates to a 1:1 personal DM chat and creates a distance request (+ → Track/Record distance → Map), the green route line on the map incorrectly displays kilometers (km) instead of miles (mi). When navigating to the confirmation page, it displays miles (mi), creating an inconsistent state between the map route line and the confirmation/transaction amount.
What is the root cause of that problem?
In src/components/DistanceRequest/DistanceRequestFooter.tsx:
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID);
const activePolicy = usePolicy(activePolicyID);
const personalPolicy = usePolicy(personalPolicyID);
...
const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(policy ?? activePolicy);
const policyCurrency = (policy ?? activePolicy ?? personalPolicy)?.outputCurrency ?? CONST.CURRENCY.USD;
const mileageRate = isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(policyCurrency, transaction) : defaultMileageRate;
const {unit} = mileageRate ?? {};
There are two interrelated flaws causing this:
-
Premature
isCustomUnitRateIDForP2Pcheck on draft transactions:
During the initial map step in a 1:1 chat,startDistanceRequestonly clears the draft transaction and navigates to the map screen. At this point,transaction.comment?.customUnit?.customUnitRateIDhas not yet been set toCONST.CUSTOM_UNITS.FAKE_P2P_ID. Thus,isCustomUnitRateIDForP2P(transaction)returnsfalse. -
Erroneous fallback to
activePolicyfor personal/DM chats:
In a 1:1 personal chat,report.policyIDisundefined. Consequently,usePolicyForTransactionreturnspolicy: undefined(because personal 1:1 chats are not linked to any workspace policy).
BecausepolicyisundefinedandisCustomUnitRateIDForP2P(transaction)isfalse,DistanceRequestFooterfalls back toactivePolicyon line 69:DistanceRequestUtils.getDefaultMileageRate(policy ?? activePolicy)
activePolicyrepresents whichever workspace the user currently has active in their app (which in this reproduction has unit set to Kilometers). As a result, the personal 1:1 chat distance request pulls in the workspace's default rate withunit: 'km'and renderskmon the map route line.On the confirmation screen,
useDistanceRequestStatederives the rate viaDistanceRequestUtils.getRate, which does not have anactivePolicyfallback and correctly defaults to miles (mi).
What changes do you think we should make in order to solve the problem?
In src/components/DistanceRequest/DistanceRequestFooter.tsx:
- Remove the fallback to
activePolicy. Personal / 1:1 chat requests must not inherit unrelated workspace settings. - If
policyis not defined (or empty), or ifisCustomUnitRateIDForP2P(transaction)is true, treat the request as P2P and resolve the rate viaDistanceRequestUtils.getRateForP2P(policyCurrency, transaction). - Derive
unitconsistently viaDistanceRequestUtils.getDistanceUnit(transaction, mileageRate).
diff --git a/src/components/DistanceRequest/DistanceRequestFooter.tsx b/src/components/DistanceRequest/DistanceRequestFooter.tsx
index b70422bcc..9812a34ef 100644
--- a/src/components/DistanceRequest/DistanceRequestFooter.tsx
+++ b/src/components/DistanceRequest/DistanceRequestFooter.tsx
@@ -20,6 +20,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy} from '@src/types/onyx';
import type {WaypointCollection} from '@src/types/onyx/Transaction';
import type Transaction from '@src/types/onyx/Transaction';
+import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type TransactionState from '@src/types/utils/TransactionStateType';
import type {StyleProp, ViewStyle} from 'react-native';
@@ -57,19 +58,18 @@ function DistanceRequestFooter({waypoints, transaction, navigateToWaypointEditPa
const {translate} = useLocalize();
const expensifyIcons = useMemoizedLazyExpensifyIcons(['Plus', 'History']);
const [reusableDistanceRoutes] = useOnyx(ONYXKEYS.REUSABLE_DISTANCE_ROUTES);
- const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID);
- const activePolicy = usePolicy(activePolicyID);
const personalPolicy = usePolicy(personalPolicyID);
const [mapboxAccessToken] = useOnyx(ONYXKEYS.MAPBOX_ACCESS_TOKEN);
const numberOfWaypoints = Object.keys(waypoints ?? {}).length;
const numberOfFilledWaypoints = Object.values(waypoints ?? {}).filter((waypoint) => waypoint?.address).length;
const lastWaypointIndex = numberOfWaypoints - 1;
- const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(policy ?? activePolicy);
- const policyCurrency = (policy ?? activePolicy ?? personalPolicy)?.outputCurrency ?? CONST.CURRENCY.USD;
- const mileageRate = isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(policyCurrency, transaction) : defaultMileageRate;
- const {unit} = mileageRate ?? {};
+ const policyCurrency = policy?.outputCurrency ?? personalPolicy?.outputCurrency ?? CONST.CURRENCY.USD;
+ const isP2P = !policy || isEmptyObject(policy) || isCustomUnitRateIDForP2P(transaction);
+ const mileageRate = isP2P ? DistanceRequestUtils.getRateForP2P(policyCurrency, transaction) : DistanceRequestUtils.getDefaultMileageRate(policy);
+ const unit = DistanceRequestUtils.getDistanceUnit(transaction, mileageRate);
const primaryRoute = transaction?.routes?.[CONST.TRANSACTION.DEFAULT_ROUTE_KEY];
const alternateRoute = transaction?.routes?.[CONST.TRANSACTION.ALTERNATE_ROUTE_KEY];
const isAlternateDirectionSelected = getSelectedRouteKey(transaction) === CONST.TRANSACTION.ALTERNATE_ROUTE_KEY;
What alternative solutions did you explore? (Optional)
We could also pass isFakeP2PRate from IOURequestStepDistanceMap by inspecting whether !isPolicyExpenseChatUtil(report), but handling it directly in DistanceRequestFooter.tsx via !policy || isEmptyObject(policy) || isCustomUnitRateIDForP2P(transaction) is cleaner and encapsulates the rate resolution self-sufficiently without leaking unrelated activePolicy data into non-workspace requests.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
Please re-state the problem that we are trying to solve in this issue.
In a 1:1 DM chat, Track distance on the Map tab shows the route distance in kilometers on the green route line, even though the expected unit for this request is miles. This happens after a USD workspace is created and its Distance rates unit is set to Kilometers, and that workspace is not the workspace for the DM request.
What is the root cause of that problem?
DistanceRequestFooter in src/components/DistanceRequest/DistanceRequestFooter.tsx is the only distance surface that does not use DistanceRequestUtils.getRate. It computes the map unit from DistanceRequestUtils.getDefaultMileageRate(policy ?? activePolicy) and also derives policyCurrency from policy ?? activePolicy ?? personalPolicy. In a 1:1 DM, policy is undefined, so it falls back to activePolicy, which is the unrelated USD workspace the user just set to Kilometers. That gives a km unit, which is passed as unit to DistanceMapView, then to Directions and DistanceSymbol, so the route label shows km. The confirmation page, DynamicIOURequestStepDistance, and the native GPS page all use DistanceRequestUtils.getRate({transaction, policy, personalPolicyOutputCurrency}), which resolves the P2P rate for a non policy chat and returns miles for USD, so the map disagrees with the rest of the flow.
What changes do you think we should make in order to solve the problem?
In DistanceRequestFooter.tsx, replace the getDefaultMileageRate(policy ?? activePolicy) calculation with DistanceRequestUtils.getRate({transaction, policy, personalPolicyOutputCurrency: personalPolicy?.outputCurrency}), the same call used in IOURequestStepDistanceGPS/index.native.tsx and in DynamicIOURequestStepDistance.tsx, and use its unit for DistanceMapView. Remove the now unused activePolicy lookup using NVP_ACTIVE_POLICY_ID and usePolicy(activePolicyID), and keep personalPolicy which the component already loads. This keeps workspace distance requests working, because getRate still resolves the selected or default rate from the real policy when there is one, and it keeps P2P requests working, because getRate already handles the FAKE_P2P_ID case through getRateForP2P.
What alternative solutions did you explore? (Optional)
I considered only skipping the activePolicy fallback when the transaction is a P2P transaction, checked with isCustomUnitRateIDForP2P. That would fix part of this case, but it would leave the footer using a different rate calculation from every other distance surface and could still pick the wrong unit in other no policy cases. Using getRate in the footer is smaller in the long run and matches the existing pattern.
📣 @itappskitkool! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:
- Make sure you've read and understood the contributing guidelines.
- Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
- Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01e51b3f9ff738cf94
Proposal
Please re-state the problem that we are trying to solve in this issue.
When tracking distance in a 1:1 chat after configuring distance rate units to kilometers in an active workspace, the route line on the map displays kilometers instead of miles.
What is the root cause of that problem?
In src/components/DistanceRequest/DistanceRequestFooter.tsx (lines 69-72), defaultMileageRate falls back to activePolicy using DistanceRequestUtils.getDefaultMileageRate(policy ?? activePolicy). In a 1:1 chat, policy is undefined because 1:1 chats do not belong to a policy.
At the same time, the draft transaction in the map step has not set transaction.comment.customUnit.customUnitRateID to CONST.CUSTOM_UNITS.FAKE_P2P_ID yet, so isCustomUnitRateIDForP2P(transaction) returns false. DistanceRequestFooter falls back to defaultMileageRate derived from activePolicy. It leaks the active policy. Because activePolicy was set to kilometers, unit resolves to km instead of the standard P2P default unit (mi).
What changes do you think we should make in order to solve the problem?
- In
src/components/DistanceRequest/DistanceRequestFooter.tsx:
- Remove the Onyx connection to
ONYXKEYS.NVP_ACTIVE_POLICY_IDand removeactivePolicy. - Update
defaultMileageRateto evaluateDistanceRequestUtils.getDefaultMileageRate(policy)directly without falling back toactivePolicy. - Update
policyCurrencyfallback to use(policy ?? personalPolicy)?.outputCurrency ?? CONST.CURRENCY.USD. - Determine whether the request is P2P by checking
!policy || isCustomUnitRateIDForP2P(transaction). When true, selectDistanceRequestUtils.getRateForP2P(policyCurrency, transaction)as themileageRate, resolving the unit to miles.
What alternative solutions did you explore? (Optional)
I considered setting transaction.comment.customUnit.customUnitRateID to CONST.CUSTOM_UNITS.FAKE_P2P_ID upon draft creation in 1:1 chats. However, keeping the fallback to activePolicy in DistanceRequestFooter is conceptually wrong for personal chats and leaves the door open to leaking workspace state.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/nitinl2
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
Please re-state the problem that we are trying to solve in this issue.
In a 1:1 DM, Track distance → Map shows the route in km for a user whose workspace distance unit was set to km, when miles was expected.
What is the root cause of that problem?
The workspace's km setting doesn't reach this label. In a 1:1 DM:
- "Track distance" starts a SUBMIT request. The DM has no real policy (its policyID is
_FAKE_), sopolicyis undefined. - When the Map tab opens,
useResetIOUType→initMoneyRequestcreates the draft withcustomUnitRateID = FAKE_P2P_ID, becausegetCustomUnitRateIDreturns the P2P ID when there's no policy. It setsiouRequestTypein the same write, and a route (and so the green label) is only fetched after that. - So
DistanceRequestFooteralways takes thegetRateForP2Pbranch here, never theactivePolicyfallback. Its unit comes from the storedGetDefaultP2PMileageRateresponse, which Auth picks from the user's personal currency.
So the label shows km because the default P2P rate for this account's personal currency is in km. The confirmation page and the saved expense read the same value, so they will show km too. Replacing the footer's logic with DistanceRequestUtils.getRate(), as suggested above, gives the same result for this flow, because getRate takes the same getRateForP2P branch for a P2P draft.
What changes do you think we should make in order to solve the problem?
- Check the tester account's personal policy
outputCurrencyand the storeddefaultP2PMileageRate. If the currency maps to km, this is expected behaviour (or a product decision about P2P units), not an App bug. If the currency is USD and Auth still returns km, it's a backend bug in the P2P mapping. - Optional hardening, as a separate change: have the map step work out the unit once (with
DistanceRequestUtils.getRate, using the default expense policy for global-create flows, like the GPS page does) and pass it intoDistanceRequestFooter, instead of the footer re-deriving it fromactivePolicy. Also storedistanceUnitwhen an alternate route is selected, soquantitycan't be read in the wrong unit.
What alternative solutions did you explore? (Optional)
Switching the footer to getRate() alone. It has no effect on this DM flow. It also makes "Track distance" from the global FAB show miles on the map and then km on confirmation for users whose default workspace uses km, because those drafts have no rate ID yet and getRate without a policy falls back to miles.
📣 @tnclaudecode! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:
- Make sure you've read and understood the contributing guidelines.
- Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
- Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
@mkhutornyi Eep! 4 days overdue now. Issues have feelings too...
@mkhutornyi 6 days overdue. This is scarier than being forced to listen to Vogon poetry!
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user has a workspace whose distance unit is set to Kilometers (km), and then creates a Distance expense inside a 1:1 DM (with USD currency), the Map preview displays the route distance in km instead of mi, whereas the Confirmation screen displays mi.
What is the root cause of that problem?
There are three interacting inconsistencies in how the Distance Map resolves its policy and mileage rate compared to the rest of the distance flow:
-
DistanceRequestFooterfalls back toactivePolicy(NVP_ACTIVE_POLICY_ID) even in a 1:1 DM (DistanceRequestFooter.tsx:70-82): Insrc/components/DistanceRequest/DistanceRequestFooter.tsx:70-82,DistanceRequestFooteris the only distance component that readsONYXKEYS.NVP_ACTIVE_POLICY_ID(activePolicy) and computes:const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(policy ?? activePolicy); const policyCurrency = (policy ?? activePolicy ?? personalPolicy)?.outputCurrency ?? CONST.CURRENCY.USD; const mileageRate = isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(policyCurrency, transaction) : defaultMileageRate;In a 1:1 DM,
policyisundefined. WheneverisCustomUnitRateIDForP2P(transaction)isfalse(for example, whencustomUnitRateIDis not_FAKE_P2P_ID_),DistanceRequestFooterfalls back toactivePolicy(the user's workspace whose unit iskm). Even whenisCustomUnitRateIDForP2P(transaction)istrue,policyCurrencyfalls back toactivePolicy.outputCurrencybeforepersonalPolicy.outputCurrency! By contrast, every other distance step (DynamicIOURequestStepDistance.tsx:197-203,DynamicIOURequestStepDistanceManual.tsx:172-177,IOURequestStepDistanceOdometer.tsx:195-200, andIOURequestStepDistanceGPS/index.native.tsx:119-124) resolves the rate viaDistanceRequestUtils.getRate({transaction, policy, useTransactionDistanceUnit: false, personalPolicyOutputCurrency: personalPolicy?.outputCurrency}), which never leaksactivePolicyinto a 1:1 DM. -
IOURequestStepDistanceMapdoes not passshouldUseDefaultExpensePolicy ? defaultExpensePolicy : policytoDistanceMapTabContent(IOURequestStepDistanceMap.tsx:381): Insrc/pages/iou/request/step/IOURequestStepDistanceMap.tsx:86-97,IOURequestStepDistanceMapcomputesdefaultExpensePolicyandshouldUseDefaultExpensePolicy(which istruefor Global CreateCREATE/TRACKflows when the user has a paid default workspace, andfalsein a 1:1 DM whereiouType === 'submit'). However, at line 381 it passespolicy={policy}instead ofpolicy={shouldUseDefaultExpensePolicy ? defaultExpensePolicy : policy}toDistanceMapTabContent(and down toDistanceRequestFooter). -
useResetIOUTypechecks!report?.reportIDinstead of!report?.reportID && !reportID(useResetIOUType.ts:108): Insrc/hooks/useResetIOUType.ts:108,resetIOUTypeIfChangedcomputesconst isFromGlobalCreate = !report?.reportID;. When starting a distance expense from a newly opened 1:1 DM wherereportIDis present in the route params but thereportOnyx entry has not finished hydrating yet,isFromGlobalCreateevaluates totrue, causinginitMoneyRequestto skip settingcustomUnitRateID = CONST.CUSTOM_UNITS.FAKE_P2P_IDfor the DM.
What changes do you think we should make in order to solve the problem?
- Use
DistanceRequestUtils.getRateinDistanceRequestFooter.tsx(src/components/DistanceRequest/DistanceRequestFooter.tsx):- Remove the
activePolicyID/activePolicysubscriptions and resolvemileageRateviaDistanceRequestUtils.getRate({transaction, policy, useTransactionDistanceUnit: false, personalPolicyOutputCurrency: personalPolicy?.outputCurrency}), matching all other distance step components.
- Remove the
- Pass
shouldUseDefaultExpensePolicy ? defaultExpensePolicy : policyinIOURequestStepDistanceMap.tsx(src/pages/iou/request/step/IOURequestStepDistanceMap.tsx:381):- Update
<DistanceMapTabContent policy={shouldUseDefaultExpensePolicy ? defaultExpensePolicy : policy} ... />so Global Create flows continue to usedefaultExpensePolicy's unit while 1:1 DM flows (shouldUseDefaultExpensePolicy === false,policy === undefined) resolve to the P2P unit (mifor USD).
- Update
- Check
!report?.reportID && !reportIDinuseResetIOUType.ts(src/hooks/useResetIOUType.ts:108):- Ensure a chat-initiated flow with a route
reportIDis never misclassified asisFromGlobalCreateifreportis still loading.
- Ensure a chat-initiated flow with a route
diff --git a/src/components/DistanceRequest/DistanceRequestFooter.tsx b/src/components/DistanceRequest/DistanceRequestFooter.tsx
index 681ab2a..79bd1a2 100644
--- a/src/components/DistanceRequest/DistanceRequestFooter.tsx
+++ b/src/components/DistanceRequest/DistanceRequestFooter.tsx
@@ -9,14 +9,14 @@ import useLocalize from '@hooks/useLocalize';
import type {MapMarkerType} from '@hooks/useMapMarkers/types';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
-import usePolicy from '@hooks/usePolicy';
+import usePersonalPolicy from '@hooks/usePersonalPolicy';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {setSelectedRoute} from '@libs/actions/Transaction';
import DistanceRequestUtils from '@libs/DistanceRequestUtils';
import {getAvailableReusableDistanceRoutes} from '@libs/ReusableDistanceRoutesUtils';
-import {getSelectedRouteKey, getWaypointIndex, isCustomUnitRateIDForP2P} from '@libs/TransactionUtils';
+import {getSelectedRouteKey, getWaypointIndex} from '@libs/TransactionUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
@@ -67,18 +67,18 @@ function DistanceRequestFooter({waypoints, transaction, navigateToWaypointEditPa
const [hasAvailableReusableRoute = false] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {
selector: hasAvailableReusableRouteSelector,
});
- const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
- const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID);
- const activePolicy = usePolicy(activePolicyID);
- const personalPolicy = usePolicy(personalPolicyID);
+ const personalPolicy = usePersonalPolicy();
const [mapboxAccessToken] = useOnyx(ONYXKEYS.MAPBOX_ACCESS_TOKEN);
const numberOfWaypoints = Object.keys(waypoints ?? {}).length;
const numberOfFilledWaypoints = Object.values(waypoints ?? {}).filter((waypoint) => waypoint?.address).length;
const lastWaypointIndex = numberOfWaypoints - 1;
- const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(policy ?? activePolicy);
- const policyCurrency = (policy ?? activePolicy ?? personalPolicy)?.outputCurrency ?? CONST.CURRENCY.USD;
- const mileageRate = isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(policyCurrency, transaction) : defaultMileageRate;
+ const mileageRate = DistanceRequestUtils.getRate({
+ transaction,
+ policy,
+ useTransactionDistanceUnit: false,
+ personalPolicyOutputCurrency: personalPolicy?.outputCurrency,
+ });
const {unit} = mileageRate ?? {};
const primaryRoute = transaction?.routes?.[CONST.TRANSACTION.DEFAULT_ROUTE_KEY];
const alternateRoute = transaction?.routes?.[CONST.TRANSACTION.ALTERNATE_ROUTE_KEY];
diff --git a/src/pages/iou/request/step/IOURequestStepDistanceMap.tsx b/src/pages/iou/request/step/IOURequestStepDistanceMap.tsx
index 5c34616..3cc9660 100644
--- a/src/pages/iou/request/step/IOURequestStepDistanceMap.tsx
+++ b/src/pages/iou/request/step/IOURequestStepDistanceMap.tsx
@@ -378,7 +378,7 @@ function IOURequestStepDistanceMap({
renderItem={renderItem}
navigateToWaypointEditPage={navigateToWaypointEditPage}
transaction={transaction}
- policy={policy}
+ policy={shouldUseDefaultExpensePolicy ? defaultExpensePolicy : policy}
submitWaypoints={submitWaypoints}
buttonText={buttonText}
errorState={errorState}
diff --git a/src/hooks/useResetIOUType.ts b/src/hooks/useResetIOUType.ts
index 961a50b..32801c4 100644
--- a/src/hooks/useResetIOUType.ts
+++ b/src/hooks/useResetIOUType.ts
@@ -105,7 +105,7 @@ function useResetIOUType({
Keyboard.dismiss();
}
- const isFromGlobalCreate = !report?.reportID;
+ const isFromGlobalCreate = !report?.reportID && !reportID;
// Resolve early so we can decide whether to seed participants below.
const earlyReportID = resolveEarlyReportID(isFromGlobalCreate, defaultParticipants);
What alternative solutions did you explore? (Optional)
- Removing
activePolicyfromDistanceRequestFooter.tsxwithout updatingIOURequestStepDistanceMap.tsx:381: IfactivePolicyis removed fromDistanceRequestFooterwhileIOURequestStepDistanceMapstill passespolicy={policy}(which isundefinedduring Global Create before a workspace report is assigned), then Global Create (FAB -> Create expense -> Distance -> Map) loses itsdefaultExpensePolicyand wrongly displaysmieven when the user's default workspace is configured to usekm. PassingshouldUseDefaultExpensePolicy ? defaultExpensePolicy : policyinIOURequestStepDistanceMap.tsxpreserves Global Create while fixing 1:1 DMs.
⚠️ Invalid email. Please make sure to create an Expensify account with this email first here.
@mkhutornyi this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!