Skip to content

Fix distance rate not selected after creating new rate from self DM#84850

Merged
aldo-expensify merged 1 commit intomainfrom
claude-fixDistanceRateSelectionSelfDM
Mar 19, 2026
Merged

Fix distance rate not selected after creating new rate from self DM#84850
aldo-expensify merged 1 commit intomainfrom
claude-fixDistanceRateSelectionSelfDM

Conversation

@MelvinBot
Copy link
Contributor

Explanation of Change

When creating a distance expense from a self DM and submitting it to someone, the user can go through an upgrade flow to create a new custom rate. After saving the new rate and returning to the confirmation page, the newly created rate is not selected — the previous default rate persists instead.

This happens because of a race condition between two useEffect hooks in MoneyRequestConfirmationList.tsx:

  1. A rate validation effect (line 492) fires when the transaction update arrives before the policy update, sees the new rate ID isn't in the (stale) policy, and resets the transaction to the default rate.
  2. An auto-rate-update effect (line 694) normally recovers from this by restoring the user's lastSelectedRate — but it was blocked for the self DM submit flow by an isMovingTransactionFromTrackExpense guard.

The fix removes the isMovingTransactionFromTrackExpense guard from the auto-rate-update effect so that lastSelectedRate can restore the user's chosen rate in the self DM submit flow, matching the existing behavior in the FAB flow.

Fixed Issues

$ #82629
PROPOSAL: #82629 (comment)

Tests

  1. Go to the app and navigate to self DM
  2. Create a distance expense
  3. Click "Submit it to someone"
  4. Enter an email and select the user
  5. On the confirm page, click Rate
  6. Click Upgrade > Got it, thanks
  7. Enter a new rate and click Save
  8. Verify the new rate is selected on the confirm page (not the previous default rate)
  • Verify that no errors appear in the JS console

Offline tests

N/A — This fix only affects rate selection logic during an upgrade flow that requires network connectivity.

QA Steps

  1. Go to staging.new.expensify.com
  2. Navigate to self DM
  3. Create a distance expense
  4. Click "Submit it to someone"
  5. Enter an email and select the user
  6. On the confirm page, click Rate
  7. Click Upgrade > Got it, thanks
  8. Enter a new rate and click Save
  9. Verify the new rate is selected on the confirm page (not the previous default rate)
  10. Also verify creating a distance expense from FAB still works correctly (regression check)
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

Remove isMovingTransactionFromTrackExpense guard from the auto-rate-update
effect so lastSelectedRate can restore the user's chosen rate in the self DM
submit flow, matching the existing behavior in the FAB flow.

Co-authored-by: Joel Davies <jjcoffee@users.noreply.github.com>
@jjcoffee
Copy link
Contributor

@MelvinBot Could you give your reasoning for why you feel it is safe to remove the isMovingTransactionFromTrackExpense guard here? Why was it originally added?

@MelvinBot
Copy link
Contributor Author

Good question. Here's the full context:

Why the guard was originally added

The isMovingTransactionFromTrackExpense guard was added in PR #82148 (by GCyganek, Feb 2026) to fix issue #80661 (incorrect unit/rate display after switching workspaces on a distance expense).

There are two useEffects in this component that both set the distance rate:

  1. Rate-validation effect (~line 492): Only runs when isMovingTransactionFromTrackExpense is true. Its job is to check whether the tracked expense's rate belongs to the target workspace policy — if it does, great; if not, it tries to find a matching rate or shows an invalidRate error.

  2. Auto-rate-update effect (~line 694): Fires when customUnitRateID is a fake/default rate (-1 or FAKE_P2P_ID) and sets it to lastSelectedRate.

The guard was added to effect #2 to prevent it from competing with effect #1 during the move-from-track-expense flow. Without it, both effects would fire: #2 would blindly set lastSelectedRate, while #1 was trying to do its own rate matching/validation logic.

Why it's safe to remove

The guard was too broad. It blocked all lastSelectedRate restoration during the move flow, including the scenario in issue #82629: when a user creates a new custom rate via the upgrade flow in the self DM submit path.

In that scenario:

  1. User creates a new rate → it's stored as lastSelectedRate
  2. A race condition between policy and transaction updates causes the rate-validation effect (Some initial fixes and code style updates #1) to temporarily reset the rate to the default (because it sees the new rate ID isn't in the stale policy data yet)
  3. The auto-rate effect (Fix spaces #2) should then fire (since the rate is now back to a default/fake value) and restore lastSelectedRate — but the guard was preventing this

Removing the guard is safe because effect #2 still has strong preconditions — it only fires when:

  • customUnitRateID is -1 or FAKE_P2P_ID (no valid rate is set)
  • lastSelectedRate exists
  • The selected participant's policy matches

After effect #2 sets lastSelectedRate, effect #1 (the validation effect) still runs on the next render and validates whether that rate belongs to the policy. If it does, it clears the error. If it doesn't, it overrides with a matching rate or shows the invalidRate error. So the validation effect still acts as a safety net — it just no longer has exclusive control over rate selection during the move flow.

In short: the guard prevented a legitimate use case (restoring a user's newly-created rate) without adding safety, because the validation effect at line 492 already validates whatever rate ends up being set.

@jjcoffee
Copy link
Contributor

@MelvinBot That PR didn't introduce it, it just moved existing code around. The source is #74662.

@MelvinBot
Copy link
Contributor Author

Thanks for the correction — you're right, PR #82148 just reorganized the code. The guard was originally introduced in PR #74662 by gijoe0295, fixing issue #73800. Here's the corrected reasoning:

Why the guard was originally added (PR #74662)

The original bug: when a user is newly invited to a workspace, policy.customUnits isn't available yet (not pushed via Pusher on invite). So DistanceRequestUtils.getCustomUnitRateID() falls back to FAKE_P2P_ID. The old auto-rate-update useEffect only checked for customUnitRateID === '-1', so it never corrected FAKE_P2P_ID to a real workspace rate — causing the backend to reject with "The selected rate has been deleted."

PR #74662 fixed this by expanding the condition to also check for FAKE_P2P_ID. But the author also added the isMovingTransactionFromTrackExpense guard to prevent this expanded auto-rate-update from interfering with a separate, dedicated useEffect (lines ~492-528) that handles the "move tracked expense to workspace" flow. That dedicated handler has more nuanced logic: it tries to match the tracked expense's P2P rate to a policy rate, and if no match is found, shows an invalidRate error prompting the user to manually choose. Without the guard, the simpler auto-rate useEffect would blindly overwrite the rate with lastSelectedRate, bypassing that error-checking logic.

From gijoe0295's proposal:

Note the !isMovingTransactionFromTrackExpense because we already have a separate [effect] to run rate settings for that case.

Why it's safe to remove for issue #82629

The guard prevents all lastSelectedRate restoration during the move flow — including the scenario in issue #82629 where the user just created a new custom rate via the upgrade flow. In that case:

  1. User creates a new rate → stored as lastSelectedRate
  2. A race condition resets customUnitRateID back to a default/fake value
  3. The auto-rate useEffect should fire and restore lastSelectedRate, but the guard blocks it

The dedicated handler at lines 492-528 doesn't help here either — it checks if customUnitRateID exists in policyRates, but if the rate was just created and there's stale data, it may not find a match and shows an error instead.

Removing the guard lets the auto-rate useEffect fire during the move flow when the rate is fake/unset. This is safe because:

  • It only fires when customUnitRateID is -1 or FAKE_P2P_ID (no valid rate is set)
  • It sets lastSelectedRate, which is the user's explicit choice
  • The dedicated validation useEffect at lines 492-528 still runs on the next render — if the rate is valid for the policy, it clears the error; if not, it overrides with a matching rate or shows the error

So the validation effect still acts as the safety net. The guard was preventing a legitimate case (restoring a user-created rate) without adding protection that isn't already provided by the validation effect.

@jjcoffee
Copy link
Contributor

@MelvinBot Thanks! Mark this as ready for review, please.

@MelvinBot MelvinBot marked this pull request as ready for review March 12, 2026 14:01
@MelvinBot MelvinBot requested a review from a team as a code owner March 12, 2026 14:01
@melvin-bot melvin-bot bot requested a review from jjcoffee March 12, 2026 14:01
@MelvinBot
Copy link
Contributor Author

Done — PR is now marked as ready for review. 🤖

@melvin-bot
Copy link

melvin-bot bot commented Mar 12, 2026

@jjcoffee Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot requested review from heyjennahay and removed request for a team March 12, 2026 14:01
@jjcoffee
Copy link
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
android-app-2026-03-12_15.06.12.mp4
Android: mWeb Chrome
android-chrome-2026-03-12_15.07.41.mp4
iOS: HybridApp
ios-app-2026-03-12_15.01.03.mp4
iOS: mWeb Safari
ios-safari-2026-03-12_15.03.08.mp4
MacOS: Chrome / Safari
desktop-chrome-2026-03-12_14.57.37.mp4

Copy link
Contributor

@jjcoffee jjcoffee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Tests well.

@melvin-bot
Copy link

melvin-bot bot commented Mar 12, 2026

We did not find an internal engineer to review this PR, trying to assign a random engineer to #82629 as well as to this PR... Please reach out for help on Slack if no one gets assigned!

@melvin-bot melvin-bot bot requested a review from aldo-expensify March 12, 2026 14:18
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f832719df3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 698 to 701
!isPolicyExpenseChat ||
!transactionID ||
!lastSelectedRate ||
isMovingTransactionFromTrackExpense ||
!selectedParticipants.some((participant) => participant.policyID === policy?.id)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep move-flow matched rate from being overwritten

By removing the isMovingTransactionFromTrackExpense guard here, this effect now runs during the move-from-track-expense flow and can overwrite the rate chosen by the earlier move-specific effect (useEffect around line 492) in the same render cycle. In cases where the moved transaction’s matched policy rate differs from lastSelectedRate (e.g., user previously used a different workspace rate), the final customUnitRateID becomes lastSelectedRate, which changes the calculated distance amount and submits the expense with the wrong rate.

Useful? React with 👍 / 👎.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot What do you think about this? Can you provide test steps to verify.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concern is technically valid but narrow in practice. Here's the full breakdown:

The Overwrite Scenario

Both effects run in the same React commit phase (declaration order). On the first render during a move-from-track-expense flow:

  1. Effect 1 (line 492): Sees customUnitRateID = FAKE_P2P_ID, searches policy rates by rate+unit, finds a match (rateID_A), calls setCustomUnitRateID(rateID_A) → writes to Onyx but re-render hasn't happened yet.
  2. Effect 2 (line 694): Still sees customUnitRateID = FAKE_P2P_ID (stale), so its guard passes. Calls setCustomUnitRateID(lastSelectedRate) → overwrites rateID_A with lastSelectedRate.

On the second render, customUnitRateID is lastSelectedRate. Effect 1 re-runs, sees it's a valid policy rate, clears errors. Stable.

When this matters: Only when lastSelectedRate differs from the rate matched by rate+unit — meaning the user previously selected a non-default rate on this policy, AND the tracked expense's P2P rate+unit matches a different policy rate. This requires a policy with multiple mileage rates.

When it doesn't matter (the common case): Most policies have one rate. lastSelectedRate falls back to defaultMileageRate, and the rate-validation effect would match the same rate by rate+unit. Both effects write the same value → no observable difference.

My Assessment

For the specific bug being fixed (issue #82629 — creating a new rate via upgrade flow in self DM), removing the guard is the right fix. The new rate IS lastSelectedRate, and the validation effect can't match it by rate+unit because it was just created.

However, for the general move-from-track-expense case with policies that have multiple rates, the overwrite could silently change the rate. A more targeted fix would be to only skip the guard when coming from the upgrade flow, or to have the auto-rate effect check whether the validation effect already handled it (e.g., via a ref).

Test Steps to Verify

Test 1: Original bug fix (must pass)

  1. Go to Self DM
  2. Create a distance expense
  3. Click "Submit it to someone" → enter email → select user
  4. On confirm page, click Rate → Upgrade → Got it, thanks
  5. Enter a new rate and click Save
  6. Verify: The new rate is selected on the confirm page (not the previous default)

Test 2: Move-from-track with single-rate policy (regression — should still work)

  1. Go to Self DM
  2. Create a distance expense (uses P2P rate)
  3. Click "Submit it to someone" → select a user on a workspace with ONE mileage rate
  4. Verify: The policy's rate is correctly applied on the confirm page
  5. Verify: No invalidRate error appears

Test 3: Move-from-track with multi-rate policy (the edge case to watch)

  1. Set up a workspace with two or more custom mileage rates (e.g., "Standard" at $0.67/mi and "Premium" at $1.00/mi)
  2. Create a distance expense from FAB on that workspace, select the "Premium" rate, and submit it (this stores "Premium" as lastSelectedRate for that policy)
  3. Go to Self DM
  4. Create a new distance expense (it gets the P2P rate, which likely matches "Standard" by rate+unit)
  5. Click "Submit it to someone" → select a user on the same workspace
  6. Check: Which rate is applied on the confirm page?
    • With the guard removed (this PR): lastSelectedRate wins → "Premium" rate is applied
    • With the guard present (old behavior): Rate-validation effect matches by rate+unit → "Standard" rate is applied
  7. Question for product: Which behavior is correct? Should it match by rate+unit (preserving the tracked expense's economics) or use the user's last-selected rate?

Test 3 is the key one to decide whether this approach is acceptable or needs a more targeted condition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot For Test 3 there is a P2P rate (which is not the same as the default rate on any workspace), this rate is maintained on the Submit it to someone page but shows with a Rate not valid for this workspace... error (as it's a P2P rate).

If you instead chose to upgrade when creating the expense on the self-DM, this just creates a new workspace each time from what I can tell, so there wouldn't be any risk of multiple rates there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right on both points, and this effectively resolves my Test 3 concern.

On the P2P rate: I verified in the code that the P2P rate for USD is hardcoded at 72.5 cents/mi (CONST.CURRENCY_TO_DEFAULT_MILEAGE_RATE at src/CONST/index.ts:6974), which doesn't match typical workspace mileage rates. So the validation effect's rate+unit match at line 508 fails, and it falls through to setFormError('iou.error.invalidRate'). The scenario I was concerned about — effect 1 successfully matching a policy rate that effect 2 then overwrites — doesn't actually happen because effect 1 never successfully matches.

On the upgrade flow: Since upgrading from self-DM creates a fresh workspace with a single rate, there's no multi-rate conflict. lastSelectedRate is the only rate on that workspace.

So the guard removal is safe: in the move-from-track-expense case, the validation effect doesn't match any rate (it shows an error), and with the guard removed, the auto-rate effect can set lastSelectedRate which the validation effect then re-checks. In the upgrade flow (the actual bug), lastSelectedRate is the newly created rate and gets correctly restored. Both paths work correctly.

My Test 3 concern was based on an incorrect assumption that the P2P rate would match a workspace rate by rate+unit. Thanks for the correction.

@jjcoffee
Copy link
Contributor

@aldo-expensify All yours, this doesn't seem to be an issue.

@aldo-expensify aldo-expensify merged commit 5ec941f into main Mar 19, 2026
44 checks passed
@aldo-expensify aldo-expensify deleted the claude-fixDistanceRateSelectionSelfDM branch March 19, 2026 17:35
@github-actions
Copy link
Contributor

🚧 @aldo-expensify has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/aldo-expensify in version: 9.3.41-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/cristipaval in version: 9.3.41-4 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants