From 550f8b9fd7b0bd86fe1ecc18c745c75582c791f5 Mon Sep 17 00:00:00 2001 From: Josemaria Nriagu Date: Tue, 4 Feb 2025 13:48:59 +0100 Subject: [PATCH] chore(): remove unused custom hooks Signed-off-by: Josemaria Nriagu --- libs/hooks/README.md | 6 -- .../src/__tests__/use-network-state.spec.ts | 10 --- libs/hooks/src/index.ts | 3 - libs/hooks/src/use-network-state.ts | 82 ------------------- libs/hooks/src/use-show-feedback.ts | 29 ------- 5 files changed, 130 deletions(-) delete mode 100644 libs/hooks/src/__tests__/use-network-state.spec.ts delete mode 100644 libs/hooks/src/use-show-feedback.ts diff --git a/libs/hooks/README.md b/libs/hooks/README.md index 31d0cc9947..de01ecb2c6 100644 --- a/libs/hooks/README.md +++ b/libs/hooks/README.md @@ -19,12 +19,6 @@ This package contains all hooks required for proper functioning of the AKASHA Co - getLegalDoc -### [useNetworkState](./src/use-network-state.ts) - -> handles checks to ensure that the user is on the appropriate ethereum network required for the app. Available actions include; - -- checkNetwork - ### [useNotifications](./src/use-notifications.ts) > handles enabling of notifications and exposes status of pending signature request. diff --git a/libs/hooks/src/__tests__/use-network-state.spec.ts b/libs/hooks/src/__tests__/use-network-state.spec.ts deleted file mode 100644 index 8cc6cb391f..0000000000 --- a/libs/hooks/src/__tests__/use-network-state.spec.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { renderHook } from '@testing-library/react-hooks'; -import { useNetworkState } from '../use-network-state'; - -describe('useNetworkState', () => { - it('should return the network state', async () => { - const { result, waitFor } = renderHook(() => useNetworkState(true)); - await waitFor(() => result.current.isFetched, { timeout: 5000 }); - expect(result.current.data?.networkNotSupported).toBeFalsy(); - }); -}); diff --git a/libs/hooks/src/index.ts b/libs/hooks/src/index.ts index 13cc24142d..14033c5e63 100644 --- a/libs/hooks/src/index.ts +++ b/libs/hooks/src/index.ts @@ -12,8 +12,6 @@ export { hasOwn } from './utils/has-own'; export { sortByKey } from './utils/sort-by-key'; export { createReactiveVar } from './utils/create-reactive-var'; export { - useNetworkState, - useCurrentNetwork, useRequiredNetwork, switchToRequiredNetwork, useNetworkChangeListener, @@ -30,7 +28,6 @@ export { useModalData } from './use-modal-data'; // the following hooks needs refactor/reimplementation export { useListenForMutationEvents } from './use-mutation-events-listener'; -export { useShowFeedback } from './use-show-feedback'; export { useTheme } from './use-theme'; export { useProfileStats } from './use-profile-stats'; export { useSaveSettings, useGetSettings } from './use-settings'; diff --git a/libs/hooks/src/use-network-state.ts b/libs/hooks/src/use-network-state.ts index 0e38760ba9..fdc8af2035 100644 --- a/libs/hooks/src/use-network-state.ts +++ b/libs/hooks/src/use-network-state.ts @@ -23,94 +23,12 @@ const checkNetworkState = async () => { return res; }; -/** - * Hook to check if the web3 provider is set to function on the Rinkeby test network - * @param enabler - boolean (optional) that can control when to start verifying network state - * @returns networkNotSupported: true if web3 provider is not on the specified network - * @example useNetworkState hook - * ```typescript - * const networkStateQuery = useNetworkState(true); - * - * const networkNotSupported = networkStateQuery.data.networkNotSupported; - * ``` - */ -export function useNetworkState(enabler?: boolean) { - const [data, setData] = useState<{ - networkNotSupported: boolean; - }>(undefined); - const [isLoading, setIsLoading] = useState(true); - const [isFetched, setIsFetched] = useState(false); - const [error, setError] = useState(null); - - useEffect(() => { - const fetchData = async () => { - try { - const res = await checkNetworkState(); - if (res) { - setData(res); - setIsLoading(false); - setIsFetched(true); - } - } catch (err) { - setError(err); - logError('useNetworkState', err); - setIsLoading(false); - setIsFetched(true); - } - }; - - if (enabler) { - fetchData(); - } - }, [enabler]); - - return { data, isLoading, error, isFetched }; -} - const getCurrentNetwork = () => { const sdk = getSDK(); const res = sdk.services.common.web3.network; return res; }; -/** - * Hook to check the user's current web3 network - * @returns network name - * @example useCurrentNetwork hook - * ```typescript - * const currentNetworkQuery = useCurrentNetwork(true); - * - * const network = currentNetworkQuery.data; - * ``` - */ -export function useCurrentNetwork(enabler?: boolean) { - const [data, setData] = useState(undefined); - const [isLoading, setIsLoading] = useState(true); - const [error, setError] = useState(null); - - useEffect(() => { - const fetchData = async () => { - try { - const res = await getCurrentNetwork(); - if (res) { - setData(res); - setIsLoading(false); - } - } catch (err) { - setError(err); - logError('useCurrentNetwork', err); - setIsLoading(false); - } - }; - - if (enabler) { - fetchData(); - } - }, [enabler]); - - return { data, isLoading, error }; -} - const getRequiredNetwork = async () => { const sdk = getSDK(); const networkName = sdk.services.common.web3.getRequiredNetwork(); diff --git a/libs/hooks/src/use-show-feedback.ts b/libs/hooks/src/use-show-feedback.ts deleted file mode 100644 index 81aaf77bdd..0000000000 --- a/libs/hooks/src/use-show-feedback.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Dispatch, SetStateAction, useEffect, useState } from 'react'; - -/** - * Hook to manage the state of the feedback shown in the snackbar. - * @example useTheme hook - * ```typescript - * const [showFeedback, setShowFeedback] = useShowFeedback(); - * ``` - * @param initialShowValue - boolean (optional) - * @returns { showFeedback, setShowFeedback } The state of whether to - * show the feedback message and a function to set that state. - **/ -export function useShowFeedback( - initialShowValue?: boolean, -): [boolean, Dispatch>] { - const [showFeedback, setShowFeedback] = useState(initialShowValue); - - useEffect(() => { - const timeoutId = setTimeout(() => { - setShowFeedback(false); - }, 5000); - - return () => { - clearTimeout(timeoutId); - }; - }, [showFeedback]); - - return [showFeedback, setShowFeedback]; -}