Redirect to previous page on connecting wallet
This commit is contained in:
parent
a83205909b
commit
8b04536f90
@ -20,7 +20,7 @@ function App() {
|
|||||||
<WalletConnectProvider>
|
<WalletConnectProvider>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/" element={<TermsAndConditions />} />
|
<Route path="/" element={<TermsAndConditions />} />
|
||||||
<Route path="/connect-wallet" element={<ConnectWallet />} />
|
<Route path="/connect-wallet/:redirectTo?" element={<ConnectWallet />} />
|
||||||
<Route element={<SignPageLayout />}>
|
<Route element={<SignPageLayout />}>
|
||||||
<Route path="/sign-with-nitro-key" element={<SignWithNitroKey />} />
|
<Route path="/sign-with-nitro-key" element={<SignWithNitroKey />} />
|
||||||
<Route
|
<Route
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Outlet, useNavigate } from "react-router-dom";
|
import { Outlet, useLocation, useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Toolbar,
|
Toolbar,
|
||||||
@ -14,10 +14,14 @@ import { useWalletConnectContext } from "../context/WalletConnectContext";
|
|||||||
const SignPageLayout = () => {
|
const SignPageLayout = () => {
|
||||||
const { disconnect, session } = useWalletConnectContext();
|
const { disconnect, session } = useWalletConnectContext();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
const disconnectHandler = async () => {
|
const disconnectHandler = async () => {
|
||||||
|
const { pathname } = location;
|
||||||
|
const redirectTo = pathname ? pathname.substring(1) : "";
|
||||||
|
|
||||||
await disconnect();
|
await disconnect();
|
||||||
navigate("/");
|
navigate(`/connect-wallet/${redirectTo}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect } from "react";
|
import React, { useEffect } from "react";
|
||||||
import {useNavigate } from "react-router-dom";
|
import {useLocation, useNavigate, useParams } from "react-router-dom";
|
||||||
|
|
||||||
import { Button, Box, Container, Typography, colors } from "@mui/material";
|
import { Button, Box, Container, Typography, colors } from "@mui/material";
|
||||||
|
|
||||||
@ -11,13 +11,19 @@ const ConnectWallet = () => {
|
|||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const {redirectTo} = useParams();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
if (session) {
|
if (session) {
|
||||||
|
if (redirectTo){
|
||||||
|
navigate(`/${redirectTo}`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
navigate("/sign-with-nitro-key");
|
navigate("/sign-with-nitro-key");
|
||||||
}
|
}
|
||||||
}, [session, navigate,]);
|
}
|
||||||
|
}, [session, navigate, redirectTo]);
|
||||||
|
|
||||||
const handler = async () => {
|
const handler = async () => {
|
||||||
await connect();
|
await connect();
|
||||||
|
Loading…
Reference in New Issue
Block a user