-
Notifications
You must be signed in to change notification settings - Fork 4k
fix: preserve lightning bolt icon after government rate currency change #100607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
neil-marcellini
merged 4 commits into
Expensify:main
from
nabi-ebrahimi:fix/preserve-government-rate-icon-currency-change
Sep 10, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7504b32
fix: preserve lightning bolt icon after government rate currency change
nabi-ebrahimi d993be9
Merge branch 'main' into fix/preserve-government-rate-icon-currency-c…
nabi-ebrahimi 27ecb83
docs: move government rate JSDoc to correct function
nabi-ebrahimi 20f1814
docs: clarify government rate unit conversion
nabi-ebrahimi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -185,13 +185,36 @@ function getRateStatus(rate: Rate): string { | |
| return CONST.CUSTOM_UNITS.RATE_STATUS.ACTIVE; | ||
| } | ||
|
|
||
| function getGovernmentRateAmountForUnit(governmentRateAmount: number, sourceRateID: string | undefined, currentUnit: Unit | undefined): number { | ||
| if (!sourceRateID || !currentUnit) { | ||
| return governmentRateAmount; | ||
| } | ||
|
|
||
| const snapshotCountry = sourceRateID.split('_').at(0); | ||
| const countryToUnit: Partial<Record<string, Unit>> = CONST.CUSTOM_UNITS.GOVERNMENT_RATE_COUNTRY_TO_UNIT; | ||
| const snapshotUnit = snapshotCountry ? countryToUnit[snapshotCountry] : undefined; | ||
|
|
||
| if (!snapshotUnit || snapshotUnit === currentUnit) { | ||
| return governmentRateAmount; | ||
| } | ||
|
|
||
| // If a rate is expressed in cents / km, converting to cents / mi means multiplying by a factor that cancels the kilometers: | ||
| // cents / km * km / mi = cents / mi. Do the opposite for a rate expressed in cents / mi. | ||
| const convertedAmount = | ||
| snapshotUnit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_KILOMETERS | ||
| ? governmentRateAmount * CONST.CUSTOM_UNITS.MILES_TO_KILOMETERS | ||
| : governmentRateAmount / CONST.CUSTOM_UNITS.MILES_TO_KILOMETERS; | ||
|
Comment on lines
+203
to
+206
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| return Math.round(convertedAmount * 100) / 100; | ||
| } | ||
|
|
||
| /** | ||
| * Whether a government-managed rate still matches the government-published snapshot it was copied from. | ||
| * Returns true only when the rate amount, start date, and end date each match the snapshot in attributes.governmentRate. | ||
| * The amount is compared within a small tolerance to absorb floating-point noise from the stored cents value. | ||
| * 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 isGovernmentRateUnmodified(rate: Rate, currentUnit?: Unit): boolean { | ||
| const governmentRate = rate.attributes?.governmentRate; | ||
| // A snapshot without a rate amount (e.g. malformed data) can never be matched, otherwise `undefined === undefined` would | ||
| // incorrectly report an unset rate as unmodified. | ||
|
|
@@ -201,7 +224,8 @@ function isGovernmentRateUnmodified(rate: Rate): boolean { | |
|
|
||
| // The submit path stores the amount as `Number(value) * 100`, which can introduce tiny floating-point errors (e.g. restoring | ||
| // 0.29 yields 28.999999999999996), so compare amounts within a tolerance rather than requiring strict equality. | ||
| const isRateAmountMatching = Math.abs(rate.rate - governmentRate.rate) < CONST.CUSTOM_UNITS.GOVERNMENT_RATE_MATCH_TOLERANCE; | ||
| const governmentRateAmount = getGovernmentRateAmountForUnit(governmentRate.rate, governmentRate.sourceRateID, currentUnit); | ||
| const isRateAmountMatching = Math.abs(rate.rate - governmentRateAmount) < CONST.CUSTOM_UNITS.GOVERNMENT_RATE_MATCH_TOLERANCE; | ||
|
|
||
| return isRateAmountMatching && (rate.startDate ?? undefined) === governmentRate.startDate && (rate.endDate ?? undefined) === governmentRate.endDate; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.