diff --git a/src/App.tsx b/src/App.tsx index ad4399f..6821a40 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -14,7 +14,7 @@ import { WalletConnectProvider } from "./context/WalletConnectContext"; import VerifyEmail from "./pages/VerifyEmail"; import Email from "./pages/Email"; import Thanks from "./pages/Thanks"; -import CreateValidator from "./pages/CreateValidator"; +import Validator from "./pages/Validator"; function App() { return ( @@ -25,7 +25,7 @@ function App() { } /> } /> } /> - } /> + } /> } /> }> } /> @@ -43,7 +43,7 @@ function App() { > } + element={} > } /> diff --git a/src/layout/SignPageLayout.tsx b/src/layout/SignPageLayout.tsx index 208d503..b985f1c 100644 --- a/src/layout/SignPageLayout.tsx +++ b/src/layout/SignPageLayout.tsx @@ -21,7 +21,7 @@ const SignPageLayout = () => { const redirectTo = pathname ? pathname.substring(1) : ""; await disconnect(); - navigate(`/connect-wallet/${redirectTo}`); + navigate(`/connect-wallet?redirectTo=${redirectTo}`); }; return ( diff --git a/src/pages/ConnectWallet.tsx b/src/pages/ConnectWallet.tsx index aabaa2e..7492805 100644 --- a/src/pages/ConnectWallet.tsx +++ b/src/pages/ConnectWallet.tsx @@ -1,5 +1,5 @@ import React, { useEffect } from "react"; -import {useNavigate, useParams } from "react-router-dom"; +import {useLocation, useNavigate, useParams, useSearchParams } from "react-router-dom"; import { Button, Box, Container, Typography, colors } from "@mui/material"; @@ -7,14 +7,21 @@ import { useWalletConnectContext } from "../context/WalletConnectContext"; import { WALLET_DISCLAIMER_MSG } from "../constants"; const ConnectWallet = () => { - const { connect, session } = useWalletConnectContext(); + const { connect, session, signClient, checkPersistedState } = useWalletConnectContext(); const navigate = useNavigate(); const location = useLocation(); - const {redirectTo} = useParams(); + const [searchParams] = useSearchParams(); + + const redirectTo = searchParams.get("redirectTo") + + useEffect(()=>{ + if (signClient && !session) { + checkPersistedState(signClient); + } + }, [checkPersistedState, signClient, session]); useEffect(() => { - if (session) { if (redirectTo){ navigate(`/${redirectTo}`, { diff --git a/src/pages/SignWithNitroKey.tsx b/src/pages/SignWithNitroKey.tsx index 70eb635..5e0e06e 100644 --- a/src/pages/SignWithNitroKey.tsx +++ b/src/pages/SignWithNitroKey.tsx @@ -17,16 +17,20 @@ import { ENABLE_KYC, SUBSCRIBER_ID_HASH_KEY } from "../constants"; const SignWithNitroKey = () => { - const { session, signClient, checkPersistedState } = + const { session, signClient } = useWalletConnectContext(); - useEffect(() => { - if (signClient && !session) { - checkPersistedState(signClient); - } - }, [session, signClient, checkPersistedState]); - const navigate = useNavigate(); + const location = useLocation(); + + useEffect(() => { + if (!session){ + navigate("/connect-wallet?redirectTo=sign-with-nitro-key", { + state: location.state, + }); + } + }, [session, navigate, location.state]); + const [ethAddress, setEthAddress] = useState(""); const [ethSignature, setEthSignature] = useState(""); diff --git a/src/pages/Thanks.tsx b/src/pages/Thanks.tsx index 6cd4c3e..e62f4c9 100644 --- a/src/pages/Thanks.tsx +++ b/src/pages/Thanks.tsx @@ -45,7 +45,7 @@ const Thanks: React.FC = () => { localStorage.setItem(SUBSCRIBER_ID_HASH_KEY, subscriberIdHash); - navigate('/connect-wallet'); + navigate('/sign-with-nitro-key'); } catch (error) { setErr(String(error)); } diff --git a/src/pages/CreateValidator.tsx b/src/pages/Validator.tsx similarity index 82% rename from src/pages/CreateValidator.tsx rename to src/pages/Validator.tsx index 70bf382..67daa80 100644 --- a/src/pages/CreateValidator.tsx +++ b/src/pages/Validator.tsx @@ -12,24 +12,24 @@ import { Registry } from '@cerc-io/registry-sdk'; import { useWalletConnectContext } from '../context/WalletConnectContext' import { Participant } from '../types'; -const CreateValidator = () => { +const Validator = () => { const {session, signClient} = useWalletConnectContext(); const navigate = useNavigate(); const [cosmosAddress, setCosmosAddress] = useState('laconic1z4l4556v8jnk7k456ujme720nk8mzjwhka7qvw'); const [isLoading, setIsLoading] = useState(false); - const [pubkey, setPubkey] = useState('d5aOEYaCIHaDn6kG0tAg699D7sLgAgkJI5reTMl0o5U='); + const [pubkey, setPubkey] = useState('qiQEvyqIf9/e912ZEIZD5CfdqR3iOlpI+NVtRnpHuYc='); const [participant, setParticipant] = useState(null); if (!session){ - navigate("/connect-wallet") + navigate("/connect-wallet?redirectTo=create-validator"); } const msgCreateValidator: MsgCreateValidator = useMemo(() => { return { description: { - moniker: "dockerNode", + moniker: "dockerNode2", identity: "", website: "", securityContact: "", @@ -41,7 +41,7 @@ const CreateValidator = () => { rate: "100000000000000000", // 0.1 }, minSelfDelegation: "1", - delegatorAddress: cosmosAddress, + delegatorAddress: '', validatorAddress: toBech32('laconicvaloper', fromBech32(cosmosAddress).data), pubkey: encodePubkey({ type: "tendermint/PubKeyEd25519", @@ -183,38 +183,38 @@ const CreateValidator = () => { )} - {participant && participant.role === "validator" && ( - <> - Send transaction to chain - + Send transaction to chain + + + {JSON.stringify(msgCreateValidator, null, 2)} + + + + { + console.log(msgCreateValidatorEncodeObject); + await sendTransaction(msgCreateValidatorEncodeObject); }} + loading={isLoading} > - - {JSON.stringify(msgCreateValidator, null, 2)} - - - - { - console.log(msgCreateValidatorEncodeObject); - await sendTransaction(msgCreateValidatorEncodeObject); - }} - loading={isLoading} - > - Send transaction - - - > - )} + Send transaction + + + > + {/* )} */} )} ) } -export default CreateValidator +export default Validator
+ {JSON.stringify(msgCreateValidator, null, 2)} +
- {JSON.stringify(msgCreateValidator, null, 2)} -