diff --git a/packages/wallets/src/AppContent.tsx b/packages/wallets/src/AppContent.tsx index dd067ac31790..7cdbb9c85277 100644 --- a/packages/wallets/src/AppContent.tsx +++ b/packages/wallets/src/AppContent.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useDerivAccountsList } from '@deriv/api-v2'; import { Analytics } from '@deriv-com/analytics'; @@ -12,18 +12,21 @@ const AppContent: React.FC = () => { const [isPanelOpen, setIsPanelOpen] = useState(false); const { i18n } = useTranslation(); const { isSubscribed, subscribeToAllBalance, unsubscribeFromAllBalance } = useAllBalanceSubscription(); - const { data: derivAccountList, isRefetching } = useDerivAccountsList(); + const { data: derivAccountList } = useDerivAccountsList(); + const previousDerivAccountListLenghtRef = useRef(0); useEffect(() => { - if ((derivAccountList?.length ?? 0) > 0 && !isRefetching && !isSubscribed) { + if (!derivAccountList?.length) return; + if (previousDerivAccountListLenghtRef.current !== derivAccountList.length || !isSubscribed) { subscribeToAllBalance(); + previousDerivAccountListLenghtRef.current = derivAccountList.length; } return () => { if (isSubscribed) { unsubscribeFromAllBalance(); } }; - }, [derivAccountList?.length, isRefetching, isSubscribed, subscribeToAllBalance, unsubscribeFromAllBalance]); + }, [derivAccountList?.length, isSubscribed, subscribeToAllBalance, unsubscribeFromAllBalance]); useEffect(() => { const handleShortcutKey = (event: globalThis.KeyboardEvent) => {