Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix convertCurrencyWithFxRates

Steven Teye9f9ef1f8bb2
diff --git a/apps/web/lib/analytics/convert-currency.ts b/apps/web/lib/analytics/convert-currency.ts
index 248597917a..f6c21aebf8 100644
--- a/apps/web/lib/analytics/convert-currency.ts
+++ b/apps/web/lib/analytics/convert-currency.ts
@@ -56,33 +56,27 @@ export const convertCurrency = async ({
export const convertCurrencyWithFxRates = ({
currency,
amount,
- fxRates,
+ fxRates: fxRatesData,
}: {
currency: string;
amount: number;
- fxRates?: Record<string, string>;
+ fxRates: Record<string, string>;
}) => {
const currencyCode = currency.toUpperCase();
const isZeroDecimalCurrency = ZERO_DECIMAL_CURRENCIES.includes(currencyCode);
+ const fxRates = fxRatesData[currencyCode];
- if (fxRates) {
- // convert amount to USD based on the current FX rate
- let convertedAmount = amount / Number(fxRates);
-
- // if the currency is a zero decimal currency, we need to multiply the converted amount by 100
- if (isZeroDecimalCurrency) {
- convertedAmount = convertedAmount * 100;
- }
+ // convert amount to USD based on the current FX rate
+ let convertedAmount = amount / Number(fxRates);
- return {
- currency: "usd",
- // round the final converted amount to 0 decimal places (USD in cents)
- amount: Math.round(convertedAmount),
- };
+ // if the currency is a zero decimal currency, we need to multiply the converted amount by 100
+ if (isZeroDecimalCurrency) {
+ convertedAmount = convertedAmount * 100;
}
return {
- currency,
- amount,
+ currency: "usd",
+ // round the final converted amount to 0 decimal places (USD in cents)
+ amount: Math.round(convertedAmount),
};
};