From 0f262dea5a97ca02f656b506f9d89338907fb831 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Fri, 9 Aug 2024 11:03:25 +0530 Subject: [PATCH] Overwrite subscriber ID in thanks page --- src/constants.ts | 6 ++++-- src/pages/ConnectWallet.tsx | 4 +++- src/pages/OnboardingSuccess.tsx | 4 ++-- src/pages/SignWithCosmos.tsx | 3 ++- src/pages/SignWithNitroKey.tsx | 14 ++++++-------- src/pages/Thanks.tsx | 8 ++------ src/pages/UserVerification.tsx | 2 +- 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index ccceafc..8df2b99 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,5 +1,7 @@ -export const WALLET_DISCLAIMER_MSG = 'You are connecting to an experimental wallet! It is not secure. Do not use it elsewhere and/or for managing real assets.' +export const WALLET_DISCLAIMER_MSG = 'You are connecting to an experimental wallet! It is not secure. Do not use it elsewhere and/or for managing real assets.'; -export const REDIRECT_EMAIL_MSG = 'Close this tab and the confirmation link in your email will bring you back to the onboarding app.' +export const REDIRECT_EMAIL_MSG = 'Close this tab and the confirmation link in your email will bring you back to the onboarding app.'; export const ENABLE_KYC = false; + +export const SUBSCRIBER_ID_HASH_KEY = 'subscriberIdHash'; diff --git a/src/pages/ConnectWallet.tsx b/src/pages/ConnectWallet.tsx index 1550f77..a0a83dd 100644 --- a/src/pages/ConnectWallet.tsx +++ b/src/pages/ConnectWallet.tsx @@ -15,7 +15,9 @@ const ConnectWallet = () => { useEffect(() => { if (session) { - navigate("/sign-with-nitro-key"); + navigate("/sign-with-nitro-key", { + state: location.state + }); } }, [session, navigate, location]); diff --git a/src/pages/OnboardingSuccess.tsx b/src/pages/OnboardingSuccess.tsx index 129d724..689b3be 100644 --- a/src/pages/OnboardingSuccess.tsx +++ b/src/pages/OnboardingSuccess.tsx @@ -8,7 +8,7 @@ import SumsubWebSdk from "@sumsub/websdk-react"; import { MessageHandler } from "@sumsub/websdk"; import { config, fetchAccessToken, getAccessTokenExpirationHandler, options } from "../utils/sumsub"; -import { ENABLE_KYC } from "../constants"; +import { ENABLE_KYC, SUBSCRIBER_ID_HASH_KEY } from "../constants"; interface Participant { cosmosAddress: string; @@ -48,7 +48,7 @@ const OnboardingSuccess = () => { return; } - localStorage.removeItem('subscriberIdHash'); + localStorage.removeItem(SUBSCRIBER_ID_HASH_KEY); setParticipant(participant); } catch (error) { diff --git a/src/pages/SignWithCosmos.tsx b/src/pages/SignWithCosmos.tsx index 24f279e..c5db0a2 100644 --- a/src/pages/SignWithCosmos.tsx +++ b/src/pages/SignWithCosmos.tsx @@ -12,6 +12,7 @@ import { StargateClient } from "@cosmjs/stargate"; import { useWalletConnectContext } from "../context/WalletConnectContext"; import SelectRoleCard, {Role} from "../components/SelectRoleCard"; +import { SUBSCRIBER_ID_HASH_KEY } from "../constants"; const SignWithCosmos = () => { const { session, signClient } = useWalletConnectContext(); @@ -35,7 +36,7 @@ const SignWithCosmos = () => { }; const ethAddress = innerMessage!.address; - const subscriberIdHash = localStorage.getItem('subscriberIdHash'); + const subscriberIdHash = localStorage.getItem(SUBSCRIBER_ID_HASH_KEY); const createCosmosClient = useCallback(async (endpoint: string) => { return await StargateClient.connect(endpoint); diff --git a/src/pages/SignWithNitroKey.tsx b/src/pages/SignWithNitroKey.tsx index eb92c55..63718dc 100644 --- a/src/pages/SignWithNitroKey.tsx +++ b/src/pages/SignWithNitroKey.tsx @@ -13,7 +13,7 @@ import LoadingButton from '@mui/lab/LoadingButton'; import { utf8ToHex } from "@walletconnect/encoding"; import { useWalletConnectContext } from "../context/WalletConnectContext"; -import { ENABLE_KYC } from "../constants"; +import { ENABLE_KYC, SUBSCRIBER_ID_HASH_KEY } from "../constants"; const SignWithNitroKey = () => { @@ -34,14 +34,12 @@ const SignWithNitroKey = () => { const [isLoading, setIsLoading] = useState(false); - const subscriberIdHash = localStorage.getItem('subscriberIdHash'); + const subscriberIdHash = localStorage.getItem(SUBSCRIBER_ID_HASH_KEY); - useEffect(()=>{ - if(!subscriberIdHash){ - setIsLoading(false) - enqueueSnackbar("Subscriber ID not found. Please verify your email and try again", { variant: "error" }); - } - }, [subscriberIdHash]) + if(!subscriberIdHash){ + setIsLoading(false) + enqueueSnackbar("Subscriber ID not found. Please verify your email and try again", { variant: "error" }); + } const message = useMemo(() => { return { diff --git a/src/pages/Thanks.tsx b/src/pages/Thanks.tsx index 983e89f..51debcc 100644 --- a/src/pages/Thanks.tsx +++ b/src/pages/Thanks.tsx @@ -4,6 +4,7 @@ import { jwtDecode } from "jwt-decode"; import { ethers } from 'ethers'; import { Box, colors, Typography } from '@mui/material'; +import { SUBSCRIBER_ID_HASH_KEY } from '../constants'; interface JwtPayload { subscriber_id: string; @@ -19,11 +20,6 @@ const Thanks: React.FC = () => { const [err, setErr] = useState(); useEffect(() => { - const localSubscriberIdHash = localStorage.getItem('localSubscriberIdHash'); - if(localSubscriberIdHash){ - navigate('/connect-wallet'); - } - const queryParams = new URLSearchParams(location.search); const token = queryParams.get('jwt_token'); @@ -46,7 +42,7 @@ const Thanks: React.FC = () => { const subscriberIdBytes = ethers.utils.toUtf8Bytes(decoded.subscriber_id); const subscriberIdHash = ethers.utils.sha256(subscriberIdBytes); - localStorage.setItem('subscriberIdHash', subscriberIdHash); + localStorage.setItem(SUBSCRIBER_ID_HASH_KEY, subscriberIdHash); navigate('/connect-wallet'); } catch (error) { diff --git a/src/pages/UserVerification.tsx b/src/pages/UserVerification.tsx index 4354c3a..0d858e8 100644 --- a/src/pages/UserVerification.tsx +++ b/src/pages/UserVerification.tsx @@ -45,13 +45,13 @@ const UserVerification = () => { useEffect(() => { if (applicationSubmitted && kycId !== '') { const kycIdHash = ethers.utils.sha256(ethers.utils.toUtf8Bytes(kycId)); - localStorage.setItem('subscriberIdHash', kycIdHash); navigate("/sign-with-cosmos", { state: { message, cosmosAddress, receivedEthSig, + kycIdHash }}) } }, [applicationSubmitted, kycId, navigate, cosmosAddress, message, receivedEthSig]);