Refactor useEffect

This commit is contained in:
Adw8 2024-08-09 15:23:09 +05:30
parent eb9896df87
commit 57e2c0c628
4 changed files with 19 additions and 16 deletions

View File

@ -41,15 +41,15 @@ function App() {
<Route <Route
path="/onboarding-success" path="/onboarding-success"
element={<OnboardingSuccess />} element={<OnboardingSuccess />}
></Route> />
<Route <Route
path="/validator" path="/validator"
element={<Validator />} element={<Validator />}
></Route> />
<Route <Route
path="/validator-success" path="/validator-success"
element={<ValidatorSuccess />} element={<ValidatorSuccess />}
></Route> />
</Route> </Route>
<Route path="*" element={<PageNotFound />} /> <Route path="*" element={<PageNotFound />} />
</Routes> </Routes>

View File

@ -16,6 +16,7 @@ const TermsAndConditionsBox = ({ height, onLoad }: TermsAndConditionsBoxProps )
function onDocumentLoadSuccess({ numPages }: { numPages: number }): void { function onDocumentLoadSuccess({ numPages }: { numPages: number }): void {
setNumPages(numPages); setNumPages(numPages);
if (onLoad){ if (onLoad){
onLoad(); onLoad();
}; };

View File

@ -15,25 +15,27 @@ const ConnectWallet = () => {
const redirectTo = searchParams.get("redirectTo"); const redirectTo = searchParams.get("redirectTo");
useEffect(()=>{ useEffect(() => {
if (signClient && !session) { if (signClient && !session) {
checkPersistedState(signClient); checkPersistedState(signClient);
} }
}, [checkPersistedState, signClient, session]); }, [checkPersistedState, signClient, session]);
useEffect(() => { useEffect(() => {
if (session) { if (!session) {
if (redirectTo){ return;
navigate(`/${redirectTo}`, { }
state: location.state
});
} if (redirectTo) {
else { navigate(`/${redirectTo}`, {
navigate("/sign-with-nitro-key", { state: location.state
state: location.state });
}); }
}
else {
navigate("/sign-with-nitro-key", {
state: location.state
});
} }
}, [session, navigate, redirectTo, location.state]); }, [session, navigate, redirectTo, location.state]);

View File

@ -24,7 +24,7 @@ const SignWithNitroKey = () => {
const location = useLocation(); const location = useLocation();
useEffect(() => { useEffect(() => {
if (!session){ if (!session) {
navigate("/connect-wallet?redirectTo=sign-with-nitro-key", { navigate("/connect-wallet?redirectTo=sign-with-nitro-key", {
state: location.state, state: location.state,
}); });