From 11b11f6a2b7a4bf1664185b20abfc01fa22d2926 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Thu, 25 Jul 2024 19:40:17 +0530 Subject: [PATCH] Add terms and conditions before sending cosmos tx --- src/components/TermsAndConditionsCard.tsx | 75 +++++++++++++++++++++++ src/pages/ConnectWallet.tsx | 11 +++- src/pages/SignWithCosmos.tsx | 16 +++-- src/pages/SignWithNitroKey.tsx | 2 +- src/pages/UserVerification.tsx | 2 +- 5 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 src/components/TermsAndConditionsCard.tsx diff --git a/src/components/TermsAndConditionsCard.tsx b/src/components/TermsAndConditionsCard.tsx new file mode 100644 index 0000000..bcca621 --- /dev/null +++ b/src/components/TermsAndConditionsCard.tsx @@ -0,0 +1,75 @@ +import React, { useState } from 'react'; + +import { Typography, Button, Box, Paper, Radio, RadioGroup, FormControlLabel, FormControl, FormLabel, Link, Checkbox } from '@mui/material'; + +const VALIDATOR_OPTION = "validator"; +const PARTICIPANT_OPTION = "participant"; + +const TermsAndConditionsCard = ({ handleAccept, handleRoleChange }: { handleAccept: () => void, handleRoleChange: (role: string) => void }) => { + const [selectedRole, setSelectedRole] = useState(PARTICIPANT_OPTION); + const [checked, setChecked] = useState(false); + const [isHidden, setIsHidden] = useState(false); + + const handleCheckboxChange = (event: React.ChangeEvent) => { + setChecked(event.target.checked); + }; + + const handleContinue = () => { + handleAccept() + setIsHidden(true) + } + + const handleRadioChange = (event: React.ChangeEvent) => { + setSelectedRole((event.target as HTMLInputElement).value); + handleRoleChange((event.target as HTMLInputElement).value); + }; + + return ( + + + Select your role + + } + label="Validator" + /> + } + label="Participant" + /> + + + + + + I accept the + terms and conditions + + + + + + + + ); +}; + +export default TermsAndConditionsCard; diff --git a/src/pages/ConnectWallet.tsx b/src/pages/ConnectWallet.tsx index 82ddfd1..58ccc7d 100644 --- a/src/pages/ConnectWallet.tsx +++ b/src/pages/ConnectWallet.tsx @@ -1,5 +1,5 @@ import React, { useEffect } from "react"; -import { useNavigate } from "react-router-dom"; +import { useLocation, useNavigate } from "react-router-dom"; import { Button, Box, Container } from "@mui/material"; @@ -10,11 +10,16 @@ const ConnectWallet = () => { const navigate = useNavigate(); + const location = useLocation(); + const queryParams = new URLSearchParams(location.search); + const kycId = queryParams.get('kycId'); + useEffect(() => { + if (session) { - navigate("/user-verification"); + navigate(`/sign-with-nitro-key?kycId=${kycId}`); } - }, [session, navigate]); + }, [session, navigate, kycId]); const handler = async () => { await connect(); diff --git a/src/pages/SignWithCosmos.tsx b/src/pages/SignWithCosmos.tsx index ba59956..e141890 100644 --- a/src/pages/SignWithCosmos.tsx +++ b/src/pages/SignWithCosmos.tsx @@ -11,6 +11,7 @@ import { import { StargateClient } from "@cosmjs/stargate"; import { useWalletConnectContext } from "../context/WalletConnectContext"; +import TermsAndConditionsCard from "../components/TermsAndConditionsCard"; const SignWithCosmos = () => { const { session, signClient } = useWalletConnectContext(); @@ -24,6 +25,8 @@ const SignWithCosmos = () => { const [isLoading, setIsLoading] = useState(false); const [balance, setBalance] = useState(''); const [isRequesting, setIsRequesting] = useState(false); + const [isTncAccepted, setIsTncAccepted] = useState(false); + const [role, setRole] = useState('participant'); const navigate = useNavigate(); const innerMessage = location.state; @@ -41,10 +44,11 @@ const SignWithCosmos = () => { participant: cosmosAddress!, ethPayload: innerMessage, ethSignature: ethSignature!, - kycId: kycId + kycId, + role }, }; - }, [cosmosAddress, innerMessage, ethSignature, kycId]); + }, [cosmosAddress, innerMessage, ethSignature, kycId, role]); const handleTokenRequest = async () => { try { @@ -134,10 +138,12 @@ const SignWithCosmos = () => { sx={{ display: "flex", flexDirection: "column", - marginTop: "100px", + marginY: "100px", gap: "10px", }} > + Please accept terms and conditions to continue + setIsTncAccepted(true)} handleRoleChange={setRole}/> Send transaction to chain Cosmos Account: @@ -151,7 +157,7 @@ const SignWithCosmos = () => { Request tokens from Faucet @@ -182,7 +188,7 @@ const SignWithCosmos = () => { await sendTransaction(onboardParticipantMsg); }} loading={isLoading} - disabled={balance === '0'} + disabled={isTncAccepted ? (balance === '0') : !isTncAccepted} > Send transaction diff --git a/src/pages/SignWithNitroKey.tsx b/src/pages/SignWithNitroKey.tsx index 08bff6d..cc97a26 100644 --- a/src/pages/SignWithNitroKey.tsx +++ b/src/pages/SignWithNitroKey.tsx @@ -133,7 +133,7 @@ const SignWithNitroKey = () => { style={{ marginTop: "20px" }} loading={isLoading} > - Sign using Nitro key + Sign using Nitro key diff --git a/src/pages/UserVerification.tsx b/src/pages/UserVerification.tsx index 7baa173..f0710c6 100644 --- a/src/pages/UserVerification.tsx +++ b/src/pages/UserVerification.tsx @@ -22,7 +22,7 @@ const UserVerification = () => { useEffect(()=>{ if (applicationSubmitted && kycId !== '') { - navigate(`/sign-with-nitro-key?kycId=${kycId}`) + navigate(`/connect-wallet?kycId=${kycId}`) } }, [applicationSubmitted, kycId, navigate]);