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

Commit 8d907fe

Browse files
fix: updates on checker story (#59)
* updates on checker story * cleaning * minor change * cleaning --------- Co-authored-by: Nick Lionis <nikolaos@gitcoin.co>
1 parent dfd1419 commit 8d907fe

File tree

12 files changed

+99
-61
lines changed

12 files changed

+99
-61
lines changed

src/components/pool/components/PoolSummary/PoolSummary.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ export const PoolSummary = (pool: PoolSummaryProps) => {
4444
const applyLink = `https://builder.gitcoin.co/#/chains/${pool.chainId}/round/${pool.poolId}/apply`;
4545
const explorerLink = `https://explorer.gitcoin.co/#/round/${pool.chainId}/${pool.poolId}`;
4646

47-
// TODO Fix breadcrumbItems hrefs
4847
const breadcrumbItems = [
49-
{ label: "My Programs", href: "#" },
50-
{ label: "Program Details", href: "#" },
51-
{ label: "Round Details", href: "#" },
48+
{ label: "My Programs", href: "https://manager.gitcoin.co/#/" },
49+
// TODO: Fix href for Program Details
50+
{ label: "Program Details", href: "https://manager.gitcoin.co/#/1" },
51+
{
52+
label: "Round Details",
53+
href: `https://explorer.gitcoin.co/#/round/${pool.chainId}/${pool.poolId}`,
54+
},
5255
];
5356
return (
5457
<div className={cn(variants.variants.default, "grid grid-cols-2")}>
+37-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import type { Meta, StoryObj } from "@storybook/react";
22

3-
import { handlers } from "@/mocks/handlers";
3+
import { CheckerProvider } from "~checker/store";
44

55
import { Checker } from "./Checker";
6+
import { usePerformEvaluation, usePerformOnChainReview } from "./hooks";
67

78
const meta = {
89
title: "Features/Checker",
910
component: Checker,
1011
args: {
1112
address: "0x1234567890123456789012345678901234567890",
12-
poolId: "609",
13-
chainId: 42161,
13+
poolId: "597",
14+
chainId: 11155111,
1415
},
1516
} satisfies Meta;
1617

@@ -19,9 +20,39 @@ export default meta;
1920
type Story = StoryObj<typeof Checker>;
2021

2122
export const Default: Story = {
22-
parameters: {
23-
msw: {
24-
handlers,
23+
decorators: [
24+
(Story) => {
25+
// New StoryWrapper component
26+
const StoryWrapper = () => {
27+
const { setEvaluationBody, isSigning, isSuccess, isEvaluating, isError, isErrorSigning } =
28+
usePerformEvaluation();
29+
const { steps, setReviewBody, isReviewing } = usePerformOnChainReview();
30+
31+
return (
32+
<Story
33+
setEvaluationBody={setEvaluationBody}
34+
isSigning={isSigning}
35+
isSuccess={isSuccess}
36+
isEvaluating={isEvaluating}
37+
isError={isError}
38+
isErrorSigning={isErrorSigning}
39+
steps={steps}
40+
setReviewBody={setReviewBody}
41+
isReviewing={isReviewing}
42+
/>
43+
);
44+
};
45+
46+
return (
47+
<CheckerProvider>
48+
<StoryWrapper />
49+
</CheckerProvider>
50+
);
2551
},
52+
],
53+
parameters: {
54+
// msw: {
55+
// handlers,
56+
// },
2657
},
2758
};

src/features/checker/Checker.tsx

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
import { Hex } from "viem";
2-
3-
import { CheckerProvider } from "~checker/store";
4-
5-
import { CheckerRouter } from "./CheckerRouter";
6-
7-
export interface CheckerProps {
8-
address: Hex;
9-
poolId: string;
10-
chainId: number;
11-
}
1+
import { CheckerRouter, CheckerProps } from "./CheckerRouter";
2+
import { CheckerProvider } from "./store";
123

134
export const Checker = (props: CheckerProps) => {
145
return (

src/features/checker/CheckerRouter.tsx

+29-13
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,52 @@
11
import { match, P } from "ts-pattern";
22
import { Hex } from "viem";
33

4+
import { Step } from "@/components/ProgressModal";
45
import { useCheckerContext } from "@/features/checker/store/hooks/useCheckerContext";
56

6-
import { useInitialize, usePerformEvaluation, usePerformOnChainReview } from "~checker/hooks";
7+
import { useInitialize } from "~checker/hooks";
78
import {
89
ApplicationEvaluationOverviewPage,
910
ReviewApplicationsPage,
11+
ReviewBody,
1012
SubmitApplicationEvaluationPage,
1113
SubmitFinalEvaluationPage,
1214
} from "~checker/pages";
15+
import { EvaluationBody } from "~checker/services/checker/api";
1316
import { CheckerRoute } from "~checker/store";
1417

15-
export interface CheckerRouterProps {
18+
export interface CheckerProps {
1619
address: Hex;
1720
poolId: string;
1821
chainId: number;
22+
setEvaluationBody: (body: EvaluationBody) => void;
23+
isSigning: boolean;
24+
isSuccess: boolean;
25+
isEvaluating: boolean;
26+
isError: boolean;
27+
isErrorSigning: boolean;
28+
steps: Step[];
29+
setReviewBody: (reviewBody: ReviewBody | null) => void;
30+
isReviewing: boolean;
1931
}
2032

21-
export const CheckerRouter = ({ address, poolId, chainId }: CheckerRouterProps) => {
33+
export const CheckerRouter = ({
34+
address,
35+
poolId,
36+
chainId,
37+
setEvaluationBody,
38+
isSigning,
39+
isSuccess,
40+
isEvaluating,
41+
isError,
42+
isErrorSigning,
43+
steps,
44+
setReviewBody,
45+
isReviewing,
46+
}: CheckerProps) => {
2247
useInitialize({ address, poolId, chainId });
23-
const { setEvaluationBody, isSigning, isSuccess, isEvaluating, isError, isErrorSigning } =
24-
usePerformEvaluation();
25-
const { route } = useCheckerContext();
2648

27-
const {
28-
steps,
29-
setReviewBody,
30-
isSuccess: isReviewSuccess,
31-
isError: isReviewError,
32-
isReviewing,
33-
} = usePerformOnChainReview();
49+
const { route } = useCheckerContext();
3450

3551
return match(route)
3652
.with({ id: CheckerRoute.ReviewApplications }, () => <ReviewApplicationsPage />)

src/features/checker/hooks/useApplication.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const useApplicationEvaluations = (
2020
);
2121
const data = {
2222
application,
23-
applicationEvaluations,
23+
applicationEvaluations: applicationEvaluations,
2424
};
2525
return data;
2626
},

src/features/checker/pages/ApplicationEvaluationOverviewPage/ApplicationEvaluationOverviewPage.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Hex } from "viem";
22

3-
import { PoolType } from "@/components/Badges";
43
import { PoolSummary } from "@/components/pool/components/PoolSummary/PoolSummary";
54
import { ProjectBanner } from "@/components/project/components/ProjectBanner/ProjectBanner";
65
import { Button } from "@/primitives/Button";
@@ -33,7 +32,7 @@ export const ApplicationEvaluationOverviewPage = ({
3332
const { application, applicationEvaluations } =
3433
useApplicationOverviewEvaluations({ applicationId }) || {};
3534

36-
if (!application || !applicationEvaluations) return null;
35+
if (!application) return null;
3736

3837
const dispatch = useCheckerDispatchContext();
3938

@@ -80,7 +79,7 @@ export const ApplicationEvaluationOverviewPage = ({
8079
</p>
8180
<div className="flex flex-col gap-8">
8281
<div className="px-16">
83-
<EvaluationList evaluations={applicationEvaluations} />
82+
<EvaluationList evaluations={applicationEvaluations ?? []} />
8483
</div>
8584
<div className="flex items-center justify-center">
8685
<Button

src/features/checker/pages/SubmitApplicationEvaluationPage/SubmitApplicationEvaluationPage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export const SubmitApplicationEvaluationPage = ({
167167
alloPoolId: poolId,
168168
alloApplicationId: applicationId,
169169
cid: application.metadataCid,
170-
evaluator: address ?? "0xGitcoinShips!!!",
170+
evaluator: address ?? "0xGitcoinShips!",
171171
summaryInput: {
172172
questions: data,
173173
summary: feedback,

src/features/checker/pages/SubmitFinalEvaluationPage/SubmitFinalEvaluationPage.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export const SubmitFinalEvaluationPage = ({
6565
};
6666

6767
const [success, error] = useMemo(() => {
68-
const success = steps.every((step) => step.status === "IS_SUCCESS");
69-
const error = steps.some((step) => step.status === "IS_ERROR");
68+
const success = steps?.every((step) => step.status === "IS_SUCCESS");
69+
const error = steps?.some((step) => step.status === "IS_ERROR");
7070
return [success, error];
7171
}, [steps]);
7272

src/features/checker/services/allo/dataLayer.ts

-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export async function getApplicationsFromIndexer(
1515
chainId,
1616
roundId,
1717
});
18-
1918
return response.applications as ProjectApplicationForManager[];
2019
} catch (e) {
2120
throw new Error(`Failed to fetch applications data. with error: ${e}`);
@@ -33,7 +32,6 @@ export async function getApplicationByIdFromIndexer(
3332
roundId,
3433
applicationId,
3534
});
36-
3735
return response.application as ProjectApplication;
3836
} catch (e) {
3937
throw new Error(`Failed to fetch application data. with error: ${e}`);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export async function syncPool(syncPoolBody: SyncPoolBody): Promise<boolean> {
7272
},
7373
body: JSON.stringify({
7474
...syncPoolBody,
75-
skipEvaluation: true,
75+
skipEvaluation: false,
7676
}),
7777
});
7878

src/features/checker/services/checker/dataLayer.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { syncPool } from "./api";
12
import { executeQuery } from "./checkerClient";
23
import { checkerApplicationEvaluationsQuery, checkerPoolDataQuery } from "./queries";
34
import { CheckerApiApplication, CheckerApiPoolData } from "./types";
@@ -7,6 +8,7 @@ export async function getCheckerPoolData(
78
alloPoolId?: string,
89
): Promise<CheckerApiPoolData> {
910
try {
11+
await syncPool({ chainId: chainId as number, alloPoolId: alloPoolId as string });
1012
const response = (await executeQuery(checkerPoolDataQuery, {
1113
chainId,
1214
alloPoolId,
@@ -32,7 +34,7 @@ export async function getCheckerApplicationEvaluations(
3234
})) as unknown as {
3335
applications: CheckerApiApplication[];
3436
};
35-
return response.applications[0].evaluations;
37+
return response.applications[0]?.evaluations ?? [];
3638
} catch (e) {
3739
throw new Error(
3840
`Failed to fetch application evaluations data from checker api with error: ${e}.`,

src/features/checker/utils/mapApplicationsForOverviewPage.ts

+14-16
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ export function categorizeProjectReviews(
6161
}
6262

6363
// Separate evaluations into AI and non-AI
64-
const aiEvaluations = application.evaluations.filter(
65-
(evaluation) => evaluation.evaluator.toLowerCase() === AI_EVALUATOR_ADDRESS.toLowerCase(),
66-
);
64+
const aiEvaluations =
65+
application.evaluations?.filter(
66+
(evaluation) => evaluation.evaluator.toLowerCase() === AI_EVALUATOR_ADDRESS.toLowerCase(),
67+
) ?? [];
6768

68-
const humanEvaluations = application.evaluations.filter(
69-
(evaluation) => evaluation.evaluator.toLowerCase() !== AI_EVALUATOR_ADDRESS.toLowerCase(),
70-
);
69+
const humanEvaluations =
70+
application.evaluations?.filter(
71+
(evaluation) => evaluation.evaluator.toLowerCase() !== AI_EVALUATOR_ADDRESS.toLowerCase(),
72+
) ?? [];
7173

7274
// Determine the category based on the number of human evaluations
7375
const isReadyForReview = humanEvaluations.length >= 2;
@@ -76,7 +78,7 @@ export function categorizeProjectReviews(
7678
: "INREVIEW";
7779

7880
// Map human evaluations to reviews
79-
const reviews: Review[] = humanEvaluations.map((evaluation) => {
81+
const reviews: Review[] = humanEvaluations?.map((evaluation) => {
8082
const isApproved = evaluation.evaluatorScore >= 50; // Assuming 50 as the approval threshold
8183
const reviewerAddress: `0x${string}` = evaluation.evaluator.startsWith("0x")
8284
? (evaluation.evaluator as `0x${string}`)
@@ -88,18 +90,14 @@ export function categorizeProjectReviews(
8890
});
8991

9092
// Calculate the average score including both AI and human evaluations
91-
const totalScore = application.evaluations.reduce(
92-
(sum, evaluation) => sum + evaluation.evaluatorScore,
93-
0,
94-
);
95-
const totalEvaluations = application.evaluations.length;
93+
const totalScore =
94+
application.evaluations?.reduce((sum, evaluation) => sum + evaluation.evaluatorScore, 0) ?? 0;
95+
const totalEvaluations = application.evaluations?.length ?? 0;
9696
const scoreAverage = totalEvaluations > 0 ? totalScore / totalEvaluations : 0;
9797

9898
// Calculate AI suggestion score (average AI evaluator scores)
99-
const aiTotalScore = aiEvaluations.reduce(
100-
(sum, evaluation) => sum + evaluation.evaluatorScore,
101-
0,
102-
);
99+
const aiTotalScore =
100+
aiEvaluations?.reduce((sum, evaluation) => sum + evaluation.evaluatorScore, 0) ?? 0;
103101
const aiSuggestion = aiEvaluations.length > 0 ? aiTotalScore / aiEvaluations.length : 0;
104102

105103
const projectData = application.metadata.application.project;

0 commit comments

Comments
 (0)