Skip to content

[$250] Confirm details - Unit doesn't change from Km to Mile when switching workspaces after selecting non-default rate #78212

Closed

Description

@lanitochka17

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.2.85-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: Exploratory around https://test-management.browserstack.com/projects/2219752/test-runs/TR-2467/folder/13176744/41237142/1086558789 and https://test-management.browserstack.com/projects/2219752/test-runs/TR-2467/folder/13176744/41237140/1086558788
Email or phone of affected tester (no customers): kiatest.78+ck12192510@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Windows 11/Chrome, iPhone 16/iOS 18.3.1, Pixel 8a/Android 16
App Component: Money Requests

Action Performed:

Preconditions:
On User A's side

  1. Workspace created with Distance rates enabled
  2. Few additional distance rates added
  3. Changed the unit to kilometer in settings
  4. Invited User B as member to workspace

On User's B side

  1. User B has created his default workspace with distance rates enabled

Steps:

  1. [User B] - Navigate to staging.new.expensify.com
  2. [User B] - Click FAB >> Track Distance >> Map option >> Enter waypoints >> Next
  3. Observe To field has User's B default workspace with default distance rate/mile ($0.7/mile) & take note of distance & amount
  4. Switch to User's A workspace in To field
  5. Observe rate field has default rate with kilometer unit ($0.7/kilometer)
  6. Change rate to non-default one
  7. Switch to User's B default workspace in To field
    8.Observe incorrect unit displayed in Rate field which changes the distance & amount values

Expected Result:

When User B switches from User's A workspace to User's B default workspace, the Rate field unit should change from kilometer to mile & reflect correct distance & amount

Actual Result:

When User B switches from User's A workspace to User's B default workspace , the Rate field unit still display kilometer & does not change to mile unit which is User's B workspace default unit.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022003058270992773869
  • Upwork Job ID: 2003058270992773869
  • Last Price Increase: 2026-01-05
Issue OwnerCurrent Issue Owner: @laurenreidexpensify

Activity

  1. added
    Daily
    Bug
    on Dec 20, 2025
  2. melvin-bot commented on Dec 20, 2025

    @melvin-bot

    Triggered auto assignment to @laurenreidexpensify (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. added
    BZ Test Jan 26
    External
    on Dec 22, 2025
  4. changed the title [-]Confirm details - Unit doesn't change from Km to Mile when switching workspaces after selecting non-default rate[/-] [+][$250] Confirm details - Unit doesn't change from Km to Mile when switching workspaces after selecting non-default rate[/+] on Dec 22, 2025
  5. melvin-bot commented on Dec 22, 2025

    @melvin-bot
  6. added
    Help Wanted
    on Dec 22, 2025
  7. melvin-bot commented on Dec 22, 2025

    @melvin-bot

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

  8. Eskalifer1 commented on Dec 22, 2025

    @Eskalifer1
    Contributor

    Proposal

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

    Confirm details - Unit doesn't change from Km to Mile when switching workspaces after selecting non-default rate

    What is the root cause of that problem?

    This is because when we use a custom rate, we perform this function:

    setMoneyRequestDistanceRate(transactionID, customUnitRateID, policy, shouldUseTransactionDraft(action));

    Which adds distanceUnit:

    App/src/libs/actions/IOU.ts

    Lines 1469 to 1490 in 6072cfb

    function setMoneyRequestDistanceRate(transactionID: string, customUnitRateID: string, policy: OnyxEntry<OnyxTypes.Policy>, isDraft: boolean) {
    if (policy) {
    Onyx.merge(ONYXKEYS.NVP_LAST_SELECTED_DISTANCE_RATES, {[policy.id]: customUnitRateID});
    }
    const distanceRate = DistanceRequestUtils.getRateByCustomUnitRateID({policy, customUnitRateID});
    const transaction = isDraft ? allTransactionDrafts[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`] : allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
    let newDistance;
    if (distanceRate?.unit && distanceRate?.unit !== transaction?.comment?.customUnit?.distanceUnit) {
    newDistance = DistanceRequestUtils.convertDistanceUnit(getDistanceInMeters(transaction, transaction?.comment?.customUnit?.distanceUnit), distanceRate.unit);
    }
    Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
    comment: {
    customUnit: {
    customUnitRateID,
    ...(!!policy && {defaultP2PRate: null}),
    ...(distanceRate && {distanceUnit: distanceRate.unit}),
    ...(newDistance && {quantity: newDistance}),
    },
    },
    });
    }

    ...(distanceRate && {distanceUnit: distanceRate.unit}),

    This means that the transaction now has this value, and when the unit is received here:

    const mileageRate = DistanceRequestUtils.getRate({transaction, policy, policyDraft});
    const rate = mileageRate.rate;
    const prevRate = usePrevious(rate);
    const unit = mileageRate.unit;

    In the getRate function:

    const unit = getDistanceUnit(useTransactionDistanceUnit ? transaction : undefined, mileageRate);

    We always try to get the unit from transaction?.comment?.customUnit?.distanceUnit first, and since we inserted it when selecting a non-default unit, we get it:

    function getDistanceUnit(transaction: OnyxEntry<Transaction>, mileageRate: OnyxEntry<MileageRate>): Unit {
    return transaction?.comment?.customUnit?.distanceUnit ?? mileageRate?.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES;
    }

    And we don't have any logic that would clear this field when the participant changes, we only have the logic for changing the rate:

    if (!isMovingTransactionFromTrackExpense) {
    // If not moving the transaction from track expense, select the default rate automatically.
    // Otherwise, keep the original p2p rate and let the user manually change it to the one they want from the workspace.
    const rateID = DistanceRequestUtils.getCustomUnitRateID({reportID: firstParticipantReportID, isPolicyExpenseChat, policy, lastSelectedDistanceRates});
    if (transactions.length > 0) {
    for (const transaction of transactions) {
    setCustomUnitRateID(transaction.transactionID, rateID);
    }
    } else {
    // Fallback to using initialTransactionID directly
    setCustomUnitRateID(initialTransactionID, rateID);
    }
    }

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

    When changing a participant, we can determine and set the same logic that we use here:

    App/src/libs/actions/IOU.ts

    Lines 1469 to 1490 in 6072cfb

    function setMoneyRequestDistanceRate(transactionID: string, customUnitRateID: string, policy: OnyxEntry<OnyxTypes.Policy>, isDraft: boolean) {
    if (policy) {
    Onyx.merge(ONYXKEYS.NVP_LAST_SELECTED_DISTANCE_RATES, {[policy.id]: customUnitRateID});
    }
    const distanceRate = DistanceRequestUtils.getRateByCustomUnitRateID({policy, customUnitRateID});
    const transaction = isDraft ? allTransactionDrafts[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`] : allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
    let newDistance;
    if (distanceRate?.unit && distanceRate?.unit !== transaction?.comment?.customUnit?.distanceUnit) {
    newDistance = DistanceRequestUtils.convertDistanceUnit(getDistanceInMeters(transaction, transaction?.comment?.customUnit?.distanceUnit), distanceRate.unit);
    }
    Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
    comment: {
    customUnit: {
    customUnitRateID,
    ...(!!policy && {defaultP2PRate: null}),
    ...(distanceRate && {distanceUnit: distanceRate.unit}),
    ...(newDistance && {quantity: newDistance}),
    },
    },
    });
    }

    Or reset this field, which I think is more correct, since it will correspond to the logic we have now (transaction?.comment?.customUnit does not have the distanceUnit field in the normal flow). To do this, we can create a separate function:

    function clearCustomDistanceUnit(transactionID: string) {
        Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {
            comment: {
                customUnit: {
                    distanceUnit: null,
                },
            },
        });
    }

    And use it here:

    setCustomUnitRateID(transaction.transactionID, rateID);

    And we can use it here, if necessary:

    setCustomUnitRateID(initialTransactionID, rateID);

    What alternative solutions did you explore? (Optional)

    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.

  9. marufsharifi commented on Dec 25, 2025

    @marufsharifi
    Contributor

    Proposal

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

    Confirm details - Unit doesn't change from Km to Mile when switching workspaces after selecting non-default rate

    What is the root cause of that problem?

    The issue originates from how the distance unit is persisted and later resolved during the distance request flow:

    1. When a user selects a non-default distance rate in a workspace,

      setMoneyRequestDistanceRate updates the draft transaction by storing: transaction.comment.customUnit.distanceUnit here:

    App/src/libs/actions/IOU.ts

    Lines 1482 to 1491 in c00b37a

    Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
    comment: {
    customUnit: {
    customUnitRateID,
    ...(!!policy && {defaultP2PRate: null}),
    ...(distanceRate && {distanceUnit: distanceRate.unit}),
    ...(newDistance && {quantity: newDistance}),
    },
    },
    });

    This is expected behavior and ensures correct recalculation within the same workspace .

    1. The transaction is still in draft state when the user switches the To workspace. At this point, the draft transaction continues to carry the previously stored distanceUnit.

    2. In the confirmation step, MoneyRequestConfirmationList resolves the mileage rate via getRate, which internally calls getDistanceUnit:

      const unit = getDistanceUnit(useTransactionDistanceUnit ? transaction : undefined, mileageRate);

    3. getDistanceUnit currently prioritizes the transaction’s stored unit:

      function getDistanceUnit(transaction: OnyxEntry<Transaction>, mileageRate: OnyxEntry<MileageRate>): Unit {
      return transaction?.comment?.customUnit?.distanceUnit ?? mileageRate?.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES;
      }

      This means the draft transaction’s unit always overrides the mileage rate’s unit, even when the mileage rate now belongs to a different workspace with a different default unit.

    4. As a result, a kilometer unit from Workspace A incorrectly overrides a mile-based rate from Workspace B.

    In short, the draft transaction’s stored unit leaks across workspace boundaries and incorrectly takes precedence over the newly selected workspace’s mileage rate unit.

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

    The distance unit used for display and calculation should always be consistent with the currently selected mileage rate . While the transaction’s stored distance unit is valid within the same workspace, it should not override the unit of a mileage rate that belongs to a different workspace.

    To achieve this, we should refine the distance unit resolution logic so that:

    • The transaction’s stored distance unit is treated as contextual , not authoritative
    • It is only used when it matches the unit of the active mileage rate
    • When a mismatch occurs (e.g. after switching workspaces), the mileage rate’s unit becomes the source of truth

    This ensures that:

    • Units persist correctly when editing or reselecting rates within the same workspace
    • Units automatically realign when switching to a workspace with a different default unit
    • Draft transactions do not leak unit state across workspace boundaries
    • No draft mutation or reset logic is required

    We update getDistanceUnit to explicitly validate whether the transaction’s stored unit is compatible with the mileage rate’s unit before using it.

    function getDistanceUnit(
        transaction: OnyxEntry<Transaction>,
        mileageRate: OnyxEntry<MileageRate>
    ): Unit {
        const transactionUnit = transaction?.comment?.customUnit?.distanceUnit;
        const rateUnit = mileageRate?.unit;
    
        // Use the transaction unit only when it matches the active mileage rate
        if (transactionUnit && rateUnit && transactionUnit === rateUnit) {
            return transactionUnit;
        }
    
        // Otherwise, fall back to the mileage rate unit
        return rateUnit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES;
    }

    What alternative solutions did you explore? (Optional)

    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.

  10. etCoderDysto commented on Dec 25, 2025

    @etCoderDysto
    Contributor

    Proposal

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

    Confirm details - Unit doesn't change from Km to Mile when switching workspaces after selecting non-default rate

    What is the root cause of that problem?

    When we change distance rate we call setMoneyRequestDistanceRate, and we set the draftTransaction's comment?.customUnit?.distanceUnit to km

    App/src/libs/actions/IOU.ts

    Lines 1471 to 1488 in 54c7eb4

    function setMoneyRequestDistanceRate(transactionID: string, customUnitRateID: string, policy: OnyxEntry<OnyxTypes.Policy>, isDraft: boolean) {
    if (policy) {
    Onyx.merge(ONYXKEYS.NVP_LAST_SELECTED_DISTANCE_RATES, {[policy.id]: customUnitRateID});
    }
    const distanceRate = DistanceRequestUtils.getRateByCustomUnitRateID({policy, customUnitRateID});
    const transaction = isDraft ? allTransactionDrafts[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`] : allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
    let newDistance;
    if (distanceRate?.unit && distanceRate?.unit !== transaction?.comment?.customUnit?.distanceUnit) {
    newDistance = DistanceRequestUtils.convertDistanceUnit(getDistanceInMeters(transaction, transaction?.comment?.customUnit?.distanceUnit), distanceRate.unit);
    }
    Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
    comment: {
    customUnit: {
    customUnitRateID,
    ...(!!policy && {defaultP2PRate: null}),
    ...(distanceRate && {distanceUnit: distanceRate.unit}),
    ...(newDistance && {quantity: newDistance}),

    And when try to get the rate on MoneyRequestConfirmationList, we call getRate, and inside getRate useTransactionDistanceUnit transaction is true by default in getRate function call.

    function getRate({
    transaction,
    policy,
    policyDraft,
    useTransactionDistanceUnit = true,

    And we always calculate unit from transaction (transaction?.comment?.customUnit?.distanceUnit). And we fallback to using mileageRate when transaction?.comment?.customUnit?.distanceUnit is undefined.
    const unit = getDistanceUnit(useTransactionDistanceUnit ? transaction : undefined, mileageRate);

    The logic to get the distance rate unit from transaction was introduced in this PR. The logic was introduced to avoid changing distance rate unit on MoneyRequestView when user changes unit in workspace settings by using the transaction as source of truth rather than using workspace distance rates (policy?.customUnits).

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

    We should pass false to useTransactionDistanceUnit when we call getRate in MoneyRequestConfirmationList.tsx

        const mileageRate = DistanceRequestUtils.getRate({transaction, policy, policyDraft, useTransactionDistanceUnit: false});
    

    const mileageRate = DistanceRequestUtils.getRate({transaction, policy, policyDraft});

    That should work fine since we get distance rate unit from the policy when creating distance request to a policy and from personal policy when we create distance request in DM.

    What alternative solutions did you explore? (Optional)

    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.

  11. 63 remaining items

  12. trjExpensify commented on Mar 16, 2026

    @trjExpensify
    Contributor

    approved $250 for @mananjadhav

  13. marufsharifi commented on Mar 16, 2026

    @marufsharifi
    Contributor

    @laurenreidexpensify, I've accepted the offer. thanks.

  14. marufsharifi commented on Mar 18, 2026

    @marufsharifi
    Contributor

    @laurenreidexpensify, gentle bump. thanks.

  15. inimaga commented on Mar 19, 2026

    @inimaga
    Contributor

    @marufsharifi Lauren is currently OOO and payment is being handled by @trjExpensify. Have you responded to the offer sent in upwork here.

  16. melvin-bot commented on Mar 19, 2026

    @melvin-bot

    @laurenreidexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  17. melvin-bot commented on Mar 19, 2026

    @melvin-bot

    @laurenreidexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  18. trjExpensify commented on Mar 19, 2026

    @trjExpensify
    Contributor

    payment is being handled by @trjExpensify.

    That was a C+ payment approval. I can though...

  19. trjExpensify commented on Mar 19, 2026

    @trjExpensify
    Contributor

    Paid the Upwork contract out @marufsharifi. Closing!

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

Metadata

Metadata

Labels

Awaiting PaymentBZ Test Jan 26BugDailyExternal

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions