From 65641996a9489bb550b3a5db6e2620c430a9eb2f Mon Sep 17 00:00:00 2001 From: 0xKurt Date: Fri, 29 Nov 2024 10:43:25 +0100 Subject: [PATCH 1/2] fix: add back credential verification --- .../ProjectSummary/ProjectSummary.tsx | 7 ++-- src/features/checker/services/checker/api.ts | 32 +++++++++++++++++++ src/hooks/useCredentialVerification.ts | 28 ++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 src/hooks/useCredentialVerification.ts diff --git a/src/components/project/components/ProjectSummary/ProjectSummary.tsx b/src/components/project/components/ProjectSummary/ProjectSummary.tsx index 99add45a..07f8819e 100644 --- a/src/components/project/components/ProjectSummary/ProjectSummary.tsx +++ b/src/components/project/components/ProjectSummary/ProjectSummary.tsx @@ -4,6 +4,7 @@ import { IconLabel } from "@/components/IconLabel"; // import { useCredentialverification } from "@/features/checker/hooks"; import { ProjectApplicationForManager, ProjectMetadata } from "@/features/checker/services/allo"; import { IconType } from "@/primitives/Icon"; +import { useCredentialVerification } from "@/hooks/useCredentialVerification"; export interface ProjectSummaryProps { projectMetadata: ProjectMetadata; @@ -20,7 +21,7 @@ export const ProjectSummary: React.FC = ({ projectMetadata, lastUpdated.toString() !== "0" ? lastUpdated : createdAt, ).toLocaleString()}`; - // const { isTwitterVerified, isGithubVerified } = useCredentialverification(application); + const { isTwitterVerified, isGithubVerified } = useCredentialVerification(application); return (
@@ -32,7 +33,7 @@ export const ProjectSummary: React.FC = ({ projectMetadata, type="social" platform="twitter" link={`https://x.com/${projectTwitter}`} - isVerified={false} + isVerified={isTwitterVerified} /> )}
@@ -58,7 +59,7 @@ export const ProjectSummary: React.FC = ({ projectMetadata, type="social" platform="github" link={`https://github.com/${projectGithub}`} - isVerified={false} + isVerified={isGithubVerified} /> )} diff --git a/src/features/checker/services/checker/api.ts b/src/features/checker/services/checker/api.ts index 2e530a65..c1fddba3 100644 --- a/src/features/checker/services/checker/api.ts +++ b/src/features/checker/services/checker/api.ts @@ -1,4 +1,5 @@ import { EvaluationBody } from "../../types"; +import { ProjectApplicationForManager } from "../allo"; import { CHECKER_ENDPOINT } from "./checkerClient"; export interface SyncPoolBody { @@ -59,3 +60,34 @@ export async function syncPool(syncPoolBody: SyncPoolBody): Promise { throw error; } } + +export async function verifyCredentials( + applicationMetadata: Partial, +): Promise<{ twitter: boolean; github: boolean }> { + const url = `${CHECKER_ENDPOINT}/api/passport/validate`; + + try { + const response = await fetch(url, { + method: "POST", + headers: { + accept: "*/*", + "Content-Type": "application/json", + }, + body: JSON.stringify({ application: applicationMetadata }), + }); + + if (!response.ok) { + const errorData = await response.json(); + throw new Error(`Error: ${response.status} - ${errorData.message || "Unknown error"}`); + } + + const data = await response.json(); + return { + twitter: data.provider.twitter?.isVerified || false, + github: data.provider.github?.isVerified || false, + }; + } catch (error) { + console.error("Error verifying credentials:", error); + throw error; + } +} diff --git a/src/hooks/useCredentialVerification.ts b/src/hooks/useCredentialVerification.ts new file mode 100644 index 00000000..95ae3a0f --- /dev/null +++ b/src/hooks/useCredentialVerification.ts @@ -0,0 +1,28 @@ +import { useState, useEffect } from "react"; + +import { ProjectApplicationForManager, verifyCredentials } from "@/features/checker"; + +export function useCredentialVerification( + applicationMetadata: Partial | undefined, +) { + const [isTwitterVerified, setIsTwitterVerified] = useState(false); + const [isGithubVerified, setIsGithubVerified] = useState(false); + + useEffect(() => { + async function checkVerification() { + if (applicationMetadata) { + try { + const { twitter, github } = await verifyCredentials(applicationMetadata); + setIsTwitterVerified(twitter); + setIsGithubVerified(github); + } catch (error) { + console.error("Failed to verify credentials:", error); + } + } + } + + checkVerification(); + }, [applicationMetadata]); + + return { isTwitterVerified, isGithubVerified }; +} From 41fa9ff3011d79adfd7c4c0c1eb2d8200f7eaddd Mon Sep 17 00:00:00 2001 From: 0xKurt Date: Fri, 29 Nov 2024 10:46:54 +0100 Subject: [PATCH 2/2] applicationMetadata -> application --- src/features/checker/services/checker/api.ts | 4 ++-- src/hooks/useCredentialVerification.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/features/checker/services/checker/api.ts b/src/features/checker/services/checker/api.ts index c1fddba3..364010f0 100644 --- a/src/features/checker/services/checker/api.ts +++ b/src/features/checker/services/checker/api.ts @@ -62,7 +62,7 @@ export async function syncPool(syncPoolBody: SyncPoolBody): Promise { } export async function verifyCredentials( - applicationMetadata: Partial, + application: Partial, ): Promise<{ twitter: boolean; github: boolean }> { const url = `${CHECKER_ENDPOINT}/api/passport/validate`; @@ -73,7 +73,7 @@ export async function verifyCredentials( accept: "*/*", "Content-Type": "application/json", }, - body: JSON.stringify({ application: applicationMetadata }), + body: JSON.stringify({ application: application }), }); if (!response.ok) { diff --git a/src/hooks/useCredentialVerification.ts b/src/hooks/useCredentialVerification.ts index 95ae3a0f..fdbe10d9 100644 --- a/src/hooks/useCredentialVerification.ts +++ b/src/hooks/useCredentialVerification.ts @@ -3,16 +3,16 @@ import { useState, useEffect } from "react"; import { ProjectApplicationForManager, verifyCredentials } from "@/features/checker"; export function useCredentialVerification( - applicationMetadata: Partial | undefined, + application: Partial | undefined, ) { const [isTwitterVerified, setIsTwitterVerified] = useState(false); const [isGithubVerified, setIsGithubVerified] = useState(false); useEffect(() => { async function checkVerification() { - if (applicationMetadata) { + if (application) { try { - const { twitter, github } = await verifyCredentials(applicationMetadata); + const { twitter, github } = await verifyCredentials(application); setIsTwitterVerified(twitter); setIsGithubVerified(github); } catch (error) { @@ -22,7 +22,7 @@ export function useCredentialVerification( } checkVerification(); - }, [applicationMetadata]); + }, [application]); return { isTwitterVerified, isGithubVerified }; }