diff --git a/pages/api/v1/verification/index.ts b/pages/api/v1/verification/index.ts index 88d483690f..d292707d17 100644 --- a/pages/api/v1/verification/index.ts +++ b/pages/api/v1/verification/index.ts @@ -70,39 +70,41 @@ const handler: NextApiHandler = async (req, return res.status(200).json({ message: VerificationStatus.VERFICATION_EMAIL_SENT }); } } - if (checkingVerified === true) return res.status(200).json({ message: VerificationStatus.NOT_VERIFIED }); - - const message = { - from: FROM.email, - html: `Hello ${user.username}, -
Click on the following link to complete email verification for your on chain identity: Verify Email
-
-
- Thank you, -
-
- Polkassembly Team -
`, - subject: 'Email Verification', - to: account - }; - await sgMail - .send(message) - .then(() => { - res.status(200).json({ message: VerificationStatus.VERFICATION_EMAIL_SENT }); - }) - .catch((error: any) => { - return res.status(500).json({ message: error || 'Error sending email' }); + if (checkingVerified === true) { + return res.status(200).json({ message: VerificationStatus.NOT_VERIFIED }); + } else { + const message = { + from: FROM.email, + html: `Hello ${user.username}, +
Click on the following link to complete email verification for your on chain identity: Verify Email
+
+
+ Thank you, +
+
+ Polkassembly Team +
`, + subject: 'Email Verification', + to: account + }; + await sgMail + .send(message) + .then(() => { + res.status(200).json({ message: VerificationStatus.VERFICATION_EMAIL_SENT }); + }) + .catch((error: any) => { + return res.status(500).json({ message: error || 'Error sending email' }); + }); + await tokenVerificationRef.set({ + created_at: new Date(), + email: account, + status: VerificationStatus.VERFICATION_EMAIL_SENT, + token: verificationToken, + user_id: userId, + verified: false }); - await tokenVerificationRef.set({ - created_at: new Date(), - email: account, - status: VerificationStatus.VERFICATION_EMAIL_SENT, - token: verificationToken, - user_id: userId, - verified: false - }); - return res.status(200).json({ message: VerificationStatus.VERFICATION_EMAIL_SENT }); + return res.status(200).json({ message: VerificationStatus.VERFICATION_EMAIL_SENT }); + } } else if (type === 'twitter') { const twitterVerificationDoc = await firestore.collection('twitter_verification_tokens').doc(String(userId)).get(); diff --git a/src/components/AppLayout/index.tsx b/src/components/AppLayout/index.tsx index d0aa309981..bde494be71 100644 --- a/src/components/AppLayout/index.tsx +++ b/src/components/AppLayout/index.tsx @@ -181,7 +181,7 @@ const getUserDropDown = ( {isGood && !isIdentityUnverified && ( )} diff --git a/src/components/OnchainIdentity/SocialVerification.tsx b/src/components/OnchainIdentity/SocialVerification.tsx index 3b9acfd763..72aed92d8b 100644 --- a/src/components/OnchainIdentity/SocialVerification.tsx +++ b/src/components/OnchainIdentity/SocialVerification.tsx @@ -14,6 +14,7 @@ import BN from 'bn.js'; import { useEffect, useState } from 'react'; import InprogressState from './InprogressState'; import VerifiedTick from '~assets/icons/verified-tick.svg'; +import { useRouter } from 'next/router'; interface Props { className?: string; @@ -90,6 +91,7 @@ const SocialVerification = ({ className, socials, onCancel, setLoading, closeMod const [status, setStatus] = useState({ email: '', twitter: '' }); const [fieldLoading, setFieldLoading] = useState<{ twitter: boolean; email: boolean }>({ email: false, twitter: false }); const [twitterVerificationStart, setTwitterVerificationStart] = useState(false); + const router = useRouter(); const items: TimelineItemProps[] = []; @@ -136,7 +138,7 @@ const SocialVerification = ({ className, socials, onCancel, setLoading, closeMod key: 2 }); } - const handleLocalStorageSave = (field: any) => { + const handleLocalStorageSave = (field: any, socialsChanging?: boolean) => { let data: any = localStorage.getItem('identityForm'); if (data) { data = JSON.parse(data); @@ -148,22 +150,21 @@ const SocialVerification = ({ className, socials, onCancel, setLoading, closeMod ...field }) ); - setSocials({ - ...socials, - email: { ...email, ...data?.email }, - twitter: { ...twitter, ...data?.twitter } - }); + socialsChanging && + setSocials({ + ...socials, + email: { ...email, ...data?.email }, + twitter: { ...twitter, ...data?.twitter } + }); }; const handleSetStates = (fieldName: ESocials, verified: boolean, verificationStatus: VerificationStatus, noStatusUpdate?: boolean) => { if (ESocials.EMAIL === fieldName) { - setSocials({ ...socials, email: { ...email, verified } }); !noStatusUpdate && setStatus({ ...status, email: verificationStatus }); - handleLocalStorageSave({ email: { ...email, verified } }); + handleLocalStorageSave({ email: { ...email, verified } }, true); } else { - setSocials({ ...socials, twitter: { ...twitter, verified } }); !noStatusUpdate && setStatus({ ...status, twitter: verificationStatus }); - handleLocalStorageSave({ twitter: { ...twitter, verified } }); + handleLocalStorageSave({ twitter: { ...twitter, verified } }, true); } }; @@ -254,6 +255,7 @@ const SocialVerification = ({ className, socials, onCancel, setLoading, closeMod setLoading(false); setOpenSuccessModal(true); closeModal(true); + router.replace('/'); } else if (error) { queueNotification({ header: 'Error!', diff --git a/src/ui-components/Address.tsx b/src/ui-components/Address.tsx index fde0383b40..6237ab4a1e 100644 --- a/src/ui-components/Address.tsx +++ b/src/ui-components/Address.tsx @@ -302,7 +302,7 @@ const Address = ({ )} {t1 && {t1}} {sub && isSubVisible && {sub}}