From 1463f97f1442a4abfb3b0fa5fe069f999e576f35 Mon Sep 17 00:00:00 2001 From: Pritam <113875582+Pritam-sd-dev@users.noreply.github.com> Date: Wed, 28 Feb 2024 17:14:26 +0530 Subject: [PATCH] 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> --- .../app-store/stripepayment/lib/currencyConversions.ts | 4 ++-- packages/lib/price.ts | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/app-store/stripepayment/lib/currencyConversions.ts b/packages/app-store/stripepayment/lib/currencyConversions.ts index 75c528c75f..72fe54ff86 100644 --- a/packages/app-store/stripepayment/lib/currencyConversions.ts +++ b/packages/app-store/stripepayment/lib/currencyConversions.ts @@ -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; diff --git a/packages/lib/price.ts b/packages/lib/price.ts index 54a3f8423e..3fcc184924 100644 --- a/packages/lib/price.ts +++ b/packages/lib/price.ts @@ -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))}`; } };