fix: Currency Not Reflecting Correctly #13845 (#13847)

* fix currency problem

* fix type errors

---------

Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
This commit is contained in:
PritamandUdit Takkar authored and GitHub committed 2024-02-28 17:14:26 +05:30
1 parent 34fea35e83
commit 1463f97f14
2 files changed
+7 -4

No files matched your search

@@ -22,7 +22,7 @@ const zeroDecimalCurrencies = [
export const convertToSmallestCurrencyUnit = (amount: number, currency: string) => {
// Special cases
if (zeroDecimalCurrencies.includes(currency)) {
if (zeroDecimalCurrencies.includes(currency.toUpperCase())) {
return amount;
}
return Math.round(amount * 100);
@@ -30,7 +30,7 @@ export const convertToSmallestCurrencyUnit = (amount: number, currency: string)
export const convertFromSmallestToPresentableCurrencyUnit = (amount: number, currency: string) => {
// Special cases
if (zeroDecimalCurrencies.includes(currency)) {
if (zeroDecimalCurrencies.includes(currency.toUpperCase())) {
return amount;
}
return amount / 100;
+5 -2
View File
@@ -1,11 +1,14 @@
import { convertFromSmallestToPresentableCurrencyUnit } from "@calcom/app-store/stripepayment/lib/currencyConversions";
export const formatPrice = (price: number, currency: string | undefined, locale = "en") => {
switch (currency) {
case "BTC":
return `${price} sats`;
default:
currency = currency?.toUpperCase() || "USD";
return `${Intl.NumberFormat(locale, {
style: "currency",
currency: currency?.toUpperCase() || "USD",
}).format(price / 100.0)}`;
currency: currency,
}).format(convertFromSmallestToPresentableCurrencyUnit(price, currency))}`;
}
};