Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/libs/CurrencyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

let currencyList: OnyxValues[typeof ONYXKEYS.CURRENCY_LIST] = {};

Onyx.connect({

Check warning on line 11 in src/libs/CurrencyUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 11 in src/libs/CurrencyUtils.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CURRENCY_LIST,
callback: (val) => {
if (!val || Object.keys(val).length === 0) {
Expand Down Expand Up @@ -105,7 +105,7 @@
* @param amountInCents – should be an integer. Anything after a decimal place will be dropped.
* @param currency - IOU currency
*/
function convertToDisplayString(amountInCents = 0, currency: string = CONST.CURRENCY.USD): string {
function convertToDisplayString(amountInCents = 0, currency: string = CONST.CURRENCY.USD, shouldUseLocalCurrencySymbol = false): string {
const convertedAmount = convertToFrontendAmountAsInteger(amountInCents, currency);
/**
* Fallback currency to USD if it empty string or undefined
Expand All @@ -114,6 +114,20 @@
if (!currency) {
currencyWithFallback = CONST.CURRENCY.USD;
}

if (shouldUseLocalCurrencySymbol) {
const currencySymbol = getCurrencySymbol(currencyWithFallback);

if (currencySymbol) {
const formattedNumber = format(IntlStore.getCurrentLocale(), convertedAmount, {
style: 'decimal',
minimumFractionDigits: getCurrencyDecimals(currency),
maximumFractionDigits: 2,
});
return `${currencySymbol}${formattedNumber}`;
}
}

return format(IntlStore.getCurrentLocale(), convertedAmount, {
style: 'currency',
currency: currencyWithFallback,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Violations/ViolationsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ const ViolationsUtils = {
shouldShowCategoryReceiptRequiredViolation || !policy.maxExpenseAmountNoReceipt
? undefined
: {
formattedLimit: CurrencyUtils.convertToDisplayString(policy.maxExpenseAmountNoReceipt, policy.outputCurrency),
formattedLimit: CurrencyUtils.convertToDisplayString(policy.maxExpenseAmountNoReceipt, policy.outputCurrency, true),
},
type: CONST.VIOLATION_TYPES.VIOLATION,
showInReview: true,
Expand Down
Loading