From 7095276c1fb57670c319cc28fb4f6220617da791 Mon Sep 17 00:00:00 2001 From: Oleg Chendighelean Date: Thu, 13 Jun 2024 22:23:05 +0300 Subject: [PATCH] Update useDataPolling hook to show only one notification --- src/utils/dataPolling/useDataPolling.ts | 37 ++++++++----------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/src/utils/dataPolling/useDataPolling.ts b/src/utils/dataPolling/useDataPolling.ts index fc0e0978e0..32f120cf4d 100644 --- a/src/utils/dataPolling/useDataPolling.ts +++ b/src/utils/dataPolling/useDataPolling.ts @@ -14,31 +14,18 @@ import { assetsActions } from "../redux/slices/assetsSlice"; export const useDataPolling = () => { const dispatch = useAppDispatch(); - const { dataUpdatedAt: isMultisigsUpdatedAt, isFetching: isMultisigsFetching } = - usePollMultisigs(); - const { dataUpdatedAt: isPendingOperationsUpdatedAt, isFetching: isPendingOperationsFetching } = - usePollPendingOperations(); - const { dataUpdatedAt: isTezBalancesUpdatedAt, isFetching: isTezBalancesFetching } = - usePollTezBalances(); - const { dataUpdatedAt: isTokenBalancesUpdatedAt, isFetching: isTokenBalancesFetching } = - usePollTokenBalances(); - - usePollConversionRate(); - usePollBlockLevel(); - usePollBakers(); - - const isFetching = - isMultisigsFetching || - isPendingOperationsFetching || - isTezBalancesFetching || - isTokenBalancesFetching; - - const lastUpdatedAt = Math.max( - isMultisigsUpdatedAt, - isPendingOperationsUpdatedAt, - isTezBalancesUpdatedAt, - isTokenBalancesUpdatedAt - ); + const pollers = [ + usePollMultisigs(), + usePollPendingOperations(), + usePollTezBalances(), + usePollTokenBalances(), + usePollConversionRate(), + usePollBlockLevel(), + usePollBakers(), + ]; + + const isFetching = pollers.some(poller => poller.isFetching); + const lastUpdatedAt = Math.max(...pollers.map(poller => poller.dataUpdatedAt)); useEffect(() => { dispatch(assetsActions.setIsLoading(isFetching));