Skip to content

Commit

Permalink
fix: [NOJIRA] increase REFRESH_BALANCE_INTERVAL_MS (#1430)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrearampin authored Jan 31, 2024
1 parent ad7267e commit 6585779
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions packages/checkout/widgets-lib/src/lib/hooks/useBalance.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useCallback, useEffect, useState } from 'react';
import { useCallback, useState } from 'react';
import { Checkout, GetBalanceResult } from '@imtbl/checkout-sdk';
import { Web3Provider } from '@ethersproject/providers';
import { getTokenBalances } from '../../widgets/wallet/functions/tokenBalances';
import { DEFAULT_BALANCE_RETRY_POLICY } from '../constants';
import { useInterval } from './useInterval';

const REFRESH_BALANCE_INTERVAL_MS = 10000;
const REFRESH_BALANCE_INTERVAL_MS = 30000; // 30 seconds -- keep app less chatty

export interface UseBalanceParams {
checkout: Checkout | undefined;
Expand Down Expand Up @@ -58,18 +58,8 @@ export const useBalance = ({
}
}
}, [checkout, provider]);
useInterval(() => refreshBalances(true), REFRESH_BALANCE_INTERVAL_MS);

// Listen for window focus event to refresh after a potential interaction with a wallet
useEffect(() => {
const handleFocus = () => {
refreshBalances(true);
};
window.addEventListener('focus', handleFocus);
return () => {
window.removeEventListener('focus', handleFocus);
};
}, [refreshBalances]);
useInterval(() => refreshBalances(true), REFRESH_BALANCE_INTERVAL_MS);

return {
balancesLoading,
Expand Down

0 comments on commit 6585779

Please sign in to comment.