Inline tax amount does not update correctly - #92910
Conversation
|
@thelullabyy pls review |
|
@bernhardoj 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] |
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.
|
| const focusTimeoutRef = useRef<NodeJS.Timeout | null>(null); | ||
|
|
||
| const transactionSlice = useTransactionSelector(transactionID, amountSliceSelector); | ||
| const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`); |
There was a problem hiding this comment.
❌ PERF-11 (docs)
This component already uses useTransactionSelector with amountSliceSelector to subscribe to a narrow slice of the transaction, avoiding re-renders from unrelated transaction field changes. The new useOnyx call subscribes to the entire transaction object without a selector, which re-renders the component whenever any transaction field changes. The full transaction is only used inside handleAmountChange to call getTaxValue(policy, transaction, taxCode), which internally only needs the transaction to determine the default tax code.
Use a selector to extract only the fields that getTaxValue/transformedTaxRates actually reads from the transaction (e.g., the currency or policy-related fields), or compute the needed tax value from data already available:
const [transactionForTax] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
selector: (txn) => ({
currency: txn?.currency,
// include only fields that getTaxValue actually needs
}),
});Reviewed at: 30b60f1 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 30b60f16db
ℹ️ 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".
| const taxCode = effectiveCurrency !== policy?.outputCurrency ? policy?.taxRates?.foreignTaxDefault : policy?.taxRates?.defaultExternalID; | ||
| if (taxCode) { | ||
| setMoneyRequestTaxRate(transactionID, taxCode); | ||
| const taxPercentage = getTaxValue(policy, transaction, taxCode) ?? ''; |
There was a problem hiding this comment.
Preserve the selected tax rate when amount changes
When moving a track expense and the user has already selected a non-default tax rate, editing the inline amount now always recomputes taxCode from the policy currency defaults and writes it back with setMoneyRequestTaxRate. That resets the user's selected tax rate and calculates tax from the default instead of the current transaction.taxCode, so the tax amount can change to the wrong rate just by editing the amount. This should only choose the default when the currency changed or no tax code is selected; otherwise preserve the current tax code and recalculate from it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
We're discussing...
|
I think the expectation of this issue #92823 isn't correct.
Based on the old flow, the tax rate is updated to the default one whenever we change the amount, so the tax amount is always 0 Screen.Recording.2026-06-08.at.17.25.33.mov |
|
@trjExpensify @lakchote can you please confirm ^? Should we keep the tax rate when we change the amount? |
|
Ordinarily the So it kinda' depends on the setup, expense currency, and what not. That's unclear from your video to offer an opinion on why the taxRate is being updated. That said, also looking at the Applause video in the OP of the issue you referenced. Isn't it simply because they hadn't blurred the amount field yet to confirm the edit? 🤔 |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / SafariScreen.Recording.2026-06-08.at.11.57.59.mov |
| numberFormRef.current?.updateNumber(taxAmountInput); | ||
| }, [isNewManualExpenseFlowEnabled, taxAmountInput]); | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
Same here, why cant this be a part of the onChange handler? Why an effect? This will cause cascading re-renders
There was a problem hiding this comment.
Please follow up on this, I need to merge as is to resolve blocker.
@JS00001 no, not safely. Both effects respond to state changes that don't originate from this field's input so handleTaxAmountChange (which only fires when the user types in the tax amount box) wouldn't cover them. Effect 1: syncing the form display. taxAmountInput is derived from the transaction's stored tax amount. It changes from external sources Effect 2: clearing the error. maxTaxAmount comes from getCalculatedTaxAmount which depends on the expense amount. So this clears the error when the tax becomes valid because the max changed, not because they edited the tax, that path doesn't go through handleTaxAmountChange. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8673ae8c4
ℹ️ 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".
| const taxCode = getTaxCode(transactionForHandlers); | ||
| if (taxCode) { | ||
| const taxPercentage = getTaxValue(policy, transactionForHandlers, taxCode) ?? ''; | ||
| const taxAmount = convertToBackendAmount(calculateTaxAmount(taxPercentage, updatedAmount, getCurrencyDecimals(value))); | ||
| setMoneyRequestTaxAmount(transactionID, taxAmount); |
There was a problem hiding this comment.
Switch tax defaults when currency changes
When moving a tracked expense and changing the inline amount currency, this block recalculates the tax with whatever taxCode was already on the draft. If the user switches between the workspace output currency and a foreign currency, the draft keeps the old default tax rate instead of selecting foreignTaxDefault/defaultExternalID like the amount step and non-moving TaxController path do, so the displayed tax amount and validation limit are computed from the wrong rate until the user manually reselects tax.
Useful? React with 👍 / 👎.
|
I faced this weird behavior on this version. It broke the whole flow. @dukenv0307 Could you please check Same steps here Screen.Recording.2026-06-08.at.11.36.00.mov |
|
I can't reproduce Screen.Recording.2026-06-08.at.23.53.53.mov |
|
Please ignore ^ bug. I couldn't reproduce this err anymore after reseting cache (it seems because of broken onyx data on my end) Screen.Recording.2026-06-08.at.11.57.59.mov |
|
@dukenv0307 checks are failing |
|
Merging as it's one of a few remaining blockers. @dukenv0307 there's a comment from @JS00001 here to resolve as a follow up |
|
🚧 @Julesssss has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
Inline tax amount does not update correctly (cherry picked from commit e1efa26) (cherry-picked to staging by Julesssss)
|
🚀 Cherry-picked to staging by https://github.com/Julesssss in version: 9.4.0-5 🚀
Bundle Size Analysis (Sentry): |
|
🤖 I reviewed the changes in this PR against the help site files under No help site changes are required. Why:
Because no documentation update is needed, I did not open a draft help site PR. @dukenv0307, please confirm you agree no help site changes are needed here. If you believe an article should be updated, let me know which behavior to document and I'll create the draft PR. |
|
🚀 Deployed to production by https://github.com/Julesssss in version: 9.4.0-7 🚀
|
|
🚀 Cherry-picked to staging by https://github.com/Julesssss in version: 9.4.1-0 🚀
Bundle Size Analysis (Sentry): |
|
🚀 Deployed to production by https://github.com/Julesssss in version: 9.4.1-6 🚀
|
Explanation of Change
Fixed Issues
$ #92820
#92818
#92823
PROPOSAL:
Tests
Precondition:
Run Onyx.merge('betas', ['newManualExpenseFlow']); in console.
Enable Taxes in workspace settings.
Test 1:
Test 2:
Offline tests
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-06-08.at.17.15.10.mov