diff --git a/src/hooks/api/advert/p2p-advertiser-adverts/useAdvertiserAdverts.ts b/src/hooks/api/advert/p2p-advertiser-adverts/useAdvertiserAdverts.ts index 34e56f57..3a473d76 100644 --- a/src/hooks/api/advert/p2p-advertiser-adverts/useAdvertiserAdverts.ts +++ b/src/hooks/api/advert/p2p-advertiser-adverts/useAdvertiserAdverts.ts @@ -2,9 +2,13 @@ import { useMemo } from 'react'; import { useP2PAdvertiserAdverts } from '@deriv-com/api-hooks'; /** This custom hook returns a list of adverts under the current active client. */ -const useAdvertiserAdverts = (payload?: NonNullable[0]>['payload']) => { +const useAdvertiserAdverts = ( + payload?: NonNullable[0]>['payload'], + isEnabled = true +) => { const { data, loadMoreAdverts, ...rest } = useP2PAdvertiserAdverts({ payload: { ...payload, offset: payload?.offset, limit: payload?.limit }, + enabled: isEnabled, }); const modified_data = useMemo(() => { diff --git a/src/hooks/api/advertiser/p2p-advertiser/useAdvertiserInfo.ts b/src/hooks/api/advertiser/p2p-advertiser/useAdvertiserInfo.ts index 36b0239a..d077fa33 100644 --- a/src/hooks/api/advertiser/p2p-advertiser/useAdvertiserInfo.ts +++ b/src/hooks/api/advertiser/p2p-advertiser/useAdvertiserInfo.ts @@ -1,9 +1,9 @@ -import { useCallback, useEffect } from 'react'; +import { useEffect } from 'react'; import { DeepPartial } from 'react-hook-form'; import { useLocalStorage } from 'usehooks-ts'; import { useP2PAdvertiserInfo } from '@deriv-com/api-hooks'; -type TP2PAdvertiserInfo = ReturnType & { +type TP2PAdvertiserInfo = ReturnType['data'] & { has_basic_verification: boolean; has_full_verification: boolean; is_approved_boolean: boolean; @@ -14,11 +14,9 @@ type TP2PAdvertiserInfo = ReturnType & { should_show_name: boolean; }; -type TPayload = NonNullable> & { id?: string }; - /** This custom hook returns information about the given advertiser ID */ const useAdvertiserInfo = (id?: string) => { - const { data, error, subscribe: subscribeAdvertiserInfo, ...rest } = useP2PAdvertiserInfo(); + const { data, error, ...rest } = useP2PAdvertiserInfo(); /** * Use different local storage key for each advertiser, one to keep the current user's info, the other to keep the advertiser's info @@ -32,13 +30,6 @@ const useAdvertiserInfo = (id?: string) => { {} ); - const subscribe = useCallback( - (payload?: TPayload) => { - subscribeAdvertiserInfo({ payload }); - }, - [subscribeAdvertiserInfo] - ); - // Add additional information to the p2p_advertiser_info data useEffect(() => { if (data) { @@ -85,7 +76,6 @@ const useAdvertiserInfo = (id?: string) => { /** P2P advertiser information */ data: p2p_advertiser_info, error, - subscribe, ...rest, }; }; diff --git a/src/pages/my-ads/screens/MyAds/MyAdsTable/MyAdsTable.tsx b/src/pages/my-ads/screens/MyAds/MyAdsTable/MyAdsTable.tsx index 478cc0d3..14222c55 100644 --- a/src/pages/my-ads/screens/MyAds/MyAdsTable/MyAdsTable.tsx +++ b/src/pages/my-ads/screens/MyAds/MyAdsTable/MyAdsTable.tsx @@ -45,14 +45,7 @@ const columns = [ const MyAdsTable = () => { const isAdvertiser = useIsAdvertiser(); - const { - data = [], - isFetching, - isLoading, - loadMoreAdverts, - } = api.advertiserAdverts.useGet(undefined, { - enabled: isAdvertiser, - }); + const { data = [], isFetching, isLoading, loadMoreAdverts } = api.advertiserAdverts.useGet(undefined, isAdvertiser); const { data: advertiserInfo } = api.advertiser.useGetInfo(); const { balance_available: balanceAvailable, diff --git a/src/routes/AppContent/index.tsx b/src/routes/AppContent/index.tsx index e1ca1454..cacde618 100644 --- a/src/routes/AppContent/index.tsx +++ b/src/routes/AppContent/index.tsx @@ -29,13 +29,13 @@ const AppContent = () => { useEffect(() => { if (activeAccountData) { - subscribeP2PSettings(); + subscribeP2PSettings({}); } }, [activeAccountData, subscribeP2PSettings]); useEffect(() => { if (isSuccess) { - subscribeAdvertiserInfo(); + subscribeAdvertiserInfo({}); } }, [isSuccess, subscribeAdvertiserInfo]); @@ -43,7 +43,7 @@ const AppContent = () => { // setHasCreatedAdvertiser is triggered inside of NicknameModal. useEffect(() => { if (isSuccess && hasCreatedAdvertiser) { - subscribeAdvertiserInfo(); + subscribeAdvertiserInfo({}); } }, [hasCreatedAdvertiser, isSuccess, subscribeAdvertiserInfo]);