Skip to content

Commit

Permalink
fix: refresh currency
Browse files Browse the repository at this point in the history
  • Loading branch information
fricoben committed Sep 2, 2024
1 parent d7004a4 commit 1f15c04
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hooks/checkout/useCurrencyManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const useCurrencyManagement = () => {

// we fetch the quote for the currency selected
useEffect(() => {
let timeoutId: NodeJS.Timeout;

const fetchQuote = async () => {
if (displayedCurrency === CurrencyType.ETH) {
setQuoteData(null);
Expand Down Expand Up @@ -45,11 +47,16 @@ export const useCurrencyManagement = () => {
}

const timeUntilNextCheck = quoteData.max_quote_validity - timeLimit;
setTimeout(scheduleRefetch, Math.max(15000, timeUntilNextCheck * 100));
timeoutId = setTimeout(
scheduleRefetch,
Math.max(15000, timeUntilNextCheck * 100)
);
};

fetchQuote();
scheduleRefetch();

return () => clearTimeout(timeoutId);
}, [displayedCurrency, quoteData]);

return {
Expand Down

0 comments on commit 1f15c04

Please sign in to comment.