From 903c545f3116a56bf4367e7e226b04d225135814 Mon Sep 17 00:00:00 2001 From: 4rjunc Date: Sun, 27 Oct 2024 16:59:20 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=A9=20added=20username=20verification?= =?UTF-8?q?=20for=20instagram?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Reclaim.tsx | 53 +++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/src/components/Reclaim.tsx b/src/components/Reclaim.tsx index 1784358..ef05c4c 100644 --- a/src/components/Reclaim.tsx +++ b/src/components/Reclaim.tsx @@ -1,6 +1,6 @@ // @ts-nocheck -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { ReclaimProofRequest } from "@reclaimprotocol/js-sdk"; import { CheckCircle, Copy, Music, Loader2 } from "lucide-react"; import { FaXTwitter } from "react-icons/fa6"; @@ -39,6 +39,8 @@ function ReclaimDemo({ onProofReceived }: SocialMedia) { const [status, setStatus] = useState(""); const [isLoading, setIsLoading] = useState(false); const [copied, setCopied] = useState(false); + const [profileLink, setProfileLink] = useState(""); // New state for profile link + const [verified, setVerified] = useState(false); const handleSocialChange = (e: React.ChangeEvent) => { setSocial(e.target.value); @@ -47,6 +49,10 @@ function ReclaimDemo({ onProofReceived }: SocialMedia) { setStatus(""); }; + const handleProfileLinkChange = (e: React.ChangeEvent) => { + setProfileLink(e.target.value); + }; + const setup = async () => { try { setIsLoading(true); @@ -66,10 +72,12 @@ function ReclaimDemo({ onProofReceived }: SocialMedia) { const url = await reclaimProofRequest.getRequestUrl(); setRequestUrl(url); setStatus("Ready for verification"); + console.log("Verification Started"); await reclaimProofRequest.startSession({ onSuccess: (proofs: any) => { setProofs(proofs); + console.log("Verification Session Started"); onProofReceived(proofs); setStatus("Verification successful!"); }, @@ -79,7 +87,7 @@ function ReclaimDemo({ onProofReceived }: SocialMedia) { }, }); } catch (error: any) { - setStatus("Setup failed"); + setStatus("Setup failed", error); } finally { setIsLoading(false); } @@ -93,6 +101,28 @@ function ReclaimDemo({ onProofReceived }: SocialMedia) { } }; + // Automatically verify username from profile link + useEffect(() => { + const verifyUsername = () => { + const usernameFromLink = profileLink.split("/").pop(); + + if (proofs && proofs.claimData) { + // Check if proofs and claimData exist + const parameters = JSON.parse(proofs.claimData.parameters); + const extractedUsername = parameters.paramValues.username; + + if (extractedUsername === usernameFromLink) { + console.log("Username verified successfully!"); + setVerified(true); + } else { + console.log("Username verification failed"); + setVerified(false); + } + } + }; + verifyUsername(); + }, [proofs, profileLink]); + return (
{/* Header */} @@ -101,11 +131,22 @@ function ReclaimDemo({ onProofReceived }: SocialMedia) {
Social Verification
-

- Verify your social media accounts -

+

Verify social media accounts

+ {/* Profile Link Input */} +
+ + +
{/* Platform Selector - Updated */}
)} {/* Success State */} - {proofs && ( + {verified && (