Pass kycId in cosmos message

This commit is contained in:
Shreerang Kale 2024-07-25 18:34:44 +05:30
parent 723d51db0d
commit f1fea8e6f8
5 changed files with 29 additions and 19 deletions

View File

@ -25,13 +25,13 @@ function App() {
/> />
<Route path="/connect-wallet" element={<ConnectWallet />} /> <Route path="/connect-wallet" element={<ConnectWallet />} />
<Route element={<SignPageLayout />}> <Route element={<SignPageLayout />}>
<Route path="/sign-with-nitro-key/:userId" element={<SignWithNitroKey />} /> <Route path="/sign-with-nitro-key" element={<SignWithNitroKey />} />
<Route <Route
path="/sign-with-cosmos/:cosmosAddress/:ethSignature" path="/sign-with-cosmos"
element={<SignWithCosmos />} element={<SignWithCosmos />}
/> />
<Route <Route
path="/onboarding-success/:cosmosAddress" path="/onboarding-success"
element={<OnboardingSuccess />} element={<OnboardingSuccess />}
></Route> ></Route>
</Route> </Route>

View File

@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { SnackbarProvider, enqueueSnackbar } from "notistack"; import { SnackbarProvider, enqueueSnackbar } from "notistack";
import { useParams } from "react-router-dom"; import { useLocation } from "react-router-dom";
import { Box, Typography } from "@mui/material"; import { Box, Typography } from "@mui/material";
import { Registry } from "@cerc-io/registry-sdk"; import { Registry } from "@cerc-io/registry-sdk";
@ -15,7 +15,9 @@ const registry = new Registry(
); );
const OnboardingSuccess = () => { const OnboardingSuccess = () => {
const { cosmosAddress } = useParams(); const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const cosmosAddress = queryParams.get('cosmosAddress');
const [participant, setParticipant] = useState<Participant>(); const [participant, setParticipant] = useState<Participant>();

View File

@ -1,5 +1,5 @@
import React, { useCallback, useEffect, useMemo, useState } from "react"; import React, { useCallback, useEffect, useMemo, useState } from "react";
import { useParams, useLocation, useNavigate } from "react-router-dom"; import { useLocation, useNavigate } from "react-router-dom";
import { SnackbarProvider, enqueueSnackbar } from "notistack"; import { SnackbarProvider, enqueueSnackbar } from "notistack";
import { Box, Card, CardContent, Grid, Typography } from "@mui/material"; import { Box, Card, CardContent, Grid, Typography } from "@mui/material";
@ -15,14 +15,17 @@ import { useWalletConnectContext } from "../context/WalletConnectContext";
const SignWithCosmos = () => { const SignWithCosmos = () => {
const { session, signClient } = useWalletConnectContext(); const { session, signClient } = useWalletConnectContext();
const { cosmosAddress, ethSignature } = useParams(); 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 navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation();
const innerMessage = location.state; const innerMessage = location.state;
const ethAddress = innerMessage.address; const ethAddress = innerMessage.address;
@ -35,12 +38,13 @@ const SignWithCosmos = () => {
return { return {
typeUrl: typeUrlMsgOnboardParticipant, typeUrl: typeUrlMsgOnboardParticipant,
value: { value: {
participant: cosmosAddress, participant: cosmosAddress!,
ethPayload: innerMessage, ethPayload: innerMessage,
ethSignature, ethSignature: ethSignature!,
kycId: kycId
}, },
}; };
}, [cosmosAddress, innerMessage, ethSignature]); }, [cosmosAddress, innerMessage, ethSignature, kycId]);
const handleTokenRequest = async () => { const handleTokenRequest = async () => {
try { try {
@ -100,7 +104,7 @@ 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}`); navigate(`/onboarding-success?cosmosAddress=${cosmosAddress}`);
} }
} catch (error) { } catch (error) {
console.error(error); console.error(error);

View File

@ -1,5 +1,5 @@
import React, { useState, useMemo, useEffect } from "react"; import React, { useState, useMemo, useEffect } from "react";
import { useNavigate } from "react-router-dom"; import { useLocation, 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,6 +15,10 @@ 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();
@ -55,7 +59,7 @@ const SignWithNitroKey = () => {
}); });
setIsLoading(false) setIsLoading(false)
setEthSignature(ethSignature); setEthSignature(ethSignature);
navigate(`/sign-with-cosmos/${cosmosAddress}/${receivedEthSig}`, { navigate(`/sign-with-cosmos?cosmosAddress=${cosmosAddress}&ethSignature=${receivedEthSig}&kycId=${kycId}`, {
state: message, state: message,
}); });
} catch (error) { } catch (error) {

View File

@ -15,16 +15,16 @@ const options = {
} }
const UserVerification = () => { const UserVerification = () => {
const [userId, setUserId] = useState<String>(''); const [kycId, setKycId] = useState<String>('');
const [applicationSubmitted, setApplicationSubmitted] = useState<boolean>(false); const [applicationSubmitted, setApplicationSubmitted] = useState<boolean>(false);
const navigate = useNavigate(); const navigate = useNavigate();
useEffect(()=>{ useEffect(()=>{
if (applicationSubmitted && userId !== '') { if (applicationSubmitted && kycId !== '') {
navigate(`/sign-with-nitro-key/${userId}`) navigate(`/sign-with-nitro-key?kycId=${kycId}`)
} }
}, [applicationSubmitted, userId, navigate]); }, [applicationSubmitted, kycId, navigate]);
// TODO: Implement // TODO: Implement
const accessTokenExpirationHandler = async () => { const accessTokenExpirationHandler = async () => {
@ -41,7 +41,7 @@ const UserVerification = () => {
const messageHandler = (event: any, payload: any ) => { const messageHandler = (event: any, payload: any ) => {
if (event === 'idCheck.onApplicantLoaded') { if (event === 'idCheck.onApplicantLoaded') {
setUserId(payload.applicantId); setKycId(payload.applicantId);
} }
if (event === 'idCheck.onApplicantSubmitted'){ if (event === 'idCheck.onApplicantSubmitted'){