Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.34k stars 2.77k forks source link

Distance - App crashes after selecting rate that has no Tax rate & Tax reclaimable on #49556

Open IuliiaHerets opened 16 hours ago

IuliiaHerets commented 16 hours ago

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.39-0 Reproducible in staging?: Y Reproducible in production?: Y Email or phone of affected tester (no customers): applausetester+zm22@applause.expensifail.com Issue reported by: Applause Internal Team

Action Performed:

  1. Launch New Expensify app.
  2. Create a new workspace.
  3. Enable Distance rates and Taxes.
  4. Go to Distance rates > Settings > Enable Track tax.
  5. Add a distance rate and leave Tax rate and Tax reclaimable on fields empty.
  6. Submit a distance expense in the workspace chat.
  7. Go to transaction thread.
  8. Click Rate.
  9. Select the other distance rate that does not have Tax rate and Tax reclaimable on.

Expected Result:

App will not crash.

Actual Result:

App crashes after selecting distance rate that has no Tax rate and Tax reclaimable on.

Crash happens when the rate has

Workaround:

Unknown

Platforms:

Screenshots/Videos

2009_1.txt

https://github.com/user-attachments/assets/4a41aae2-5e23-4bc7-bbdf-24b7373298da

View all open jobs on GitHub

melvin-bot[bot] commented 16 hours ago

Triggered auto assignment to @OfstadC (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

IuliiaHerets commented 16 hours ago

We think that this bug might be related to #wave-collect - Release 1

IuliiaHerets commented 16 hours ago

@OfstadC FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

etCoderDysto commented 15 hours ago

Proposal

Please re-state the problem that we are trying to solve in this issue.

Distance - App crashes after selecting rate that has no Tax rate & Tax reclaimable on

What is the root cause of that problem?

We are not adding optional chaining before value below https://github.com/Expensify/App/blob/513e6b3c714adbe24cd8b88c9fc9c20130a6c9d4/src/libs/ReportUtils.ts#L3477

What changes do you think we should make in order to solve the problem?

Add optional chaining before value

originalMessage.taxRate = transactionChanges?.taxCode && policy?.taxRates?.taxes[transactionChanges?.taxCode]?.value;

What alternative solutions did you explore? (Optional)

nkdengineer commented 15 hours ago

Proposal

Please re-state the problem that we are trying to solve in this issue.

App crashes after selecting distance rate that has no Tax rate and Tax reclaimable on.

What is the root cause of that problem?

When track tax is enabled and we select the rate that has no tax rate, taxRateExternalID here is -1

https://github.com/Expensify/App/blob/513e6b3c714adbe24cd8b88c9fc9c20130a6c9d4/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx#L95-L107

Then here we passed it to transactionChanges because updatedTaxCode is not empty https://github.com/Expensify/App/blob/513e6b3c714adbe24cd8b88c9fc9c20130a6c9d4/src/libs/actions/IOU.ts#L3176-L3180

Then the app crashes here because policy?.taxRates?.taxes[transactionChanges?.taxCode] is undefined with transactionChanges?.taxCode as -1 https://github.com/Expensify/App/blob/83835702a43ee9299475e406fa7aa10027e05584/src/libs/ReportUtils.ts#L3475-L3477

What changes do you think we should make in order to solve the problem?

Safely get the value field here

policy?.taxRates?.taxes[transactionChanges?.taxCode]?.value

https://github.com/Expensify/App/blob/83835702a43ee9299475e406fa7aa10027e05584/src/libs/ReportUtils.ts#L3475-L3477 And we can fallback taxRateExternalID as empty string

https://github.com/Expensify/App/blob/513e6b3c714adbe24cd8b88c9fc9c20130a6c9d4/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx#L95-L107

or add a check here to not add taxCode to transactionChanges if it's -1

)updatedTaxCode && updatedTaxCode !== '-1') ? {taxCode: updatedTaxCode} : {}

https://github.com/Expensify/App/blob/513e6b3c714adbe24cd8b88c9fc9c20130a6c9d4/src/libs/actions/IOU.ts#L3176-L3180

What alternative solutions did you explore? (Optional)

NA