From 311ae4c99a7a8c99bc15f4052d61c19984f80257 Mon Sep 17 00:00:00 2001 From: pulkit-999 <97938993+pulkit-999@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:40:25 +0530 Subject: [PATCH] Update use-app-config.ts No need of if condition which is used in the code, it will be handled internally i think. --- app/hooks/use-app-config.ts | 83 +++++++++++++------------------------ 1 file changed, 29 insertions(+), 54 deletions(-) diff --git a/app/hooks/use-app-config.ts b/app/hooks/use-app-config.ts index 88d4765a40..485322a4e4 100644 --- a/app/hooks/use-app-config.ts +++ b/app/hooks/use-app-config.ts @@ -1,66 +1,41 @@ -import { useCallback, useMemo } from "react" - -import { GaloyInstance, resolveGaloyInstanceOrDefault } from "@app/config" -import { usePersistentStateContext } from "@app/store/persistent-state" +import { useCallback, useMemo } from "react"; +import { GaloyInstance, resolveGaloyInstanceOrDefault } from "@app/config"; +import { usePersistentStateContext } from "@app/store/persistent-state"; export const useAppConfig = () => { - const { persistentState, updateState } = usePersistentStateContext() + const { persistentState, updateState } = usePersistentStateContext(); - const appConfig = useMemo( - () => ({ - token: persistentState.galoyAuthToken, - galoyInstance: resolveGaloyInstanceOrDefault(persistentState.galoyInstance), - }), - [persistentState.galoyAuthToken, persistentState.galoyInstance], - ) + const appConfig = useMemo(() => ({ + token: persistentState.galoyAuthToken, + galoyInstance: resolveGaloyInstanceOrDefault(persistentState.galoyInstance), + }), [persistentState.galoyAuthToken, persistentState.galoyInstance]); - const setGaloyInstance = useCallback( - (newInstance: GaloyInstance) => { - updateState((state) => { - if (state) - return { - ...state, - galoyInstance: newInstance, - } - return undefined - }) - }, - [updateState], - ) + const setGaloyInstance = useCallback((newInstance: GaloyInstance) => { + updateState((state) => ({ + ...state, + galoyInstance: newInstance, + })); + }, [updateState]); - const saveToken = useCallback( - (token: string) => { - updateState((state) => { - if (state) - return { - ...state, - galoyAuthToken: token, - } - return undefined - }) - }, - [updateState], - ) + const saveToken = useCallback((token: string) => { + updateState((state) => ({ + ...state, + galoyAuthToken: token, + })); + }, [updateState]); - const saveTokenAndInstance = useCallback( - ({ token, instance }: { token: string; instance: GaloyInstance }) => { - updateState((state) => { - if (state) - return { - ...state, - galoyInstance: instance, - galoyAuthToken: token, - } - return undefined - }) - }, - [updateState], - ) + const saveTokenAndInstance = useCallback(({ token, instance }: { token: string; instance: GaloyInstance }) => { + updateState((state) => ({ + ...state, + galoyInstance: instance, + galoyAuthToken: token, + })); + }, [updateState]); return { appConfig, setGaloyInstance, saveToken, saveTokenAndInstance, - } -} + }; +};