From 57e2c0c6287f72dc5a0b563039420bce2c5ed43a Mon Sep 17 00:00:00 2001 From: Adw8 Date: Fri, 9 Aug 2024 15:23:09 +0530 Subject: [PATCH] Refactor useEffect --- src/App.tsx | 6 +++--- src/components/TermsAndConditionsBox.tsx | 1 + src/pages/ConnectWallet.tsx | 26 +++++++++++++----------- src/pages/SignWithNitroKey.tsx | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index c31c658..3bd3147 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -41,15 +41,15 @@ function App() { } - > + /> } - > + /> } - > + /> } /> diff --git a/src/components/TermsAndConditionsBox.tsx b/src/components/TermsAndConditionsBox.tsx index 18004b9..ccc3a3c 100644 --- a/src/components/TermsAndConditionsBox.tsx +++ b/src/components/TermsAndConditionsBox.tsx @@ -16,6 +16,7 @@ const TermsAndConditionsBox = ({ height, onLoad }: TermsAndConditionsBoxProps ) function onDocumentLoadSuccess({ numPages }: { numPages: number }): void { setNumPages(numPages); + if (onLoad){ onLoad(); }; diff --git a/src/pages/ConnectWallet.tsx b/src/pages/ConnectWallet.tsx index fbe8115..e904c33 100644 --- a/src/pages/ConnectWallet.tsx +++ b/src/pages/ConnectWallet.tsx @@ -15,25 +15,27 @@ const ConnectWallet = () => { const redirectTo = searchParams.get("redirectTo"); - useEffect(()=>{ + useEffect(() => { if (signClient && !session) { checkPersistedState(signClient); } }, [checkPersistedState, signClient, session]); useEffect(() => { - if (session) { - if (redirectTo){ - navigate(`/${redirectTo}`, { - state: location.state - }); + if (!session) { + return; + } - } - else { - navigate("/sign-with-nitro-key", { - state: location.state - }); - } + if (redirectTo) { + navigate(`/${redirectTo}`, { + state: location.state + }); + } + + else { + navigate("/sign-with-nitro-key", { + state: location.state + }); } }, [session, navigate, redirectTo, location.state]); diff --git a/src/pages/SignWithNitroKey.tsx b/src/pages/SignWithNitroKey.tsx index 8d610e3..0edb193 100644 --- a/src/pages/SignWithNitroKey.tsx +++ b/src/pages/SignWithNitroKey.tsx @@ -24,7 +24,7 @@ const SignWithNitroKey = () => { const location = useLocation(); useEffect(() => { - if (!session){ + if (!session) { navigate("/connect-wallet?redirectTo=sign-with-nitro-key", { state: location.state, });