From 896ab93952c8b005397e55ec7857ad9396e8ba24 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Thu, 25 Jul 2024 18:34:44 +0530 Subject: [PATCH] Pass kycId in cosmos message --- src/App.tsx | 6 +++--- src/pages/OnboardingSuccess.tsx | 6 ++++-- src/pages/SignWithCosmos.tsx | 18 +++++++++++------- src/pages/SignWithNitroKey.tsx | 8 ++++++-- src/pages/UserVerification.tsx | 10 +++++----- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 72ce01f..af3f1ed 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -25,13 +25,13 @@ function App() { /> } /> }> - } /> + } /> } /> } > diff --git a/src/pages/OnboardingSuccess.tsx b/src/pages/OnboardingSuccess.tsx index 72b24e5..051a65b 100644 --- a/src/pages/OnboardingSuccess.tsx +++ b/src/pages/OnboardingSuccess.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from "react"; import { SnackbarProvider, enqueueSnackbar } from "notistack"; -import { useParams } from "react-router-dom"; +import { useLocation } from "react-router-dom"; import { Box, Typography } from "@mui/material"; import { Registry } from "@cerc-io/registry-sdk"; @@ -15,7 +15,9 @@ const registry = new Registry( ); const OnboardingSuccess = () => { - const { cosmosAddress } = useParams(); + const location = useLocation(); + const queryParams = new URLSearchParams(location.search); + const cosmosAddress = queryParams.get('cosmosAddress'); const [participant, setParticipant] = useState(); diff --git a/src/pages/SignWithCosmos.tsx b/src/pages/SignWithCosmos.tsx index bb8f44b..ba59956 100644 --- a/src/pages/SignWithCosmos.tsx +++ b/src/pages/SignWithCosmos.tsx @@ -1,5 +1,5 @@ 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 { Box, Card, CardContent, Grid, Typography } from "@mui/material"; @@ -15,14 +15,17 @@ import { useWalletConnectContext } from "../context/WalletConnectContext"; const SignWithCosmos = () => { 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 [balance, setBalance] = useState(''); const [isRequesting, setIsRequesting] = useState(false); const navigate = useNavigate(); - const location = useLocation(); const innerMessage = location.state; const ethAddress = innerMessage.address; @@ -35,12 +38,13 @@ const SignWithCosmos = () => { return { typeUrl: typeUrlMsgOnboardParticipant, value: { - participant: cosmosAddress, + participant: cosmosAddress!, ethPayload: innerMessage, - ethSignature, + ethSignature: ethSignature!, + kycId: kycId }, }; - }, [cosmosAddress, innerMessage, ethSignature]); + }, [cosmosAddress, innerMessage, ethSignature, kycId]); const handleTokenRequest = async () => { try { @@ -100,7 +104,7 @@ const SignWithCosmos = () => { if (responseFromWallet.code !== 0) { enqueueSnackbar("Transaction not sent", { variant: "error" }); } else { - navigate(`/onboarding-success/${cosmosAddress}`); + navigate(`/onboarding-success?cosmosAddress=${cosmosAddress}`); } } catch (error) { console.error(error); diff --git a/src/pages/SignWithNitroKey.tsx b/src/pages/SignWithNitroKey.tsx index 038fda2..08bff6d 100644 --- a/src/pages/SignWithNitroKey.tsx +++ b/src/pages/SignWithNitroKey.tsx @@ -1,5 +1,5 @@ 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 canonicalStringify from "canonical-json"; @@ -15,6 +15,10 @@ import { utf8ToHex } from "@walletconnect/encoding"; import { useWalletConnectContext } from "../context/WalletConnectContext"; const SignWithNitroKey = () => { + const location = useLocation(); + const queryParams = new URLSearchParams(location.search); + const kycId = queryParams.get('kycId'); + const { session, signClient, checkPersistedState } = useWalletConnectContext(); @@ -55,7 +59,7 @@ const SignWithNitroKey = () => { }); setIsLoading(false) setEthSignature(ethSignature); - navigate(`/sign-with-cosmos/${cosmosAddress}/${receivedEthSig}`, { + navigate(`/sign-with-cosmos?cosmosAddress=${cosmosAddress}ðSignature=${receivedEthSig}&kycId=${kycId}`, { state: message, }); } catch (error) { diff --git a/src/pages/UserVerification.tsx b/src/pages/UserVerification.tsx index 6e8a015..7baa173 100644 --- a/src/pages/UserVerification.tsx +++ b/src/pages/UserVerification.tsx @@ -15,16 +15,16 @@ const options = { } const UserVerification = () => { - const [userId, setUserId] = useState(''); + const [kycId, setKycId] = useState(''); const [applicationSubmitted, setApplicationSubmitted] = useState(false); const navigate = useNavigate(); useEffect(()=>{ - if (applicationSubmitted && userId !== '') { - navigate(`/sign-with-nitro-key/${userId}`) + if (applicationSubmitted && kycId !== '') { + navigate(`/sign-with-nitro-key?kycId=${kycId}`) } - }, [applicationSubmitted, userId, navigate]); + }, [applicationSubmitted, kycId, navigate]); // TODO: Implement const accessTokenExpirationHandler = async () => { @@ -41,7 +41,7 @@ const UserVerification = () => { const messageHandler = (event: any, payload: any ) => { if (event === 'idCheck.onApplicantLoaded') { - setUserId(payload.applicantId); + setKycId(payload.applicantId); } if (event === 'idCheck.onApplicantSubmitted'){