Compare commits

..

No commits in common. "b79f1d500fbaa840f48fb5736e44b7fa8aef3585" and "08306be36c06843f990e4a6ca3551f0a15cddac6" have entirely different histories.

4 changed files with 48 additions and 85 deletions

View File

@ -1,16 +1,15 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Typography, Button, Box, Paper, Radio, RadioGroup, FormControlLabel, FormControl, FormLabel, Link, Checkbox } from '@mui/material'; import { Typography, Button, Box, Paper, Radio, RadioGroup, FormControlLabel, FormControl, FormLabel, Link, Checkbox } from '@mui/material';
import { Role } from '@cerc-io/registry-sdk/dist/proto/cerc/onboarding/v1/onboarding';
import TermsAndConditionsDialog from './TermsAndConditionsDialog'; import TermsAndConditionsDialog from './TermsAndConditionsDialog';
export enum Role { const VALIDATOR_OPTION = "validator";
Validator = 'validator', const PARTICIPANT_OPTION = "participant";
Participant = 'participant'
}
const TermsAndConditionsCard = ({ handleAccept, handleRoleChange }: { handleAccept: () => void, handleRoleChange: (role: Role) => void }) => { const TermsAndConditionsCard = ({ handleAccept, handleRoleChange }: { handleAccept: () => void, handleRoleChange: (role: Role) => void }) => {
const [selectedRole, setSelectedRole] = useState<Role>(Role.Participant); const [selectedRole, setSelectedRole] = useState(PARTICIPANT_OPTION);
const [checked, setChecked] = useState(false); const [checked, setChecked] = useState(false);
const [isHidden, setIsHidden] = useState(false); const [isHidden, setIsHidden] = useState(false);
@ -26,8 +25,8 @@ const TermsAndConditionsCard = ({ handleAccept, handleRoleChange }: { handleAcce
} }
const handleRadioChange = (event: React.ChangeEvent<HTMLInputElement>) => { const handleRadioChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSelectedRole(event.target.value as Role); setSelectedRole((event.target as HTMLInputElement).value);
handleRoleChange((event.target as HTMLInputElement).value === Role.Validator ? Role.Validator : Role.Participant); handleRoleChange((event.target as HTMLInputElement).value === VALIDATOR_OPTION ? Role.ROLE_VALIDATOR : Role.ROLE_PARTICIPANT);
}; };
return ( return (
@ -41,12 +40,12 @@ const TermsAndConditionsCard = ({ handleAccept, handleRoleChange }: { handleAcce
onChange={handleRadioChange} onChange={handleRadioChange}
> >
<FormControlLabel <FormControlLabel
value={Role.Validator} value={VALIDATOR_OPTION}
control={<Radio />} control={<Radio />}
label="Validator" label="Validator"
/> />
<FormControlLabel <FormControlLabel
value={Role.Participant} value={PARTICIPANT_OPTION}
control={<Radio />} control={<Radio />}
label="Participant" label="Participant"
/> />
@ -74,7 +73,7 @@ const TermsAndConditionsCard = ({ handleAccept, handleRoleChange }: { handleAcce
Continue Continue
</Button> </Button>
</Box> </Box>
<TermsAndConditionsDialog isValidator = { selectedRole === Role.Validator } open={isDialogOpen} onClose={() => setisDialogOpen(false)}/> <TermsAndConditionsDialog isValidator = { selectedRole === VALIDATOR_OPTION } open={isDialogOpen} onClose={() => setisDialogOpen(false)}/>
</Paper> </Paper>
); );
}; };

View File

@ -8,10 +8,11 @@ import {
MsgOnboardParticipantEncodeObject, MsgOnboardParticipantEncodeObject,
typeUrlMsgOnboardParticipant, typeUrlMsgOnboardParticipant,
} from "@cerc-io/registry-sdk"; } from "@cerc-io/registry-sdk";
import { Role } from "@cerc-io/registry-sdk/dist/proto/cerc/onboarding/v1/onboarding";
import { StargateClient } from "@cosmjs/stargate"; import { StargateClient } from "@cosmjs/stargate";
import { useWalletConnectContext } from "../context/WalletConnectContext"; import { useWalletConnectContext } from "../context/WalletConnectContext";
import TermsAndConditionsCard, {Role} from "../components/TermsAndConditionsCard"; import TermsAndConditionsCard from "../components/TermsAndConditionsCard";
const SignWithCosmos = () => { const SignWithCosmos = () => {
const { session, signClient } = useWalletConnectContext(); const { session, signClient } = useWalletConnectContext();
@ -21,7 +22,7 @@ const SignWithCosmos = () => {
const [balance, setBalance] = useState(''); const [balance, setBalance] = useState('');
const [isRequesting, setIsRequesting] = useState(false); const [isRequesting, setIsRequesting] = useState(false);
const [isTncAccepted, setIsTncAccepted] = useState(false); const [isTncAccepted, setIsTncAccepted] = useState(false);
const [role, setRole] = useState(Role.Participant); const [role, setRole] = useState(Role.ROLE_PARTICIPANT);
const navigate = useNavigate(); const navigate = useNavigate();
const {message: innerMessage, cosmosAddress, ethSignature, kycId} = location.state as { const {message: innerMessage, cosmosAddress, ethSignature, kycId} = location.state as {

View File

@ -1,49 +1,26 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { Box, Typography } from '@mui/material';
import SumsubWebSdk from '@sumsub/websdk-react';
import { fetchToken } from '../utils/getToken'; import { Box, Typography } from '@mui/material'
import SumsubWebSdk from '@sumsub/websdk-react'
const config = { const config = {
lang: "en", // language of WebSDK texts and comments (ISO 639-1 format) lang: "en", //language of WebSDK texts and comments (ISO 639-1 format)
theme: "light", theme: "light",
}; }
const options = { const options = {
addViewportTag: false, addViewportTag: false,
adaptIframeHeight: true, adaptIframeHeight: true
}; }
const UserVerification = () => { const UserVerification = () => {
const [kycId, setKycId] = useState<string>(''); const [kycId, setKycId] = useState<String>('');
const [applicationSubmitted, setApplicationSubmitted] = useState<boolean>(false); const [applicationSubmitted, setApplicationSubmitted] = useState<boolean>(false);
const [token, setToken] = useState<string>('');
const [loading, setLoading] = useState<boolean>(true);
const navigate = useNavigate(); const navigate = useNavigate();
useEffect(() => { useEffect(()=>{
const getToken = async (kycId: string) => {
console.log(kycId);
const newToken = await fetchToken(kycId);
if (newToken) {
console.log('newToken: ', newToken);
setToken(newToken);
} else {
alert("Failed to fetch token");
}
setLoading(false);
};
if (kycId) {
console.log(kycId);
getToken(kycId);
}
}, [kycId]);
useEffect(() => {
if (applicationSubmitted && kycId !== '') { if (applicationSubmitted && kycId !== '') {
navigate("/connect-wallet", { navigate("/connect-wallet", {
state: { state: {
@ -53,18 +30,25 @@ const UserVerification = () => {
} }
}, [applicationSubmitted, kycId, navigate]); }, [applicationSubmitted, kycId, navigate]);
// TODO: Implement
const accessTokenExpirationHandler = async () => { const accessTokenExpirationHandler = async () => {
alert("Please renew token"); alert("Please renew token");
return "Token expired"; return "Token expired";
}; }
const messageHandler = (event: any, payload: any) => { const accessToken = {
console.log(event); // TODO: Programmatically fetch access-token using sumsub API
"token": process.env.REACT_APP_SUMSUB_TOKEN!,
// TODO: Generate random user-id string
"userId": "alice"
}
const messageHandler = (event: any, payload: any ) => {
if (event === 'idCheck.onApplicantLoaded') { if (event === 'idCheck.onApplicantLoaded') {
setKycId(payload.applicantId); setKycId(payload.applicantId);
} }
if (event === 'idCheck.onApplicantSubmitted') { if (event === 'idCheck.onApplicantSubmitted'){
setApplicationSubmitted(true); setApplicationSubmitted(true);
} }
@ -73,7 +57,7 @@ const UserVerification = () => {
setApplicationSubmitted(true); setApplicationSubmitted(true);
} }
} }
}; }
return ( return (
<> <>
@ -86,19 +70,19 @@ const UserVerification = () => {
}} }}
> >
<Typography variant="h5">User verification</Typography> <Typography variant="h5">User verification</Typography>
<div id="sumsub-websdk-container"></div> <div id="sumsub-websdk-container">
</div>
</Box> </Box>
{!loading && token && (
<SumsubWebSdk <SumsubWebSdk
accessToken={token} accessToken={accessToken.token}
expirationHandler={accessTokenExpirationHandler} expirationHandler={accessTokenExpirationHandler}
config={config} config={config}
options={options} options={options}
onMessage={messageHandler} onMessage={messageHandler}
/> />
)}
</> </>
); )
}; }
export default UserVerification; export default UserVerification

View File

@ -1,21 +0,0 @@
export const fetchToken = async (userId: string) => {
try {
const response = await fetch('http://localhost:3000/generate-token', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ userId })
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
return data.token;
} catch (error) {
console.error('Error fetching token:', error);
return null;
}
};