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.12k stars 2.61k forks source link

mWeb-distance rate-Selected Distance rate amount (IQD 0.7) is not shown in rate page #44846

Open lanitochka17 opened 3 days ago

lanitochka17 commented 3 days 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.4 Reproducible in staging?: Y Reproducible in production?: Y If this was caught during regression testing, add the test name, ID and link from TestRail: N/A Issue reported by: Applause - Internal Team

Action Performed:

  1. Go to https://staging.new.expensify.com/home
  2. Tap on profile icon -- workspaces-- workspace
  3. Tap more features -- Enable distance rate
  4. Tap profile and change currency to IQD
  5. Tap back
  6. Tap distance rates -- rate -- rate

Expected Result:

Selected Distance rate amount (IQD 0.7) must be shown in rate page

Actual Result:

Selected Distance rate amount (IQD 0.7) is not shown in rate page. Rate page shows amount as zero

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Add any screenshot/video evidence

https://github.com/Expensify/App/assets/78819774/057ca424-7d51-413e-8c31-d6d46e989e3b

View all open jobs on GitHub

lanitochka17 commented 3 days ago

We think that this bug might be related to #vip-vsp

ShridharGoel commented 2 days ago

Proposal

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

Selected distance amount does not take into account currency decimals.

What is the root cause of that problem?

In the amount form, we don't show the decimals if the currency doesn't support it. This is valid for VND and IQD type of currencies.

https://github.com/Expensify/App/blob/2e80218e1077450e6548fcf1894a12e24cf16267/src/components/AmountForm.tsx#L135

But in the other places, we show the exact decimal amount even though the currency doesn't support it.

This needs to be updated.

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

We can also stop showing the decimals in the main pages:

function convertAmountToDisplayString(amount = 0, currency: string = CONST.CURRENCY.USD): string {
    const convertedAmount = amount / 100.0;
    return MoneyRequestUtils.stripDecimalsFromAmount(NumberFormatUtils.format(BaseLocaleListener.getPreferredLocale(), convertedAmount, {
        style: 'currency',
        currency,
        minimumFractionDigits: getCurrencyDecimals(currency) + 1,
    }));
}

This will fix it wherever convertAmountToDisplayString is used.

What alternative options did you explore?

We can calculate the convertedAmount like this in convertAmountToDisplayString which is used at this place:

const convertedAmount = convertToFrontendAmountAsInteger(amount, currency);

And convertToFrontendAmountAsInteger will use the decimals based on currency (this work is already in progress and will be merged soon).

Then, in the amount form we need to use proper decimal count:

Update this:

const decimals = getCurrencyDecimals(currency);
const currentRateValue = (parseFloat((rate?.rate ?? 0).toString()) / CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET).toFixed(decimals !== 0 ? 3 : 0);