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.

improve

Steven Tey2c8b957e26d0
diff --git a/apps/web/lib/analytics/convert-currency.ts b/apps/web/lib/analytics/convert-currency.ts
index 3520e49140..9bdbed596b 100644
--- a/apps/web/lib/analytics/convert-currency.ts
+++ b/apps/web/lib/analytics/convert-currency.ts
@@ -33,12 +33,17 @@ export const convertCurrency = async ({
const fxRates = await redis.hget("fxRates:usd", currency.toUpperCase()); // e.g. for MYR it'll be around 4.4
if (fxRates) {
- // convert amount to USD (in cents) based on the current FX rate and round it to 0 decimal places
- const convertedAmount = Math.round(amount / Number(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;
+ }
+
return {
currency: "usd",
- // if the currency is a zero decimal currency, we need to multiply the amount by 100 to convert it to cents
- amount: isZeroDecimalCurrency ? convertedAmount * 100 : convertedAmount,
+ // round the final converted amount to 0 decimal places (USD in cents)
+ amount: Math.round(convertedAmount),
};
}