Skip to content

fix: preserve lightning bolt icon after government rate currency change - #100607

Merged
neil-marcellini merged 4 commits into
Expensify:mainfrom
nabi-ebrahimi:fix/preserve-government-rate-icon-currency-change
Sep 10, 2026
Merged

fix: preserve lightning bolt icon after government rate currency change#100607
neil-marcellini merged 4 commits into
Expensify:mainfrom
nabi-ebrahimi:fix/preserve-government-rate-icon-currency-change

Conversation

@nabi-ebrahimi

@nabi-ebrahimi nabi-ebrahimi commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

When a workspace changes its default currency, existing auto-generated government rates may be displayed using a different distance unit from the one in the original government rate snapshot.

Previously, the app compared the displayed converted rate directly against the original government snapshot. Because the values could differ after the system converted the rate to the workspace's current distance unit, the rate could incorrectly appear to have been manually edited and lose its auto-generated lightning bolt icon.

This change converts the government reference rate to the workspace's current distance unit before performing the comparison. This ensures that rates changed only by the system continue to be recognized as auto-generated, while rates manually edited by an admin still lose the lightning bolt icon as expected.

Fixed Issues

$ #98962
PROPOSAL: #98962 (comment)

Tests

  1. Create a Control workspace and set its default currency to CAD.

  2. Enable Distance rates and turn on Auto-update government rates.

  3. Verify that the Canadian government rate is automatically created with the lightning bolt icon.

  4. Change the workspace default currency from CAD to USD.

  5. Return to Distance rates.

  6. Verify that:

    • A new United States government rate is created with the lightning bolt icon.
    • The existing Canadian government rate retains its lightning bolt icon.
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • 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 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 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)
  • 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)
  • 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.
  • 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
Screen.Recording.2026-09-08.at.9.50.00.PM.mp4
Android: mWeb Chrome
Screen.Recording.2026-09-08.at.9.57.06.PM.mp4
iOS: Native
Screen.Recording.2026-09-08.at.10.20.51.PM.mp4
iOS: mWeb Safari
Screen.Recording.2026-09-08.at.10.09.36.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2026-09-08.at.9.34.59.PM.mov

@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/libs/PolicyDistanceRatesUtils.ts 48.07% <100.00%> (+7.41%) ⬆️
...nents/Tables/WorkspaceDistanceRatesTable/index.tsx 0.00% <0.00%> (ø)
...orkspace/distanceRates/PolicyDistanceRatesPage.tsx 0.00% <0.00%> (ø)
...tanceRatesTable/WorkspaceDistanceRatesTableRow.tsx 0.00% <0.00%> (ø)
... and 9 files with indirect coverage changes

@nabi-ebrahimi
nabi-ebrahimi marked this pull request as ready for review September 8, 2026 17:56
@nabi-ebrahimi
nabi-ebrahimi requested review from a team as code owners September 8, 2026 17:56
@melvin-bot
melvin-bot Bot requested review from flaviadefaria and suneox and removed request for a team September 8, 2026 17:56
@melvin-bot

melvin-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

@suneox 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 removed the request for review from a team September 8, 2026 17:56
@suneox

suneox commented Sep 9, 2026

Copy link
Copy Markdown
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 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 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)
  • 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)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • 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
    • 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 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.
  • 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 CleanShot 2026-09-10 at 13 41 05@2x
Android: mWeb Chrome Screenshot_1789022564
iOS: HybridApp
CleanShot.2026-09-10.at.13.20.21.1.mp4
iOS: mWeb Safari Simulator Screenshot - iPhone 17 Pro - 2026-09-10 at 13 23 00
MacOS: Chrome / Safari
CleanShot.2026-09-10.at.00.30.59.1.mp4
Automation test 0 1-1-before-set-currency-VND-to-CAD 1 1-1-before-auto-update-off-no-gov-rate 1 1-2-action-CA-gov-rate-created-with-bolt 1 1-3-result-CA-rate-row-bolt-closeup "847" alt="1 2-1-before-currency-CAD-before-change" src="https://github.com/user-attachments/assets/5742e069-2f07-4ee9-8e95-21527abcf12a" /> 1 2-2-action-currency-changed-USD 1 2-3-result-CA-keeps-bolt-US-new-bolt 2 1-1-before-edit-page-rate-1 1748-with-bolt 2 1-2-action-rate-edited-to-1 20-saving 2 1-3-result-edited-rate-lost-bolt 2 2-1-before-rate-1 20-no-bolt 2 2-2-action-rate-reverted-to-1 1748-saving 2 2-3-result-bolt-returns-after-revert

@suneox

suneox commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

@nabi-ebrahimi Please update the QA Steps section

@suneox suneox left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@nabi-ebrahimi

Copy link
Copy Markdown
Contributor Author

@neil-marcellini, please feel free to review the code when you have a chance. I found an edge case that I’ll look into and will keep you updated. Thanks!

@nabi-ebrahimi

Copy link
Copy Markdown
Contributor Author

@suneox I was able to reproduce a rounding edge case on Web:

  • Start with the US government rate at 0.7600/mi with the bolt.
  • Manually edit it to 0.7599/mi — the bolt disappears as expected.
  • Change the workspace default currency from USD to CAD.
  • The rate converts to about 0.4722/km, and the bolt appears again.
  • Start with the US government rate at 0.7600/mi with the bolt.
  • Manually edit it to 0.7599/mi — the bolt disappears as expected.
  • Change the workspace default currency from USD to CAD.
  • The rate converts to about 0.4722/km, and the bolt appears again.

It looks like both the original government rate and the manually edited rate round to the same converted value, so the edited rate is classified as unmodified again.

Could you confirm whether this is expected/acceptable behavior for this PR?

@neil-marcellini neil-marcellini left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One small thing needs to be fixed, the location of the comment.

* A date omitted on both sides counts as a match; a date omitted on only one side does not.
*/
function isGovernmentRateUnmodified(rate: Rate): boolean {
function getGovernmentRateAmountForUnit(governmentRateAmount: number, sourceRateID: string | undefined, currentUnit: Unit | undefined): number {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The comment above this function is supposed to be for isGovernmentRateUnmodified. Please move it.

Comment on lines +207 to +210
const convertedAmount =
snapshotUnit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_KILOMETERS
? governmentRateAmount * CONST.CUSTOM_UNITS.MILES_TO_KILOMETERS
: governmentRateAmount / CONST.CUSTOM_UNITS.MILES_TO_KILOMETERS;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NAB: The conversion looked backwards to me at first because I usually think of converting distances, but since we're converting rates it's correct. It might be helpful to add a comment about this.

// If a rate is expressed in cents / km, to convert to cents / mi we multiply by a conversion factor which cancels out the kilometers: cents / km * km / mi = cents / mi. Do the opposite for a rate in cents / mi.

@neil-marcellini

Copy link
Copy Markdown
Contributor

@suneox I was able to reproduce a rounding edge case on Web:

  • Start with the US government rate at 0.7600/mi with the bolt.
  • Manually edit it to 0.7599/mi — the bolt disappears as expected.
  • Change the workspace default currency from USD to CAD.
  • The rate converts to about 0.4722/km, and the bolt appears again.
  • Start with the US government rate at 0.7600/mi with the bolt.
  • Manually edit it to 0.7599/mi — the bolt disappears as expected.
  • Change the workspace default currency from USD to CAD.
  • The rate converts to about 0.4722/km, and the bolt appears again.

It looks like both the original government rate and the manually edited rate round to the same converted value, so the edited rate is classified as unmodified again.

Could you confirm whether this is expected/acceptable behavior for this PR?

Yes this is expected and acceptable. The only solution is to always store rates in meters and never convert them, but that's a really big change that I don't think is worth doing.

@nabi-ebrahimi

Copy link
Copy Markdown
Contributor Author

@neil-marcellini, I’ve addressed your feedback. Could you please take another look when you have a chance? Thanks!

@neil-marcellini

Copy link
Copy Markdown
Contributor
  • 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.

@suneox I checked this off for you. I don't think it applies here and it was preventing us from merging.

@neil-marcellini
neil-marcellini merged commit 3017c10 into Expensify:main Sep 10, 2026
34 of 36 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 neil-marcellini has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
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
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/neil-marcellini in version: 9.4.76-0 🚀

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

@MelvinBot

MelvinBot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Yes — help site changes were required. Draft PR: #100906

The change itself is a bug fix, so it doesn't add a documented feature. But reviewing it against docs/articles/new-expensify/workspaces/Set-distance-rates.md turned up two factual errors plus a gap covering exactly the behavior this PR restores.

Finding Fix
Article lists NZD as a supported currency in 3 places. It isn't — GOVERNMENT_RATE_CURRENCY_TO_COUNTRY maps only USD, CAD, GBP, AUD Corrected to USD, CAD, GBP, or AUD
Article says Auto-update government rate (singular) in 5 places. Live UI label is Auto-update government rates Corrected everywhere, including the FAQ heading
The lightning bolt icon, its tooltip, and the currency-change behavior were undocumented Added 2 sections + 3 FAQ entries
What the new sections cover

How to tell which distance rates Expensify created automatically — the lightning bolt icon and its tooltip This rate is auto-generated. The icon is removed only when an admin edits the rate amount, Start date, or End date. A unit conversion Expensify performs on its own is not an edit, which is precisely the distinction isGovernmentRateUnmodified now makes.

What happens to distance rates when you change the workspace default currency — a new government rate is added for the new country; the workspace Unit switches to the unit that country publishes in (Miles for the United States and Great Britain, Kilometers for Canada and Australia, per GOVERNMENT_RATE_COUNTRY_TO_UNIT and the unit correction in DistanceRate.ts:757-764); earlier government rates are converted to that unit and keep their lightning bolt icon.

Verification. Every label was checked against the live web UI on a Control workspace, not inferred from code: page heading Distance rates, button Add rate, settings rows Unit, Default category, Auto-update government rates, Require GPS or map entry, Track tax, unit options Kilometers and Miles, and the toggle description "Automatically create new rates when the United States publishes new guidance."

npm run spell-changed passes. The article satisfies the structural rules in docs/HELP_AUTHORING_GUIDELINES.md: one # title plus # FAQ, ## for every section, no ###, every heading task-based.

One thing I couldn't do: assign you to #100906. GitHub rejects the assignment because your permission on Expensify/App is read and only users with write access are assignable. I tagged you in a comment on the PR instead. The HelpDot label is applied and the PR is a draft.

@nabi-ebrahimi, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review


view run · no recording available

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 9.4.76-1 🚀

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

Bundle Size Analysis (Sentry):

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.

5 participants