Skip to content

Commit

Permalink
Fix crash when using invalid currency code
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1206agra committed Nov 25, 2024
1 parent 821bde5 commit a20132e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/libs/CurrencyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ function isValidCurrencyCode(currencyCode: string): boolean {
return !!currency;
}

function sanitizeCurrencyCode(currencyCode: string): string {
return isValidCurrencyCode(currencyCode) ? currencyCode : CONST.CURRENCY.USD;
}

export {
getCurrencyDecimals,
getCurrencyUnit,
Expand All @@ -211,4 +215,5 @@ export {
convertToDisplayStringWithoutCurrency,
isValidCurrencyCode,
convertToShortDisplayString,
sanitizeCurrencyCode,
};
3 changes: 2 additions & 1 deletion src/pages/workspace/perDiem/ImportedPerDiemPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import useLocalize from '@hooks/useLocalize';
import usePolicy from '@hooks/usePolicy';
import {closeImportPage} from '@libs/actions/ImportSpreadsheet';
import * as PerDiem from '@libs/actions/Policy/PerDiem';
import {sanitizeCurrencyCode} from '@libs/CurrencyUtils';
import {findDuplicate, generateColumnNames} from '@libs/importSpreadsheetUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -108,7 +109,7 @@ function ImportedPerDiemPage({route}: ImportedPerDiemPageProps) {
const perDiemAmountColumn = columns.findIndex((column) => column === CONST.CSV_IMPORT_COLUMNS.AMOUNT);
const perDiemDestination = spreadsheet?.data[perDiemDestinationColumn].map((destination) => destination) ?? [];
const perDiemSubRate = spreadsheet?.data[perDiemSubRateColumn].map((subRate) => subRate) ?? [];
const perDiemCurrency = spreadsheet?.data[perDiemCurrencyColumn].map((currency) => currency) ?? [];
const perDiemCurrency = spreadsheet?.data[perDiemCurrencyColumn].map((currency) => sanitizeCurrencyCode(currency)) ?? [];
const perDiemAmount = spreadsheet?.data[perDiemAmountColumn].map((amount) => amount) ?? [];
const perDiemUnits = generatePerDiemUnits(
perDiemDestination?.slice(containsHeader ? 1 : 0),
Expand Down

0 comments on commit a20132e

Please sign in to comment.