Skip to content

Display rate name instead of rate value on distance expenses#83393

Merged
mollfpr merged 20 commits intomainfrom
neil-marcellini-displayRateNameForDistance
Mar 3, 2026
Merged

Display rate name instead of rate value on distance expenses#83393
mollfpr merged 20 commits intomainfrom
neil-marcellini-displayRateNameForDistance

Conversation

@neil-marcellini
Copy link
Contributor

@neil-marcellini neil-marcellini commented Feb 25, 2026

Explanation of Change

This PR fixes how the rate field and merchant string are displayed on distance expenses so that workspace rate changes no longer retroactively alter historical expenses.

Workspace distance expenses now show the rate name (e.g., "Default Rate") in the rate field instead of the formatted rate value (e.g., "$0.67 / mile"). The rate name is stable — if a workspace admin updates the rate value, existing expenses keep showing the same rate name they were created with. This brings New Expensify in line with the OldDot UX.

P2P distance expenses (not tied to a workspace) have no named rate, so they continue showing the formatted rate value (e.g., "$0.67 / mile") directly.

Merchant string (getMerchant): Previously, getMerchant() recalculated the merchant string (e.g., "10 mi @ $0.67 / mi") from the live workspace rate on every call for distance expenses. This was added in PR #59063 to $ #58612 but caused workspace rate changes to retroactively alter the merchant on all historical expenses. Since the merchant is already correctly set at creation time (via getDistanceMerchant in updateWaypoints and getUpdatedTransaction), the recalculation was unnecessary. getMerchant is now a simple one-liner that returns the stored modifiedMerchant or merchant field, same as for all other expense types.

Changes:

  • DistanceRequestUtils.ts: Added getRateForExpenseDisplay() — for P2P expenses (no rate name) it calls getRateForDisplay internally and returns the formatted rate value; for workspace expenses it returns the rate name; for out-of-policy workspace rates it returns "Rate out of policy"
  • MoneyRequestView.tsx: Uses getRateForExpenseDisplay instead of getRateForDisplay
  • SplitExpenseEditPage.tsx: Same change as MoneyRequestView
  • MoneyRequestConfirmationListFooter.tsx: Uses getRateForExpenseDisplay with isCustomUnitOutOfPolicy=false since a rate violation is not applicable during expense creation/edit confirmation
  • MoneyRequestConfirmationList.tsx: Passes the new distanceRateName prop to the footer
  • TransactionUtils.ts (getMerchant): Simplified to always return the stored merchant from the transaction
  • Added unit tests for getRateForExpenseDisplay and getMerchant

Fixed Issues

$ #82123

Tests

Workspace rate change

  1. Create a workspace if needed
  2. Enable distance rates in more features
  3. Add an additional rate, making note of the name and value you set
  4. Create a distance expense on the workspace
  5. Verify the first listed rate is selected and displays its name on the expense page
  6. Select the rate
  7. Verify both rate options are listed with the name and value
  8. Select the rate you added
  9. Verify the amount updates and a system message describes the change
  10. Go to workspace settings and change the rate value (e.g., to $1.00/mi)
  11. Navigate back to the previously created distance expense
  12. Verify a violation displays on the amount field
  13. Verify the rate field still shows the same rate name ("New Rate")
  14. Verify the merchant in the chat preview still shows the original rate value (e.g., "10 mi @ $0.70 / mi"), not the updated one
  15. Switch to the other rate and back to the one you updated
  16. Verify the violation clears, and the amount and merchant update
  17. Create a new distance expense and verify the rate selector shows the updated rate name + value

P2P

  1. Track distance
  2. Send the expense to an individual
  3. Verify the rate value is displayed directly (e.g., "$0.67 / mile"), not a rate name
  4. Select the rate menu item
  5. Verify the upgrade page displays
  6. Create the expense
  7. Verify the rate value displays in the merchant
  • Verify that no errors appear in the JS console

Test workspace rate change

2026-02-25_13-25-42.mp4

P2P

2026-02-25_13-21-47.mp4

Workspace single expense report view

2026-02-25_13-22-46.mp4

Offline tests

  1. Run the same tests above but go offline before all actions, and back online after all actions.
  2. Verify the UI shows pending updates (grayed out) while offline, and then saves properly after going online

QA Steps

Same as tests

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

The changes should be platform independent. Please see the test videos on Mac Chrome above.

@neil-marcellini neil-marcellini force-pushed the neil-marcellini-displayRateNameForDistance branch from 981f29d to 99ee2f8 Compare February 25, 2026 00:08
@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/components/MoneyRequestConfirmationList.tsx 62.60% <ø> (+0.64%) ⬆️
.../components/MoneyRequestConfirmationListFooter.tsx 83.53% <100.00%> (ø)
src/libs/DistanceRequestUtils.ts 85.16% <100.00%> (+1.26%) ⬆️
src/libs/ReportUtils.ts 75.55% <ø> (-0.03%) ⬇️
src/libs/SearchUIUtils.ts 68.98% <100.00%> (ø)
src/libs/TransactionUtils/index.ts 82.84% <100.00%> (-0.19%) ⬇️
...c/components/ReportActionItem/MoneyRequestView.tsx 0.43% <0.00%> (+<0.01%) ⬆️
...es/iou/request/step/IOURequestStepDistanceRate.tsx 0.00% <0.00%> (ø)
src/pages/iou/SplitExpenseEditPage.tsx 0.00% <0.00%> (ø)
... and 11 files with indirect coverage changes

@neil-marcellini neil-marcellini force-pushed the neil-marcellini-displayRateNameForDistance branch 2 times, most recently from 6f6a2ed to b1f97ef Compare February 25, 2026 17:26
@neil-marcellini neil-marcellini marked this pull request as ready for review February 25, 2026 17:26
@neil-marcellini neil-marcellini requested review from a team as code owners February 25, 2026 17:26
@melvin-bot melvin-bot bot requested a review from situchan February 25, 2026 17:26
@melvin-bot
Copy link

melvin-bot bot commented Feb 25, 2026

@situchan 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 joekaufmanexpensify and removed request for a team February 25, 2026 17:26
@neil-marcellini neil-marcellini marked this pull request as draft February 25, 2026 17:29
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: b1f97ef0f4

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@neil-marcellini neil-marcellini force-pushed the neil-marcellini-displayRateNameForDistance branch 4 times, most recently from b1f97ef to e17adae Compare February 25, 2026 18:12
neil-marcellini and others added 2 commits February 25, 2026 10:28
Show the rate name (e.g., "Default Rate") on all expense display sites
instead of the formatted rate value (e.g., "$0.67 / mile"). This prevents
rate value changes on the workspace from retroactively altering the
displayed rate on historical expenses.

Consolidate rate display logic into a single getRateForExpenseDisplay()
util that handles rate name display, out-of-policy state, and P2P
fallback to "Default rate". Updated all call sites:
- MoneyRequestView (expense detail page)
- MoneyRequestConfirmationListFooter (expense confirmation page)
- SplitExpenseEditPage (split expense editing)

Co-authored-by: Neil Marcellini <neil-marcellini@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@neil-marcellini neil-marcellini force-pushed the neil-marcellini-displayRateNameForDistance branch from 72f557c to a019b86 Compare February 25, 2026 18:29
Co-authored-by: Cursor <cursoragent@cursor.com>
@neil-marcellini
Copy link
Contributor Author

@codex pls review again

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: 32fdcb9d43

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

neil-marcellini and others added 5 commits February 25, 2026 11:31
Previously, getMerchant() recalculated the merchant string from the
current workspace rate for every distance expense, causing rate changes
to retroactively alter the merchant displayed on historical expenses.

Now it returns the stored modifiedMerchant when available, only falling
back to recalculation when no merchant has been saved yet (e.g., during
expense creation before the merchant is first set).

Added a unit test that verifies the stored merchant is preserved even
when the policy rate has changed.

Co-authored-by: Cursor <cursoragent@cursor.com>
The distance-specific branch was recalculating the merchant from the
live workspace rate on every call. This is unnecessary since the
merchant is already set on the transaction when the expense is created.
Just return modifiedMerchant or merchant like we do for all other
expense types.

Co-authored-by: Cursor <cursoragent@cursor.com>
For expenses not tied to a workspace (P2P), there's no rate name to
display. Instead of showing the generic "Default rate" string, fall
back to the formatted rate value (e.g., "$0.67 / mi") which is more
informative.

Changed getRateForExpenseDisplay to accept a formattedRateFallback
string instead of a translate function, used when there's no rate name
or when the rate is out of policy.

Made-with: Cursor
getRateForExpenseDisplay now handles calling getRateForDisplay internally
for P2P expenses instead of requiring callers to pre-compute the
formatted rate. The logic is now:
- P2P (no rate name): show the formatted rate value (e.g., "$0.67 / mi")
- Workspace out-of-policy: show "Rate out of policy"
- Workspace normal: show the rate name

Made-with: Cursor
@melvin-bot melvin-bot bot requested a review from mollfpr February 27, 2026 08:15
@melvin-bot
Copy link

melvin-bot bot commented Feb 27, 2026

@mollfpr 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]

@situchan
Copy link
Contributor

situchan commented Feb 27, 2026

Can you pls run through the related tests and lmk if they are failing, as well as what the expected and actual behavior is?

Please fix conflict

Resolve Mobile-Expensify submodule conflict by using main's pointer.

Made-with: Cursor
Only show "Rate out of policy" for workspace expenses (those with a
rate name). P2P expenses don't have named rates, so the out-of-policy
concept doesn't apply — they always show the formatted rate value.

Made-with: Cursor
This reverts commit 6a8e3be.
The getMerchant simplification removed the only usage of getPolicy,
leaving an unused import that fails the ESLint CI check.

Made-with: Cursor
The test asserted that P2P expenses with isCustomUnitOutOfPolicy=true
should show the formatted rate, but the function intentionally checks
out-of-policy first regardless of expense type.

Made-with: Cursor
@mollfpr
Copy link
Contributor

mollfpr commented Mar 2, 2026

@neil-marcellini Could you resolve the conflict? Thanks!

neil-marcellini and others added 3 commits March 2, 2026 13:41
Combine main's isTrackExpense rate calculation logic with the
getRateForExpenseDisplay function from this branch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The getMerchant simplification removed the only call site for this
function, leaving it unused and causing an ESLint error.

Made-with: Cursor
mollfpr
mollfpr previously approved these changes Mar 3, 2026
Resolve DistanceRequestUtils.ts export conflict by keeping
getRateForExpenseDisplay from this branch alongside
isDistanceAmountWithinLimit and normalizeOdometerText from main.

Resolve IOURequestStepDistanceRate.tsx conflict by keeping main's
pendingRateID/effectiveRateID logic with the branch's renamed
getFormattedRateValue function.

Made-with: Cursor
@mollfpr mollfpr merged commit c9cc9b0 into main Mar 3, 2026
34 checks passed
@mollfpr mollfpr deleted the neil-marcellini-displayRateNameForDistance branch March 3, 2026 14:59
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

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

@OSBotify
Copy link
Contributor

OSBotify commented Mar 3, 2026

✋ 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

OSBotify commented Mar 4, 2026

🚀 Deployed to staging by https://github.com/mollfpr in version: 9.3.31-0 🚀

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

@jponikarchuk
Copy link

jponikarchuk commented Mar 5, 2026

This PR failing because of the issue #84252 in Offline tests
This issue is reproducible in: Web, iOS

1.mp4

@OSBotify
Copy link
Contributor

OSBotify commented Mar 6, 2026

🚀 Deployed to production by https://github.com/blimpich in version: 9.3.31-12 🚀

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.

6 participants