Redirect to previous page on connecting wallet
This commit is contained in:
parent
34494ece12
commit
000d4ff846
@ -25,7 +25,7 @@ function App() {
|
||||
<Route path="/" element={<LandingPage />} />
|
||||
<Route path="/verify-email" element={<VerifyEmail />} />
|
||||
<Route path="/email" element={<Email/>} />
|
||||
<Route path="/connect-wallet" element={<ConnectWallet />} />
|
||||
<Route path="/connect-wallet/:redirectTo?" element={<ConnectWallet />} />
|
||||
<Route path="/thanks" element={<Thanks />} />
|
||||
<Route element={<SignPageLayout />}>
|
||||
<Route path="/sign-with-nitro-key" element={<SignWithNitroKey />} />
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React from "react";
|
||||
import { Outlet, useNavigate } from "react-router-dom";
|
||||
import { Outlet, useLocation, useNavigate } from "react-router-dom";
|
||||
|
||||
import {
|
||||
Toolbar,
|
||||
@ -14,10 +14,14 @@ import { useWalletConnectContext } from "../context/WalletConnectContext";
|
||||
const SignPageLayout = () => {
|
||||
const { disconnect, session } = useWalletConnectContext();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
const disconnectHandler = async () => {
|
||||
const { pathname } = location;
|
||||
const redirectTo = pathname ? pathname.substring(1) : "";
|
||||
|
||||
await disconnect();
|
||||
navigate("/");
|
||||
navigate(`/connect-wallet/${redirectTo}`);
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { useEffect } from "react";
|
||||
import {useLocation, useNavigate } from "react-router-dom";
|
||||
import {useLocation, useNavigate, useParams } from "react-router-dom";
|
||||
|
||||
import { Button, Box, Container, Typography, colors } from "@mui/material";
|
||||
|
||||
@ -11,15 +11,24 @@ const ConnectWallet = () => {
|
||||
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const {redirectTo} = useParams();
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
if (session) {
|
||||
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, location]);
|
||||
}, [session, navigate, redirectTo, location.state]);
|
||||
|
||||
const handler = async () => {
|
||||
await connect();
|
||||
|
Loading…
Reference in New Issue
Block a user