Skip to content

Commit 56c4ec6

Browse files
authored
Merge pull request #50 from Octasol/feat-reclaim-updations
feat: reclaim package updated and proof generations
2 parents dee60e2 + 3ab08c5 commit 56c4ec6

File tree

8 files changed

+219
-124
lines changed

8 files changed

+219
-124
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@radix-ui/react-tabs": "^1.1.1",
2828
"@radix-ui/react-toggle": "^1.1.0",
2929
"@radix-ui/react-tooltip": "^1.1.2",
30-
"@reclaimprotocol/js-sdk": "^1.3.11",
30+
"@reclaimprotocol/js-sdk": "^3.0.2",
3131
"@reduxjs/toolkit": "^2.2.5",
3232
"@tabler/icons-react": "^3.7.0",
3333
"@tiptap/extension-focus": "^2.10.3",

src/config/reclaim/codechef/service.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,30 @@ import { logToDiscord } from "@/utils/logger";
33
import axios from "axios";
44

55
export async function processCodechefData(
6-
githubId: string,
7-
proof: any,
6+
githubId: any,
7+
proofs: any,
88
providerName: string
99
) {
10-
const username = JSON.parse(proof[0].claimData.context).extractedParameters
11-
.URL_PARAMS_GRD;
10+
try {
11+
let username;
1212

13-
const lastUpdateTimeStamp = proof[0].claimData.timestampS;
13+
// Handle different proof structures
14+
if (Array.isArray(proofs)) {
15+
const contextData = JSON.parse(proofs[0]?.claimData?.context || '{}');
16+
username = contextData.extractedParameters?.URL_PARAMS_GRD;
17+
} else if (proofs.claimData && proofs.claimData.context) {
18+
const contextData = JSON.parse(proofs.claimData.context);
19+
username = contextData.extractedParameters?.URL_PARAMS_GRD;
20+
} else {
21+
const extractedParams = proofs?.extractedParameters ||
22+
JSON.parse(proofs?.context || '{}')?.extractedParameters;
23+
username = extractedParams?.URL_PARAMS_GRD;
24+
}
25+
26+
if (!username) {
27+
throw new Error("Could not extract username from proof");
28+
}
1429

15-
try {
1630
const response = await axios.get(
1731
`https://codechef-api.vercel.app/handle/${username}`
1832
);
@@ -25,12 +39,13 @@ export async function processCodechefData(
2539
BigInt(githubId),
2640
response.data.currentRating
2741
);
42+
2843
return true;
2944
} catch (error) {
3045
await logToDiscord(`processCodechefData: ${(error as any).message}`, "ERROR");
3146

3247
console.error(
33-
`Failed to fetch CodeChef data for username: ${username}`,
48+
`Failed to fetch CodeChef data for username`,
3449
error
3550
);
3651
throw new Error("Error fetching CodeChef data");
Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
11
import { setGFGDatabyGithubId, setUsername } from "@/utils/dbUtils";
2+
import { logToDiscord } from "@/utils/logger";
23

34
export async function processGeeksForGeeksData(
4-
githubId: string,
5-
proof: any,
5+
githubId: any,
6+
proofs: any,
67
providerName: string
78
) {
8-
const score = parseInt(JSON.parse(proof[0].claimData.context).extractedParameters
9-
.score);
9+
try {
10+
let username, score, problemsSolved;
1011

11-
const problemsSolved = parseInt(JSON.parse(proof[0].claimData.context)
12-
.extractedParameters.total_problems_solved);
12+
// Handle different proof structures
13+
if (Array.isArray(proofs)) {
14+
const contextData = JSON.parse(proofs[0]?.claimData?.context || '{}');
15+
username = contextData.extractedParameters?.URL_PARAMS_1;
16+
score = parseInt(contextData.extractedParameters?.score);
17+
problemsSolved = parseInt(contextData.extractedParameters?.total_problems_solved);
18+
} else if (proofs.claimData && proofs.claimData.context) {
19+
const contextData = JSON.parse(proofs.claimData.context);
20+
username = contextData.extractedParameters?.URL_PARAMS_1;
21+
score = parseInt(contextData.extractedParameters?.score);
22+
problemsSolved = parseInt(contextData.extractedParameters?.total_problems_solved);
23+
} else {
24+
const extractedParams = proofs?.extractedParameters ||
25+
JSON.parse(proofs?.context || '{}')?.extractedParameters;
26+
username = extractedParams?.URL_PARAMS_1;
27+
score = parseInt(extractedParams?.score);
28+
problemsSolved = parseInt(extractedParams?.total_problems_solved);
29+
}
1330

14-
const username = JSON.parse(proof[0].claimData.context).extractedParameters
15-
.URL_PARAMS_1;
31+
if (!username) {
32+
throw new Error("Could not extract username from proof");
33+
}
1634

17-
const lastUpdateTimeStamp = proof[0].claimData.timestampS;
35+
await setUsername(BigInt(githubId), {
36+
gfgUsername: username,
37+
});
1838

19-
await setUsername(BigInt(githubId), {
20-
gfgUsername: username,
21-
});
22-
await setGFGDatabyGithubId(BigInt(githubId), score, problemsSolved);
23-
return true;
39+
await setGFGDatabyGithubId(BigInt(githubId), score, problemsSolved);
40+
41+
return true;
42+
} catch (error) {
43+
await logToDiscord(`processGeeksForGeeksData: ${(error as any).message}`, "ERROR");
44+
console.error("Error processing GeeksForGeeks proof:", error);
45+
return false;
46+
}
2447
}

src/config/reclaim/hackerrank/service.ts

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,42 @@ import { logToDiscord } from "@/utils/logger";
44

55
export async function processHackerRankData(
66
githubId: any,
7-
proof: any,
7+
proofs: any,
88
providerName: string
99
) {
10-
const username = JSON.parse(proof[0].claimData.context).extractedParameters
11-
.username;
12-
const lastUpdateTimeStamp = proof[0].claimData.timestampS;
13-
await setUsername(githubId, {
14-
hackerrankUsername: username,
15-
});
16-
const { currentPoints, stars } = await getHackerrankStats(username);
17-
await setHackerrankDatabyGithubId(BigInt(githubId), currentPoints, stars);
18-
return true;
10+
try {
11+
let username;
12+
13+
// Handle different proof structures
14+
if (Array.isArray(proofs)) {
15+
const contextData = JSON.parse(proofs[0]?.claimData?.context || '{}');
16+
username = contextData.extractedParameters?.username;
17+
} else if (proofs.claimData && proofs.claimData.context) {
18+
const contextData = JSON.parse(proofs.claimData.context);
19+
username = contextData.extractedParameters?.username;
20+
} else {
21+
const extractedParams = proofs?.extractedParameters ||
22+
JSON.parse(proofs?.context || '{}')?.extractedParameters;
23+
username = extractedParams?.username;
24+
}
25+
26+
if (!username) {
27+
throw new Error("Could not extract username from proof");
28+
}
29+
30+
await setUsername(githubId, {
31+
hackerrankUsername: username,
32+
});
33+
34+
const { currentPoints, stars } = await getHackerrankStats(username);
35+
await setHackerrankDatabyGithubId(BigInt(githubId), currentPoints, stars);
36+
37+
return true;
38+
} catch (error) {
39+
await logToDiscord(`processHackerRankData: ${(error as any).message}`, "ERROR");
40+
console.error("Error processing HackerRank proof:", error);
41+
return false;
42+
}
1943
}
2044

2145
export async function getHackerrankStats(username: string) {

src/config/reclaim/leetcode/service.ts

Lines changed: 64 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,82 @@ import { logToDiscord } from "@/utils/logger";
44

55
export async function processLeetcodeData(
66
githubId: any,
7-
proof: any,
7+
proofs: any,
88
providerName: string
99
) {
10-
const username = JSON.parse(proof[0].claimData.context).extractedParameters
11-
.username;
12-
await setUsername(githubId, {
13-
leetcodeUsername: username,
14-
});
15-
16-
const query = `
17-
query userProfileUserQuestionProgressV2($userSlug: String!) {
18-
userProfileUserQuestionProgressV2(userSlug: $userSlug) {
19-
numAcceptedQuestions {
20-
count
21-
difficulty
22-
}
23-
}
10+
try {
11+
let username;
12+
13+
// Handle different proof structures
14+
if (Array.isArray(proofs)) {
15+
const contextData = JSON.parse(proofs[0]?.claimData?.context || '{}');
16+
username = contextData.extractedParameters?.username;
17+
} else if (proofs.claimData && proofs.claimData.context) {
18+
const contextData = JSON.parse(proofs.claimData.context);
19+
username = contextData.extractedParameters?.username;
20+
} else {
21+
const extractedParams = proofs?.extractedParameters ||
22+
JSON.parse(proofs?.context || '{}')?.extractedParameters;
23+
username = extractedParams?.username;
2424
}
25-
`;
2625

27-
const variables = {
28-
userSlug: username,
29-
};
26+
if (!username) {
27+
throw new Error("Could not extract username from proof");
28+
}
3029

31-
const url = "https://leetcode.com/graphql/";
32-
try {
33-
const response = await fetch(url, {
34-
method: "POST",
35-
headers: {
36-
"Content-Type": "application/json",
37-
},
38-
body: JSON.stringify({ query, variables }),
30+
// Save the username
31+
await setUsername(githubId, {
32+
leetcodeUsername: username,
3933
});
4034

41-
const data = await response.json();
42-
const questionData: QuestionData[] =
43-
data.data.userProfileUserQuestionProgressV2.numAcceptedQuestions;
35+
const query = `
36+
query userProfileUserQuestionProgressV2($userSlug: String!) {
37+
userProfileUserQuestionProgressV2(userSlug: $userSlug) {
38+
numAcceptedQuestions {
39+
count
40+
difficulty
41+
}
42+
}
43+
}
44+
`;
45+
46+
const variables = {
47+
userSlug: username,
48+
};
49+
50+
const url = "https://leetcode.com/graphql/";
51+
try {
52+
const response = await fetch(url, {
53+
method: "POST",
54+
headers: {
55+
"Content-Type": "application/json",
56+
},
57+
body: JSON.stringify({ query, variables }),
58+
});
59+
60+
const data = await response.json();
61+
const questionData: QuestionData[] =
62+
data.data.userProfileUserQuestionProgressV2.numAcceptedQuestions;
4463

45-
const easyQues =
46-
questionData.find((q) => q.difficulty === "EASY")?.count || 0;
47-
const mediumQues =
48-
questionData.find((q) => q.difficulty === "MEDIUM")?.count || 0;
49-
const hardQues =
50-
questionData.find((q) => q.difficulty === "HARD")?.count || 0;
64+
const easyQues =
65+
questionData.find((q) => q.difficulty === "EASY")?.count || 0;
66+
const mediumQues =
67+
questionData.find((q) => q.difficulty === "MEDIUM")?.count || 0;
68+
const hardQues =
69+
questionData.find((q) => q.difficulty === "HARD")?.count || 0;
5170

52-
await setLeetCodeDatabyGithubId(githubId, easyQues, mediumQues, hardQues);
71+
await setLeetCodeDatabyGithubId(githubId, easyQues, mediumQues, hardQues);
5372

54-
return true;
73+
return true;
74+
} catch (error) {
75+
await logToDiscord(`processLeetcodeData: ${(error as any).message}`, "ERROR");
76+
77+
console.error("Error fetching Leetcode data:", error);
78+
return false;
79+
}
5580
} catch (error) {
5681
await logToDiscord(`processLeetcodeData: ${(error as any).message}`, "ERROR");
57-
58-
console.error("Error fetching Leetcode data:", error);
82+
console.error("Error processing LeetCode proof:", error);
5983
return false;
6084
}
6185
}

0 commit comments

Comments
 (0)