Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit dac96ec

Browse files
authored
fix: add back credential verification (#66)
* fix: add back credential verification * applicationMetadata -> application
1 parent 3d8c29e commit dac96ec

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

src/components/project/components/ProjectSummary/ProjectSummary.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IconLabel } from "@/components/IconLabel";
44
// import { useCredentialverification } from "@/features/checker/hooks";
55
import { ProjectApplicationForManager, ProjectMetadata } from "@/features/checker/services/allo";
66
import { IconType } from "@/primitives/Icon";
7+
import { useCredentialVerification } from "@/hooks/useCredentialVerification";
78

89
export interface ProjectSummaryProps {
910
projectMetadata: ProjectMetadata;
@@ -20,7 +21,7 @@ export const ProjectSummary: React.FC<ProjectSummaryProps> = ({ projectMetadata,
2021
lastUpdated.toString() !== "0" ? lastUpdated : createdAt,
2122
).toLocaleString()}`;
2223

23-
// const { isTwitterVerified, isGithubVerified } = useCredentialverification(application);
24+
const { isTwitterVerified, isGithubVerified } = useCredentialVerification(application);
2425

2526
return (
2627
<div className="flex gap-16">
@@ -32,7 +33,7 @@ export const ProjectSummary: React.FC<ProjectSummaryProps> = ({ projectMetadata,
3233
type="social"
3334
platform="twitter"
3435
link={`https://x.com/${projectTwitter}`}
35-
isVerified={false}
36+
isVerified={isTwitterVerified}
3637
/>
3738
)}
3839
</div>
@@ -58,7 +59,7 @@ export const ProjectSummary: React.FC<ProjectSummaryProps> = ({ projectMetadata,
5859
type="social"
5960
platform="github"
6061
link={`https://github.com/${projectGithub}`}
61-
isVerified={false}
62+
isVerified={isGithubVerified}
6263
/>
6364
)}
6465
</div>

src/features/checker/services/checker/api.ts

+32
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { EvaluationBody } from "../../types";
2+
import { ProjectApplicationForManager } from "../allo";
23
import { CHECKER_ENDPOINT } from "./checkerClient";
34

45
export interface SyncPoolBody {
@@ -59,3 +60,34 @@ export async function syncPool(syncPoolBody: SyncPoolBody): Promise<boolean> {
5960
throw error;
6061
}
6162
}
63+
64+
export async function verifyCredentials(
65+
application: Partial<ProjectApplicationForManager>,
66+
): Promise<{ twitter: boolean; github: boolean }> {
67+
const url = `${CHECKER_ENDPOINT}/api/passport/validate`;
68+
69+
try {
70+
const response = await fetch(url, {
71+
method: "POST",
72+
headers: {
73+
accept: "*/*",
74+
"Content-Type": "application/json",
75+
},
76+
body: JSON.stringify({ application: application }),
77+
});
78+
79+
if (!response.ok) {
80+
const errorData = await response.json();
81+
throw new Error(`Error: ${response.status} - ${errorData.message || "Unknown error"}`);
82+
}
83+
84+
const data = await response.json();
85+
return {
86+
twitter: data.provider.twitter?.isVerified || false,
87+
github: data.provider.github?.isVerified || false,
88+
};
89+
} catch (error) {
90+
console.error("Error verifying credentials:", error);
91+
throw error;
92+
}
93+
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { useState, useEffect } from "react";
2+
3+
import { ProjectApplicationForManager, verifyCredentials } from "@/features/checker";
4+
5+
export function useCredentialVerification(
6+
application: Partial<ProjectApplicationForManager> | undefined,
7+
) {
8+
const [isTwitterVerified, setIsTwitterVerified] = useState<boolean>(false);
9+
const [isGithubVerified, setIsGithubVerified] = useState<boolean>(false);
10+
11+
useEffect(() => {
12+
async function checkVerification() {
13+
if (application) {
14+
try {
15+
const { twitter, github } = await verifyCredentials(application);
16+
setIsTwitterVerified(twitter);
17+
setIsGithubVerified(github);
18+
} catch (error) {
19+
console.error("Failed to verify credentials:", error);
20+
}
21+
}
22+
}
23+
24+
checkVerification();
25+
}, [application]);
26+
27+
return { isTwitterVerified, isGithubVerified };
28+
}

0 commit comments

Comments
 (0)