App: [HOLD for C+ newdot payment] [$500] Web - App crashes when currency in url is changed to invalid currency code

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


Action Performed:

Action Performed:

  1. Go to any chat
  2. Open request money
  3. Change currency in currency list
  4. Notice there is a currency code in url indicating selected currency
  5. (a). Now change that currency code in url to invalid currency code for example ABCD Another case:
  6. (b). Change currency code in url to not invalid currency code but keep it 3 letters like ABC

Expected Result:

In both cases invalid currency should be ignored and default currency should be selected

Actual Result:

a) App crashes. b) You can request money with invalid currency code

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.62.0 Reproducible in staging?: y Reproducible in production?: y If this was caught during regression testing, add the test name, ID and link from TestRail: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Notes/Photos/Videos: Any additional supporting documentation

Case A

https://github.com/Expensify/App/assets/93399543/22a93902-cd73-4c31-a848-a2bd908999ce

https://github.com/Expensify/App/assets/93399543/cd1b7aa4-f1c1-4988-ac95-307304242511

Case B

https://github.com/Expensify/App/assets/93399543/bbd5f249-63ad-4fe2-830c-4336681c8a82

https://github.com/Expensify/App/assets/93399543/df23d3e7-967e-4f9d-82cf-a2afe0b7a70f

Expensify/Expensify Issue URL: Issue reported by: @alitoshmatov Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1693385994296529

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0140a8a0afc8dbbe3d
  • Upwork Job ID: 1698528155580948480
  • Last Price Increase: 2023-09-04

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 35 (20 by maintainers)

Most upvoted comments

Proposal

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

The app crashes when the currency in the URL is changed to an invalid currency code.

What is the root cause of that problem?

We currently don’t perform a check to verify whether the currency from the route parameters is valid or not. This issue is not limited to the new money request page; it also affects the edit and confirmation money request pages.

Additionally, when the currency code length exceeds 3 characters, the app crashes due to the NumberFormatUtils.formatToParts function used in getLocalizedCurrencySymbol and isCurrencySymbolLTR functions within the CurrencyUtils.js file. The issue arises because we are not handling errors in these functions.

Here are the relevant code sections: https://github.com/Expensify/App/blob/ebcc8d045695871d8189a6335c6cdfeede657deb/src/libs/CurrencyUtils.js#L51-L57 https://github.com/Expensify/App/blob/ebcc8d045695871d8189a6335c6cdfeede657deb/src/libs/CurrencyUtils.js#L75-L83

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

We can find the relevant code here: https://github.com/Expensify/App/blob/4676492705a96d766fd1f0f1d2e2401cfd5bc566/src/pages/iou/steps/MoneyRequestAmountForm.js#L252 https://github.com/Expensify/App/blob/44721d2035642266b43d1bad36b30d7a3c5e239d/src/libs/CurrencyUtils.js#L65-L67 Fortunately, we already have a function for obtaining the currency symbol. If the currency symbol is undefined, it signifies that the currency is invalid. While we could create a custom validation function for currency, I believe it would be more consistent and simpler to add the validation logic for currency to the submit button in the MoneyRequestAmountForm.

isDisabled={!currentAmount.length || parseFloat(currentAmount) < 0.01 || !CurrencyUtils.getCurrencySymbol(currency)}

We can also use a default value when CurrencyUtils.getCurrencySymbol(currency) returns undefined. https://github.com/Expensify/App/blob/ebcc8d045695871d8189a6335c6cdfeede657deb/src/pages/iou/steps/MoneyRequestAmountForm.js#L223

selectedCurrencyCode={CurrencyUtils.getCurrencySymbol(currency) ? 'USD' : currency}

Considering the second issue, we have two options for addressing it within the functions in the CurrencyUtils.js file:

First, we can employ the try/catch syntax. Second, we can utilize a default currency code such as USD.

For example:

currency: !getCurrencySymbol(currencyCode) ? 'USD' : currencyCode,

I would prefer the second option because it’s simpler and more straightforward.

What alternative solutions did you explore? (Optional)

Alternatively, we can include form helper text in our money request form to display the error using the proposed validation logic.

Result:

image image