Integrate sumsub KYC with terms & conditions #6

Merged
nabarun merged 5 commits from deep-stack/testnet-onboarding-app:kyc-integration into main 2024-07-30 08:22:10 +00:00
14 changed files with 173 additions and 93 deletions
Showing only changes of commit 9bd82a0023 - Show all commits

View File

@ -6,4 +6,4 @@ REACT_APP_LACONICD_RPC_ENDPOINT=http://localhost:26657
REACT_APP_LACONICD_DENOM=photon REACT_APP_LACONICD_DENOM=photon
REACT_APP_FAUCET_ENDPOINT=http://localhost:4000 REACT_APP_FAUCET_ENDPOINT=http://localhost:4000
REACT_APP_WALLET_META_URL=http://localhost:3000 REACT_APP_WALLET_META_URL=http://localhost:3000
REACT_APP_SUMSUB_TOKEN= REACT_APP_SUMSUB_API_ENDPOINT=

View File

@ -3,7 +3,7 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@cerc-io/registry-sdk": "^0.2.2", "@cerc-io/registry-sdk": "^0.2.3",
"@cosmjs/stargate": "^0.32.4", "@cosmjs/stargate": "^0.32.4",
"@emotion/react": "^11.11.4", "@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.0", "@emotion/styled": "^11.11.0",

View File

@ -19,13 +19,13 @@ function App() {
<WalletConnectProvider> <WalletConnectProvider>
<Routes> <Routes>
<Route path="/" element={<TermsAndConditions />} /> <Route path="/" element={<TermsAndConditions />} />
<Route path="/connect-wallet" element={<ConnectWallet />} />
<Route element={<SignPageLayout />}>
<Route path="/sign-with-nitro-key" element={<SignWithNitroKey />} />
<Route <Route
path="/user-verification" path="/user-verification"
element={<UserVerification />} element={<UserVerification />}
/> />
<Route path="/connect-wallet" element={<ConnectWallet />} />
<Route element={<SignPageLayout />}>
<Route path="/sign-with-nitro-key" element={<SignWithNitroKey />} />
<Route <Route
path="/sign-with-cosmos" path="/sign-with-cosmos"
element={<SignWithCosmos />} element={<SignWithCosmos />}

View File

@ -1,15 +1,16 @@
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';
const VALIDATOR_OPTION = "validator"; export enum Role {
const PARTICIPANT_OPTION = "participant"; Validator = 'validator',
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(PARTICIPANT_OPTION); const [selectedRole, setSelectedRole] = useState<Role>(Role.Participant);
const [checked, setChecked] = useState(false); const [checked, setChecked] = useState(false);
const [isHidden, setIsHidden] = useState(false); const [isHidden, setIsHidden] = useState(false);
@ -25,8 +26,9 @@ const TermsAndConditionsCard = ({ handleAccept, handleRoleChange }: { handleAcce
} }
const handleRadioChange = (event: React.ChangeEvent<HTMLInputElement>) => { const handleRadioChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSelectedRole((event.target as HTMLInputElement).value); setSelectedRole(event.target.value as Role);
handleRoleChange((event.target as HTMLInputElement).value === VALIDATOR_OPTION ? Role.ROLE_VALIDATOR : Role.ROLE_PARTICIPANT); handleRoleChange((event.target as HTMLInputElement).value === Role.Validator ? Role.Validator : Role.Participant);
setChecked(false);
}; };
return ( return (
@ -40,12 +42,12 @@ const TermsAndConditionsCard = ({ handleAccept, handleRoleChange }: { handleAcce
onChange={handleRadioChange} onChange={handleRadioChange}
> >
<FormControlLabel <FormControlLabel
value={VALIDATOR_OPTION} value={Role.Validator}
control={<Radio />} control={<Radio />}
label="Validator" label="Validator"
/> />
<FormControlLabel <FormControlLabel
value={PARTICIPANT_OPTION} value={Role.Participant}
control={<Radio />} control={<Radio />}
label="Participant" label="Participant"
/> />
@ -73,7 +75,7 @@ const TermsAndConditionsCard = ({ handleAccept, handleRoleChange }: { handleAcce
Continue Continue
</Button> </Button>
</Box> </Box>
<TermsAndConditionsDialog isValidator = { selectedRole === VALIDATOR_OPTION } open={isDialogOpen} onClose={() => setisDialogOpen(false)}/> <TermsAndConditionsDialog isValidator = { selectedRole === Role.Validator } open={isDialogOpen} onClose={() => setisDialogOpen(false)}/>
</Paper> </Paper>
); );
}; };

View File

@ -2,7 +2,7 @@ import React from 'react';
import { Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Button, Typography } from '@mui/material'; import { Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Button, Typography } from '@mui/material';
import { TNC_CONTENT } from '../constants'; import { TNC_PARTICIPANT_CONTENT, TNC_VALIDATOR_CONTENT } from '../constants';
interface TermsDialogProps { interface TermsDialogProps {
isValidator: boolean; isValidator: boolean;
@ -19,7 +19,7 @@ const TermsAndConditionsDialog: React.FC<TermsDialogProps> = ({ isValidator, ope
Onboard as a {isValidator ? "validator" : "participant"} Onboard as a {isValidator ? "validator" : "participant"}
</Typography> </Typography>
<DialogContentText> <DialogContentText>
<div dangerouslySetInnerHTML={{__html: TNC_CONTENT}} /> <div dangerouslySetInnerHTML={{__html: isValidator ? TNC_VALIDATOR_CONTENT : TNC_PARTICIPANT_CONTENT }} />
</DialogContentText> </DialogContentText>
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>

View File

@ -1,4 +1,24 @@
export const TNC_CONTENT = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/> export const TNC_GENERIC_CONTENT = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`;
export const TNC_VALIDATOR_CONTENT = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`;
export const TNC_PARTICIPANT_CONTENT = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>

View File

@ -1,5 +1,5 @@
import React, { useEffect } from "react"; import React, { useEffect } from "react";
import { useLocation, useNavigate } from "react-router-dom"; import {useNavigate } from "react-router-dom";
import { Button, Box, Container } from "@mui/material"; import { Button, Box, Container } from "@mui/material";
@ -10,16 +10,13 @@ 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(`/sign-with-nitro-key?kycId=${kycId}`); navigate("/sign-with-nitro-key");
} }
}, [session, navigate, kycId]); }, [session, navigate,]);
const handler = async () => { const handler = async () => {
await connect(); await connect();

View File

@ -16,8 +16,9 @@ const registry = new Registry(
const OnboardingSuccess = () => { const OnboardingSuccess = () => {
const location = useLocation(); const location = useLocation();
const queryParams = new URLSearchParams(location.search); const { cosmosAddress } = location.state as {
const cosmosAddress = queryParams.get('cosmosAddress'); cosmosAddress?: string
}
const [participant, setParticipant] = useState<Participant>(); const [participant, setParticipant] = useState<Participant>();

View File

@ -8,30 +8,34 @@ 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 from "../components/TermsAndConditionsCard"; import TermsAndConditionsCard, {Role} from "../components/TermsAndConditionsCard";
const SignWithCosmos = () => { const SignWithCosmos = () => {
const { session, signClient } = useWalletConnectContext(); const { session, signClient } = useWalletConnectContext();
const location = useLocation(); const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const cosmosAddress = queryParams.get('cosmosAddress');
const ethSignature = queryParams.get('ethSignature');
const kycId = queryParams.get('kycId');
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 [isTncAccepted, setIsTncAccepted] = useState(false);
const [role, setRole] = useState(Role.ROLE_PARTICIPANT); const [role, setRole] = useState(Role.Participant);
const navigate = useNavigate(); const navigate = useNavigate();
const innerMessage = location.state;
const ethAddress = innerMessage.address; const {message: innerMessage, cosmosAddress, receivedEthSig: ethSignature, kycId} = location.state as {
message?: {
msg: string;
address: string;
};
cosmosAddress?: string;
receivedEthSig?: string;
kycId?: string;
};
const ethAddress = innerMessage!.address;
const createCosmosClient = useCallback(async (endpoint: string) => { const createCosmosClient = useCallback(async (endpoint: string) => {
return await StargateClient.connect(endpoint); return await StargateClient.connect(endpoint);
@ -109,7 +113,11 @@ const SignWithCosmos = () => {
if (responseFromWallet.code !== 0) { if (responseFromWallet.code !== 0) {
enqueueSnackbar("Transaction not sent", { variant: "error" }); enqueueSnackbar("Transaction not sent", { variant: "error" });
} else { } else {
navigate(`/onboarding-success?cosmosAddress=${cosmosAddress}`); navigate("/onboarding-success", {
state: {
cosmosAddress
}
});
} }
} catch (error) { } catch (error) {
console.error(error); console.error(error);
@ -143,7 +151,7 @@ const SignWithCosmos = () => {
gap: "10px", gap: "10px",
}} }}
> >
<Typography variant="h5">Please accept terms and conditions to continue</Typography> <Typography variant="h5" display={`${isTncAccepted ? "none" : "block"}`}>Please accept terms and conditions to continue</Typography>
<TermsAndConditionsCard handleAccept={() => setIsTncAccepted(true)} handleRoleChange={setRole}/> <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>

View File

@ -1,5 +1,5 @@
import React, { useState, useMemo, useEffect } from "react"; import React, { useState, useMemo, useEffect } from "react";
import { useLocation, useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { SnackbarProvider, enqueueSnackbar } from "notistack"; import { SnackbarProvider, enqueueSnackbar } from "notistack";
import canonicalStringify from "canonical-json"; import canonicalStringify from "canonical-json";
@ -15,9 +15,6 @@ import { utf8ToHex } from "@walletconnect/encoding";
import { useWalletConnectContext } from "../context/WalletConnectContext"; import { useWalletConnectContext } from "../context/WalletConnectContext";
const SignWithNitroKey = () => { const SignWithNitroKey = () => {
const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const kycId = queryParams.get('kycId');
const { session, signClient, checkPersistedState } = const { session, signClient, checkPersistedState } =
useWalletConnectContext(); useWalletConnectContext();
@ -59,8 +56,12 @@ const SignWithNitroKey = () => {
}); });
setIsLoading(false) setIsLoading(false)
setEthSignature(ethSignature); setEthSignature(ethSignature);
navigate(`/sign-with-cosmos?cosmosAddress=${cosmosAddress}&ethSignature=${receivedEthSig}&kycId=${kycId}`, { navigate("/user-verification", {
state: message, state: {
message,
cosmosAddress,
receivedEthSig,
},
}); });
} catch (error) { } catch (error) {
console.log("err in signing ", error); console.log("err in signing ", error);
@ -70,7 +71,6 @@ const SignWithNitroKey = () => {
} }
}; };
return ( return (
<div> <div>
{session ? ( {session ? (

View File

@ -3,13 +3,13 @@ import { useNavigate } from 'react-router-dom';
import { Container, Typography, Button, Box, Paper } from '@mui/material'; import { Container, Typography, Button, Box, Paper } from '@mui/material';
import { TNC_CONTENT } from '../constants'; import { TNC_GENERIC_CONTENT } from '../constants';
const TermsAndConditions = () => { const TermsAndConditions = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const handleAccept = () => { const handleAccept = () => {
navigate('/user-verification'); navigate('/connect-wallet');
}; };
return ( return (
@ -26,8 +26,12 @@ const TermsAndConditions = () => {
marginBottom: '1rem', marginBottom: '1rem',
}} }}
> >
<Typography variant="body1" gutterBottom> <Typography
<div dangerouslySetInnerHTML={{__html: TNC_CONTENT}} /> variant="body1"
gutterBottom
component="div"
>
<div dangerouslySetInnerHTML={{__html: TNC_GENERIC_CONTENT}} />
</Typography> </Typography>
</Box> </Box>

View File

@ -1,47 +1,79 @@
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom'; import { useLocation, useNavigate } from 'react-router-dom';
import { Box, Typography } from '@mui/material' import { Box, Typography } from '@mui/material';
import SumsubWebSdk from '@sumsub/websdk-react' import SumsubWebSdk from '@sumsub/websdk-react';
import { MessageHandler } from '@sumsub/websdk';
import { EventPayload } from '@sumsub/websdk/types/types';
import { fetchAccessToken } from '../utils/sumsub';
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>('unknown');
const [applicationSubmitted, setApplicationSubmitted] = useState<boolean>(false); const [applicationSubmitted, setApplicationSubmitted] = useState<boolean>(false);
const [token, setToken] = useState<string>('');
const [loading, setLoading] = useState<boolean>(true);
const location = useLocation();
const navigate = useNavigate(); const navigate = useNavigate();
const {message, cosmosAddress, receivedEthSig} = location.state as {
message?: string;
cosmosAddress?: string;
receivedEthSig?: string;
};
const userId = cosmosAddress;
useEffect(() => {
const getToken = async (userId: string) => {
console.log(userId);
const newToken = await fetchAccessToken(userId);
setToken(newToken);
setLoading(false);
};
if (userId) {
getToken(userId).catch(error => {
console.error(error);
alert("Failed to fetch token");
});
}
}, [userId]);
useEffect(() => { useEffect(() => {
if (applicationSubmitted && kycId !== '') { if (applicationSubmitted && kycId !== '') {
navigate(`/connect-wallet?kycId=${kycId}`) navigate("/sign-with-cosmos", {
state: {
message,
cosmosAddress,
receivedEthSig,
kycId,
}})
} }
}, [applicationSubmitted, kycId, navigate]); }, [applicationSubmitted, kycId, navigate, cosmosAddress, message, receivedEthSig]);
// TODO: Implement
const accessTokenExpirationHandler = async () => { const accessTokenExpirationHandler = async () => {
alert("Please renew token"); alert("Please renew token");
return "Token expired"; return "Token expired";
} };
const accessToken = { const messageHandler: MessageHandler = (event, payload) => {
// TODO: Programmatically fetch access-token using sumsub API console.log('sumsubEvent:', event);
"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 as EventPayload<'idCheck.onApplicantLoaded'>).applicantId);
} }
if (event === 'idCheck.onApplicantSubmitted') { if (event === 'idCheck.onApplicantSubmitted') {
@ -49,11 +81,11 @@ const UserVerification = () => {
} }
if (event === 'idCheck.onApplicantStatusChanged') { if (event === 'idCheck.onApplicantStatusChanged') {
if (payload.reviewStatus === 'pending') { if ((payload as EventPayload<'idCheck.onApplicantStatusChanged'>).reviewStatus === 'pending') {
setApplicationSubmitted(true); setApplicationSubmitted(true);
} }
} }
} };
return ( return (
<> <>
@ -66,19 +98,19 @@ const UserVerification = () => {
}} }}
> >
<Typography variant="h5">User verification</Typography> <Typography variant="h5">User verification</Typography>
<div id="sumsub-websdk-container"> <div id="sumsub-websdk-container"></div>
</div>
</Box> </Box>
{!loading && token && (
<SumsubWebSdk <SumsubWebSdk
accessToken={accessToken.token} accessToken={token}
expirationHandler={accessTokenExpirationHandler} expirationHandler={accessTokenExpirationHandler}
config={config} config={config}
options={options} options={options}
onMessage={messageHandler} onMessage={messageHandler}
/> />
)}
</> </>
) );
} };
export default UserVerification export default UserVerification;

16
src/utils/sumsub.ts Normal file
View File

@ -0,0 +1,16 @@
export const fetchAccessToken = async (userId: string): Promise<string> => {
const response = await fetch(`${process.env.REACT_APP_SUMSUB_API_ENDPOINT}/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;
};

View File

@ -1183,10 +1183,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@cerc-io/registry-sdk@^0.2.2": "@cerc-io/registry-sdk@^0.2.3":
version "0.2.2" version "0.2.3"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fregistry-sdk/-/0.2.2/registry-sdk-0.2.2.tgz#2e8a533f069b4bb9f4cd4798e783f52e29167d0d" resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fregistry-sdk/-/0.2.3/registry-sdk-0.2.3.tgz#73e955b4d49d7c97eea40c351bbc21f98bb330f9"
integrity sha512-ocRMbWtdewOg02ORfK1U+qbTqB46anHP4ApXokGkY4d+mFSApR3sdUEi2geHcs8oh+SG8YAp7LUJ9AAJneNY8g== integrity sha512-8fXRdyiTXn8WsJ8r3DCSBYzUBNEZYPPk5JGUrEmkGQhKOJr+ZeakN+2t6HrqEVB9IMYTJK9BtVLPA0KlaXILYA==
dependencies: dependencies:
"@cosmjs/amino" "^0.28.1" "@cosmjs/amino" "^0.28.1"
"@cosmjs/crypto" "^0.28.1" "@cosmjs/crypto" "^0.28.1"