From 009135176baa533c3872410c8a032bab93d95e03 Mon Sep 17 00:00:00 2001 From: Siddharth Date: Wed, 5 Jun 2024 22:46:34 +0530 Subject: [PATCH] chore(voucher): better accuracy for exchange rate (#4501) rebase --- apps/voucher/hooks/use-currency-exchange-rate.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/voucher/hooks/use-currency-exchange-rate.tsx b/apps/voucher/hooks/use-currency-exchange-rate.tsx index f1376ce4e1..953ece1cb0 100644 --- a/apps/voucher/hooks/use-currency-exchange-rate.tsx +++ b/apps/voucher/hooks/use-currency-exchange-rate.tsx @@ -1,5 +1,4 @@ import { useCurrencyConversionEstimationQuery } from "@/lib/graphql/generated" -import { convertCurrency } from "@/lib/utils" export const useCurrencyExchangeRate = ({ currency, @@ -9,13 +8,14 @@ export const useCurrencyExchangeRate = ({ commissionPercentage: number }) => { const { data: currencyDataForOneUnit } = useCurrencyConversionEstimationQuery({ - variables: { amount: 1, currency }, + variables: { amount: 1000, currency }, context: { endpoint: "GALOY" }, fetchPolicy: "no-cache", }) - const usdToCurrencyRate = convertCurrency.centsToUsd({ - cents: currencyDataForOneUnit?.currencyConversionEstimation.usdCentAmount, - }) + + const usdToCurrencyRate = + currencyDataForOneUnit?.currencyConversionEstimation.usdCentAmount / 1000 / 100.0 + const voucherValueAfterCommission = usdToCurrencyRate * (1 - commissionPercentage / 100) return 1 / voucherValueAfterCommission }