Skip to content

[Due for payment 2026-02-17] [$250] Expense-Distance is shown in miles on the confirm details page and in Km on the distance edit page #79868

Closed

Description

@mitarachim

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: V9.3.4-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/folder/18717689/test-cases/49855697
Email or phone of affected tester (no customers): dreamnitethedragon+yydyd373@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Redminote 10S Android 13
App Component: Money Requests

Action Performed:

Pre-condition:
Have workspace with USD currency as default
Have a self DM

  1. Launch app
  2. Tap fab - track distance - manual
  3. Note when workspace is selected, distance is shown in miles
  4. Now change To field as self DM
  5. Note Distance is shown in miles
  6. Tap distance
  7. Note edit distance page is shown in KM

Expected Result:

Distance must be shown in Km in confirm details & distance edit page on selecting self dm while creating track distance.

Actual Result:

Distance is shown in miles in confirm details page & in Km in distance edit page on selecting self dm while creating track distance.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

Bug7051945_1768663980286.Screenrecorder-2026-01-17-20-54-04-226.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022013558515922077933
  • Upwork Job ID: 2013558515922077933
  • Last Price Increase: 2026-01-20
  • Automatic offers:
    • daledah | Contributor | 110214155
Issue OwnerCurrent Issue Owner: @thesahindia / bfitzexpensify

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jan 19, 2026
  2. melvin-bot commented on Jan 19, 2026

    @melvin-bot

    Triggered auto assignment to @bfitzexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. daledah commented on Jan 19, 2026

    @daledah
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When creating a track distance expense from a workspace with USD currency (which uses miles), and then changing the "To" field to self DM, the distance unit is inconsistent:

    • Confirmation page shows distance in miles
    • Edit distance page shows distance in km

    Expected: Both pages should show distance in km when tracking to self DM (P2P rate).

    What is the root cause of that problem?

    In MoneyRequestConfirmationList.tsx, for track expenses, the policy is always set to policyForMovingExpenses regardless of whether the destination is a policy expense chat or a P2P chat (self DM):

    const isTrackExpense = iouType === CONST.IOU.TYPE.TRACK;
    const policy = isTrackExpense ? policyForMovingExpenses : (policyReal ?? policyDraft);

    This causes the unit to come from the workspace policy (miles for USD) even when tracking to self DM.

    However, in IOURequestStepDistanceManual.tsx, the policy is correctly set to undefined for self DM (via usePolicy(report?.policyID)), which triggers P2P rates (km).

    const unit = DistanceRequestUtils.getRate({transaction, policy: shouldUseDefaultExpensePolicy ? defaultExpensePolicy : policy}).unit;

    What changes do you think we should make in order to solve the problem?

    We should modify the policy selection in MoneyRequestConfirmationList.tsx to not use policyForMovingExpenses when tracking to a P2P destination (self DM). Use isPolicyExpenseChat to determine the destination type:

    const isTrackExpense = iouType === CONST.IOU.TYPE.TRACK;
    // For track expenses to P2P (non-policy) chats, don't use a policy so P2P rates are used
    const policy = isTrackExpense ? (isPolicyExpenseChat ? policyForMovingExpenses : undefined) : (policyReal ?? policyDraft);

    What alternative solutions did you explore? (Optional)

    N/A

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  4. annaweber830 commented on Jan 19, 2026

    @annaweber830
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When creating a manual distance expense, the confirm details step can show the distance in miles, but tapping into the distance edit screen shows the same distance in kilometers after changing the “To” field to a self DM. The unit is inconsistent across screens within the same flow.

    What is the root cause of that problem?

    The distance unit is being derived from two different sources:

    • The confirmation step prefers the unit stored on the transaction draft (comment.customUnit.distanceUnit).
    • The distance edit screen derives the unit from the effective rate (P2P rate vs workspace rate).

    When the user switches the destination from a workspace to a self DM, the flow switches to a P2P distance rate, but the transaction draft’s stored distanceUnit is not updated accordingly. This leaves the confirmation step “stuck” on the old unit while the edit screen reflects the new effective unit.

    What changes do you think we should make in order to solve the problem?

    • When the flow switches to the P2P distance rate (e.g. selecting a self DM), synchronize the transaction draft’s stored comment.customUnit.distanceUnit to match the effective P2P unit used by the edit screen.
    • For manual distance requests (where the quantity is stored in the selected unit), convert the stored comment.customUnit.quantity when the unit changes so the numeric value remains consistent.

    This ensures both the confirm details step and the edit distance step display the same unit and value for the same draft transaction.

    function setCustomUnitRateID(transactionID: string, customUnitRateID: string | undefined) {
    const isFakeP2PRate = customUnitRateID === CONST.CUSTOM_UNITS.FAKE_P2P_ID;
    Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {
    comment: {
    customUnit: {
    customUnitRateID,
    ...(!isFakeP2PRate && {defaultP2PRate: null}),
    },
    },
    });
    }

    function setCustomUnitRateID(transactionID: string, customUnitRateID: string | undefined) {
        const isFakeP2PRate = customUnitRateID === CONST.CUSTOM_UNITS.FAKE_P2P_ID;
        const transaction = allTransactionDrafts[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`];
    
        let nextDistanceUnit: Unit | undefined;
        let nextQuantity: number | undefined;
    
        // When switching to the fake P2P rate (e.g. moving from a workspace chat to a self-DM),
        // ensure the transaction's distance unit matches the effective P2P unit so confirmation and edit screens stay consistent.
        if (isFakeP2PRate && transaction) {
            const currency = transaction.currency ?? CONST.CURRENCY.USD;
            const p2pMileageRate = DistanceRequestUtils.getRateForP2P(currency, transaction);
            nextDistanceUnit = p2pMileageRate.unit;
    
            const existingDistanceUnit = transaction?.comment?.customUnit?.distanceUnit;
            const existingQuantity = transaction?.comment?.customUnit?.quantity;
    
            // For manual distance requests (no route distance stored in meters), the quantity is stored in the selected unit.
            // Convert it when the effective unit changes to avoid showing miles on confirm and km on edit (or vice versa).
            if (typeof existingQuantity === 'number' && existingDistanceUnit && nextDistanceUnit && existingDistanceUnit !== nextDistanceUnit && !transaction?.routes?.route0?.distance) {
                const distanceInMeters = getDistanceInMeters(transaction, existingDistanceUnit);
                const convertedQuantity = DistanceRequestUtils.convertDistanceUnit(distanceInMeters, nextDistanceUnit);
                if (Number.isFinite(convertedQuantity)) {
                    nextQuantity = convertedQuantity;
                }
            }
        }
    
        Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {
            comment: {
                customUnit: {
                    customUnitRateID,
                    ...(!isFakeP2PRate && {defaultP2PRate: null}),
                    ...(nextDistanceUnit && {distanceUnit: nextDistanceUnit}),
                    ...(typeof nextQuantity === 'number' && {quantity: nextQuantity}),
                },
            },
        });
    }
    

    What alternative solutions did you explore? (Optional)

  5. yatin-italy commented on Jan 19, 2026

    @yatin-italy

    Proposal

    Restate the problem this issue is trying to solve.

    • When switching to self DM, the edit screen shows kilometers but the confirm screen shows miles.
    • The number shown does not match the real distance.
    • The amount and unit become inconsistent.

    What is the root cause of that problem?

    • The draft keeps the old workspace unit and quantity.
    • The rate switches to a P2P rate that uses kilometers.
    • The confirm screen reads the new rate unit, but the stored data is still miles.

    What changes do you think we should make in order to solve the problem?

    • Normalize the distance unit and quantity when the rate or participant changes.
    • Convert the stored quantity if the unit changes and there is no route distance.
    • On the confirm screen, only use the stored unit if it matches the effective rate unit.
    // src/libs/actions/IOU/index.ts — normalize unit and quantity at the action layer
    function setCustomUnitRateID(transactionID: string, customUnitRateID: string | undefined) {
        const isFakeP2PRate = customUnitRateID === CONST.CUSTOM_UNITS.FAKE_P2P_ID;
        const transaction = allTransactionDrafts[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`];
    
        let nextDistanceUnit: Unit | undefined;
        let nextQuantity: number | undefined;
    
        if (transaction) {
            const currency = transaction.currency ?? CONST.CURRENCY.USD;
            const effectiveRate = isFakeP2PRate
                ? DistanceRequestUtils.getRateForP2P(currency, transaction)
                : DistanceRequestUtils.getRate({transaction, policy: getPolicy(transaction?.policyID), useTransactionDistanceUnit: false});
    
            nextDistanceUnit = effectiveRate.unit;
    
            const existingDistanceUnit = transaction?.comment?.customUnit?.distanceUnit;
            const existingQuantity = transaction?.comment?.customUnit?.quantity;
            const hasRouteDistance = !!transaction?.routes?.route0?.distance;
    
            if (
                typeof existingQuantity === 'number' &&
                existingDistanceUnit &&
                nextDistanceUnit &&
                existingDistanceUnit !== nextDistanceUnit &&
                !hasRouteDistance
            ) {
                const distanceInMeters = getDistanceInMeters(transaction, existingDistanceUnit);
                const convertedQuantity = DistanceRequestUtils.convertDistanceUnit(distanceInMeters, nextDistanceUnit);
    
                if (Number.isFinite(convertedQuantity)) {
                    nextQuantity = convertedQuantity;
                }
            }
        }
    
        Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {
            comment: {
                customUnit: {
                    customUnitRateID,
                    ...(!isFakeP2PRate && {defaultP2PRate: null}),
                    ...(nextDistanceUnit && {distanceUnit: nextDistanceUnit}),
                    ...(typeof nextQuantity === 'number' && {quantity: nextQuantity}),
                },
            },
        });
    }
    // src/components/MoneyRequestConfirmationList.tsx — use effective unit unless stored matches
    -    const mileageRate = DistanceRequestUtils.getRate({transaction, policy, policyDraft});
    +    const storedDistanceUnit = transaction?.comment?.customUnit?.distanceUnit;
    +    const mileageRate = DistanceRequestUtils.getRate({
    +        transaction,
    +        policy,
    +        policyDraft,
    +        useTransactionDistanceUnit: false,
    +    });
         const rate = mileageRate.rate;
         const prevRate = usePrevious(rate);
         const unit = mileageRate.unit;
         const prevUnit = usePrevious(unit);
    @@
    -    const distance = getDistanceInMeters(transaction, unit);
    +    const conversionUnit = storedDistanceUnit && storedDistanceUnit === unit ? storedDistanceUnit : unit;
    +    const distance = getDistanceInMeters(transaction, conversionUnit);

    What alternative solutions did you explore? (Optional)
    none

  6. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jan 20, 2026
  7. melvin-bot commented on Jan 20, 2026

    @melvin-bot
  8. changed the title [-]Expense-Distance is shown in miles on the confirm details page and in Km on the distance edit page[/-] [+][$250] Expense-Distance is shown in miles on the confirm details page and in Km on the distance edit page[/+] on Jan 20, 2026
  9. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jan 20, 2026
  10. moved this to Bugs and Follow Up Issues in #expensify-bugson Jan 20, 2026
  11. melvin-bot commented on Jan 20, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @thesahindia (External)

  12. 50 remaining items

  13. mallenexpensify commented on Apr 13, 2026

    @mallenexpensify
    Contributor

    Requested retest and took Reviewing off. Let's see where that gets us....

  14. m-natarajan commented on Apr 14, 2026

    @m-natarajan

    Not repro, Windows 11 Chrome and Iphone 12 Pro Max / IOS 26.3.1, v9.3.59-3

    ScreenRecording_04-14-2026.10-53-42_1.MP4
    14.04.2026_10.50.28_REC.mp4
  15. mallenexpensify commented on Apr 14, 2026

    @mallenexpensify
    Contributor

    @thesahindia since the bug isn't reproducible, can we close? If you feel payment is due, provide detailed reasoning. Thx

  16. removed their assignment
    on Apr 24, 2026
  17. thesahindia commented on Apr 25, 2026

    @thesahindia
    Member

    @mallenexpensify, I think it's eligible for 50% compensation to contributor and C+. #80466 was raised by @daledah to fix the issue but there was a regression so it was reverted, then #82692 was raised to fix the issue again but we put it on hold because major changes were being made under the same flow in #84136. Now the issue is fixedl

  18. mallenexpensify commented on Apr 27, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor: @daledah due $125 via NewDot
    Contributor+: @thesahindia due $125 via NewDot

    Wow... this is confusing. I think 50% is fair because of the regression. Otherwise it likely would have been 100%.

    Does this PR needed to be close?

  19. quinthar commented on Apr 28, 2026

    @quinthar
    Contributor

    Approved $125 for @daledah

  20. garrettmknight commented on Aug 7, 2026

    @garrettmknight
    Contributor

    $125 approved for @thesahindia

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions