Add terms and conditions page and update cosmos tx message #2
75
src/components/TermsAndConditionsCard.tsx
Normal file
75
src/components/TermsAndConditionsCard.tsx
Normal file
@ -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<HTMLInputElement>) => {
|
||||||
|
setChecked(event.target.checked);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleContinue = () => {
|
||||||
|
handleAccept()
|
||||||
|
setIsHidden(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRadioChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
setSelectedRole((event.target as HTMLInputElement).value);
|
||||||
|
handleRoleChange((event.target as HTMLInputElement).value);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Paper elevation={3} style={{ padding: '2rem', marginTop: '2rem', display: isHidden ? "none" : "block" }}>
|
||||||
|
<FormControl component="fieldset">
|
||||||
|
<FormLabel component="legend">Select your role</FormLabel>
|
||||||
|
<RadioGroup
|
||||||
|
aria-label="roles"
|
||||||
|
name="roles"
|
||||||
|
value={selectedRole}
|
||||||
|
onChange={handleRadioChange}
|
||||||
|
>
|
||||||
|
<FormControlLabel
|
||||||
|
value={VALIDATOR_OPTION}
|
||||||
|
control={<Radio />}
|
||||||
|
label="Validator"
|
||||||
|
/>
|
||||||
|
<FormControlLabel
|
||||||
|
value={PARTICIPANT_OPTION}
|
||||||
|
control={<Radio />}
|
||||||
|
label="Participant"
|
||||||
|
/>
|
||||||
|
</RadioGroup>
|
||||||
|
</FormControl>
|
||||||
|
<Box mt={2} display="flex" alignItems="center">
|
||||||
|
<Checkbox
|
||||||
|
checked={checked}
|
||||||
|
onChange={handleCheckboxChange}
|
||||||
|
color="primary"
|
||||||
|
/>
|
||||||
|
<Typography variant="body1">
|
||||||
|
I accept the <Link href={selectedRole === VALIDATOR_OPTION ? '/validators' : '/participants'} target="_blank" rel="noopener">
|
||||||
|
terms and conditions
|
||||||
|
</Link>
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box mt={4} display="flex" justifyContent="end">
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={handleContinue}
|
||||||
|
disabled={!checked}
|
||||||
|
>
|
||||||
|
Continue
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</Paper>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TermsAndConditionsCard;
|
@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect } from "react";
|
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";
|
import { Button, Box, Container } from "@mui/material";
|
||||||
|
|
||||||
@ -10,11 +10,16 @@ const ConnectWallet = () => {
|
|||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const location = useLocation();
|
||||||
|
const queryParams = new URLSearchParams(location.search);
|
||||||
|
const kycId = queryParams.get('kycId');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
if (session) {
|
if (session) {
|
||||||
navigate("/user-verification");
|
navigate(`/sign-with-nitro-key?kycId=${kycId}`);
|
||||||
}
|
}
|
||||||
}, [session, navigate]);
|
}, [session, navigate, kycId]);
|
||||||
|
|
||||||
const handler = async () => {
|
const handler = async () => {
|
||||||
await connect();
|
await connect();
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
import { StargateClient } from "@cosmjs/stargate";
|
import { StargateClient } from "@cosmjs/stargate";
|
||||||
|
|
||||||
import { useWalletConnectContext } from "../context/WalletConnectContext";
|
import { useWalletConnectContext } from "../context/WalletConnectContext";
|
||||||
|
import TermsAndConditionsCard from "../components/TermsAndConditionsCard";
|
||||||
|
|
||||||
const SignWithCosmos = () => {
|
const SignWithCosmos = () => {
|
||||||
const { session, signClient } = useWalletConnectContext();
|
const { session, signClient } = useWalletConnectContext();
|
||||||
@ -24,6 +25,8 @@ const SignWithCosmos = () => {
|
|||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [balance, setBalance] = useState('');
|
const [balance, setBalance] = useState('');
|
||||||
const [isRequesting, setIsRequesting] = useState(false);
|
const [isRequesting, setIsRequesting] = useState(false);
|
||||||
|
const [isTncAccepted, setIsTncAccepted] = useState(false);
|
||||||
|
const [role, setRole] = useState('participant');
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const innerMessage = location.state;
|
const innerMessage = location.state;
|
||||||
@ -41,10 +44,11 @@ const SignWithCosmos = () => {
|
|||||||
participant: cosmosAddress!,
|
participant: cosmosAddress!,
|
||||||
ethPayload: innerMessage,
|
ethPayload: innerMessage,
|
||||||
ethSignature: ethSignature!,
|
ethSignature: ethSignature!,
|
||||||
kycId: kycId
|
kycId,
|
||||||
|
role
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}, [cosmosAddress, innerMessage, ethSignature, kycId]);
|
}, [cosmosAddress, innerMessage, ethSignature, kycId, role]);
|
||||||
|
|
||||||
const handleTokenRequest = async () => {
|
const handleTokenRequest = async () => {
|
||||||
try {
|
try {
|
||||||
@ -134,10 +138,12 @@ const SignWithCosmos = () => {
|
|||||||
sx={{
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
marginTop: "100px",
|
marginY: "100px",
|
||||||
gap: "10px",
|
gap: "10px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<Typography variant="h5">Please accept terms and conditions to continue</Typography>
|
||||||
|
<TermsAndConditionsCard handleAccept={() => setIsTncAccepted(true)} handleRoleChange={setRole}/>
|
||||||
<Typography variant="h5">Send transaction to chain</Typography>
|
<Typography variant="h5">Send transaction to chain</Typography>
|
||||||
<Typography>Cosmos Account:</Typography>
|
<Typography>Cosmos Account:</Typography>
|
||||||
<Card className='mt-1 mb-1'>
|
<Card className='mt-1 mb-1'>
|
||||||
@ -151,7 +157,7 @@ const SignWithCosmos = () => {
|
|||||||
<LoadingButton
|
<LoadingButton
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={handleTokenRequest}
|
onClick={handleTokenRequest}
|
||||||
disabled={isRequesting}
|
disabled={isTncAccepted ? isRequesting : !isTncAccepted}
|
||||||
loading={isRequesting}
|
loading={isRequesting}
|
||||||
>
|
>
|
||||||
Request tokens from Faucet
|
Request tokens from Faucet
|
||||||
@ -182,7 +188,7 @@ const SignWithCosmos = () => {
|
|||||||
await sendTransaction(onboardParticipantMsg);
|
await sendTransaction(onboardParticipantMsg);
|
||||||
}}
|
}}
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
disabled={balance === '0'}
|
disabled={isTncAccepted ? (balance === '0') : !isTncAccepted}
|
||||||
>
|
>
|
||||||
Send transaction
|
Send transaction
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
|
@ -22,7 +22,7 @@ const UserVerification = () => {
|
|||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
if (applicationSubmitted && kycId !== '') {
|
if (applicationSubmitted && kycId !== '') {
|
||||||
navigate(`/sign-with-nitro-key?kycId=${kycId}`)
|
navigate(`/connect-wallet?kycId=${kycId}`)
|
||||||
}
|
}
|
||||||
}, [applicationSubmitted, kycId, navigate]);
|
}, [applicationSubmitted, kycId, navigate]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user