Skip to content

Commit

Permalink
[WALL] Jim/WALL-4588/update expectations and conditional (binary-com#…
Browse files Browse the repository at this point in the history
…16183)

* chore: update expectations and conditional

* chore: add isSubscribed to conditional

* chore: update ref name
  • Loading branch information
jim-deriv committed Jul 25, 2024
1 parent 0cd817a commit 0c5d8b3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/wallets/src/AppContent.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) => {
Expand Down

0 comments on commit 0c5d8b3

Please sign in to comment.