From 0c5d8b3a29bd6186374a8a89e3efe6af1b013f84 Mon Sep 17 00:00:00 2001 From: Jim Daniels Wasswa <104334373+jim-deriv@users.noreply.github.com> Date: Thu, 25 Jul 2024 09:27:31 +0800 Subject: [PATCH] [WALL] Jim/WALL-4588/update expectations and conditional (#16183) * chore: update expectations and conditional * chore: add isSubscribed to conditional * chore: update ref name --- packages/wallets/src/AppContent.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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) => {