All files / app/hooks use-global-polling.ts

0% Statements 0/43
0% Branches 0/4
0% Functions 0/6
0% Lines 0/40

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                                                                                                                         
import { useApi } from './use-api';
import { useInterval } from './use-interval';
import { useNavigatorOnline } from './use-navigator-online';
import { DEFAULT_POLLING_INTERVAL } from '@constants/index';
import { getAddressDetails } from '@store/address';
import { selectAddress } from '@store/keys';
import {
  fetchAccountBalanceLocked,
  fetchBlockTimeInfo,
  fetchCoreDetails,
  fetchStackerInfo,
  fetchStackingInfo,
} from '@store/stacking';
import { getAddressTransactions } from '@store/transaction';
import { useCallback, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
 
export function useGlobalAppPolling() {
  const dispatch = useDispatch();
  const address = useSelector(selectAddress);
  const api = useApi();
 
  const initAppWithStxAddressInfo = useCallback(() => {
    Iif (!address) return;
    dispatch(getAddressTransactions(address));
    dispatch(getAddressDetails(address));
    dispatch(fetchAccountBalanceLocked(address));
  }, [address, dispatch]);
 
  const refreshWalletDetailsWithoutLoader = useCallback(() => {
    Iif (!address) return;
    dispatch(getAddressTransactions(address, { displayLoading: false }));
    dispatch(getAddressDetails(address));
    dispatch(fetchAccountBalanceLocked(address));
  }, [address, dispatch]);
 
  useNavigatorOnline({ onReconnect: initAppWithStxAddressInfo });
 
  useInterval(() => refreshWalletDetailsWithoutLoader(), DEFAULT_POLLING_INTERVAL);
 
  useEffect(() => {
    initAppWithStxAddressInfo();
    Iif (address) {
      dispatch(fetchStackingInfo());
      dispatch(fetchCoreDetails());
      dispatch(fetchBlockTimeInfo());
      dispatch(fetchStackerInfo(address));
      dispatch(fetchAccountBalanceLocked(address));
    }
  }, [address, api, initAppWithStxAddressInfo, dispatch]);
 
  useInterval(() => {
    Iif (address) {
      dispatch(fetchStackerInfo(address));
      dispatch(fetchStackingInfo());
      dispatch(fetchAccountBalanceLocked(address));
    }
    dispatch(fetchCoreDetails());
  }, 20_000);
}