From 6a572e7a43613017d7be3a6800b2674c08ed3749 Mon Sep 17 00:00:00 2001 From: gnomadic Date: Tue, 11 Feb 2025 14:26:15 -0500 Subject: [PATCH 1/4] splitting out query for rounds grid so we can show unapproved applications --- packages/data-layer/src/data-layer.ts | 10 ++++++- packages/data-layer/src/queries.ts | 30 +++++++++++++++++++ .../grant-explorer/src/features/api/rounds.ts | 8 ++++- .../features/discovery/ExploreRoundsPage.tsx | 10 ++++++- .../src/features/discovery/RoundCard.tsx | 30 ++++++++++++++++--- .../discovery/hooks/useFilterRounds.ts | 5 ++-- 6 files changed, 84 insertions(+), 9 deletions(-) diff --git a/packages/data-layer/src/data-layer.ts b/packages/data-layer/src/data-layer.ts index ee5a39d8aa..18634bd53f 100644 --- a/packages/data-layer/src/data-layer.ts +++ b/packages/data-layer/src/data-layer.ts @@ -945,6 +945,7 @@ export class DataLayer { orderBy, filter, whitelistedPrograms, + query = getRoundsQuery, }: { chainIds: number[]; first: number; @@ -952,8 +953,13 @@ export class DataLayer { orderDirection?: "asc" | "desc"; filter?: RoundsQueryVariables["filter"]; whitelistedPrograms?: string[]; + query?: string | undefined; }): Promise<{ rounds: RoundGetRound[] }> { - return await request(this.gsIndexerEndpoint, getRoundsQuery, { + // if (query === undefined) { + // query = getRoundsQuery; + // } + + const res = await request(this.gsIndexerEndpoint, query, { orderBy: orderBy ?? "NATURAL", chainIds, first, @@ -964,6 +970,8 @@ export class DataLayer { } : filter, }); + + return res as { rounds: RoundGetRound[] }; } async getProjectCollections(): Promise { diff --git a/packages/data-layer/src/queries.ts b/packages/data-layer/src/queries.ts index 1b5e239be4..21f4c6d45c 100644 --- a/packages/data-layer/src/queries.ts +++ b/packages/data-layer/src/queries.ts @@ -633,6 +633,36 @@ export const getRoundsQuery = gql` } `; +export const getRoundsQueryWithAllApplications = gql` + query GetRounds( + $first: Int + $orderBy: [RoundsOrderBy!] + $filter: RoundFilter + ) { + rounds(first: $first, orderBy: $orderBy, filter: $filter) { + id + chainId + tags + roundMetadata + roundMetadataCid + applicationsStartTime + applicationsEndTime + donationsStartTime + donationsEndTime + matchAmountInUsd + matchAmount + matchTokenAddress + strategyId + strategyName + strategyAddress + applications(first: 1000) { + id + status + } + } + } +`; + export const getRoundByIdAndChainId = gql` query getRoundByIdAndChainId($roundId: String!, $chainId: Int!) { rounds( diff --git a/packages/grant-explorer/src/features/api/rounds.ts b/packages/grant-explorer/src/features/api/rounds.ts index 27dc235086..cf5b13a0f8 100644 --- a/packages/grant-explorer/src/features/api/rounds.ts +++ b/packages/grant-explorer/src/features/api/rounds.ts @@ -6,7 +6,8 @@ import { RoundGetRound, RoundsQueryVariables, useDataLayer } from "data-layer"; export const useRounds = ( variables: RoundsQueryVariables, chainIds: number[], - onlywWhitelistedPrograms = false + onlywWhitelistedPrograms = false, + gqlQuery: string | undefined ): SWRResponse => { const dataLayer = useDataLayer(); @@ -26,9 +27,14 @@ export const useRounds = ( first: 500, chainIds, whitelistedPrograms, + query: gqlQuery, }), ]); + rounds?.map((round) => { + console.log("rounds.ts applications: " + round?.applications?.length); + }); + return rounds.filter( (round) => !spamRounds[round.chainId]?.[round.id.toLowerCase()] && diff --git a/packages/grant-explorer/src/features/discovery/ExploreRoundsPage.tsx b/packages/grant-explorer/src/features/discovery/ExploreRoundsPage.tsx index 1428ad5e1f..9f6719773c 100644 --- a/packages/grant-explorer/src/features/discovery/ExploreRoundsPage.tsx +++ b/packages/grant-explorer/src/features/discovery/ExploreRoundsPage.tsx @@ -11,6 +11,7 @@ import { getExplorerPageTitle } from "./utils/getExplorerPageTitle"; import { RoundsGrid } from "./RoundsGrid"; import { getEnabledChains } from "../../app/chainConfig"; import { useMemo } from "react"; +import { getRoundsQueryWithAllApplications } from "data-layer/src/queries"; const ExploreRoundsPage = () => { const [params] = useSearchParams(); @@ -19,7 +20,8 @@ const ExploreRoundsPage = () => { const rounds = useFilterRounds( filter, getEnabledChains(), - filter.status.includes("verified") + filter.status.includes("verified"), + getRoundsQueryWithAllApplications ); const publicRounds = useMemo( @@ -45,6 +47,12 @@ const ExploreRoundsPage = () => { className="flex-wrap" action={} > +
+ {rounds?.data?.map((round) => { + return

{"applications: " + round?.applications?.length}

; + })} +
+ diff --git a/packages/grant-explorer/src/features/discovery/RoundCard.tsx b/packages/grant-explorer/src/features/discovery/RoundCard.tsx index 44e0e1d618..0b4278802d 100644 --- a/packages/grant-explorer/src/features/discovery/RoundCard.tsx +++ b/packages/grant-explorer/src/features/discovery/RoundCard.tsx @@ -18,7 +18,7 @@ import { RoundDaysDetails } from "./RoundDaysDetails"; import { RoundMatchAmountBadge } from "./RoundMatchAmountBadge"; import { RoundStrategyBadge } from "./RoundStrategyBadge"; import { RoundTimeBadge } from "./RoundTimeBadge"; -import { RoundGetRound } from "data-layer"; +import { Application, RoundGetRound } from "data-layer"; import { parseChainIdIntoResult, stringToBlobUrl } from "common/dist/chains"; type RoundType = "all" | "endingSoon" | "active"; @@ -95,7 +95,13 @@ const RoundCard = ({ round, index, roundType }: RoundCardProps) => { atTimeMs: Date.now(), }); - const approvedApplicationsCount = applications?.length ?? 0; + // const approvedApplicationsCount = applications?.length ?? 0; + + const totalApplicationCount = applications?.length ?? 0; + const approvedApplications = + applications?.filter( + (application) => (application as Application)?.status === "APPROVED" + ).length ?? 0; const getTrackEventValue = (roundType: RoundType, index: number) => { if (roundType === "all") return "round-card"; @@ -114,6 +120,16 @@ const RoundCard = ({ round, index, roundType }: RoundCardProps) => { const trackEventValue = getTrackEventValue(roundType, index); + applications.map((application) => { + console.log("applications: " + application.id); + + const app = application as Application; + console.log("casted: ", JSON.stringify(app)); + // return ( + //

{application.id}

+ // ) + }); + return ( {
+ {totalApplicationCount} applications + + - {approvedApplicationsCount} projects + {approvedApplications} projects {strategyName !== ROUND_PAYOUT_DIRECT && ( => { const chainIds = where.network === undefined || where.network.trim() === "" @@ -103,7 +104,7 @@ export const useFilterRounds = ( const orderBy = where.orderBy === undefined ? "CREATED_AT_BLOCK_DESC" : where.orderBy; const vars = { orderBy, filter }; - return useRounds(vars, chainIds, onlywWhitelistedPrograms); + return useRounds(vars, chainIds, onlywWhitelistedPrograms, gqlQuery); }; const createRoundWhereFilter = ( From 4b76b389c8c0b2865cf4458b5e388f565c59689c Mon Sep 17 00:00:00 2001 From: MasterHW <43460021+MasterHW@users.noreply.github.com> Date: Tue, 11 Feb 2025 14:58:04 -0500 Subject: [PATCH 2/4] added conditional display logic --- .../grant-explorer/src/features/api/rounds.ts | 4 --- .../features/discovery/ExploreRoundsPage.tsx | 6 ---- .../src/features/discovery/RoundCard.tsx | 28 ++++------------ .../src/features/discovery/RoundProjects.tsx | 33 +++++++++++++++++++ 4 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 packages/grant-explorer/src/features/discovery/RoundProjects.tsx diff --git a/packages/grant-explorer/src/features/api/rounds.ts b/packages/grant-explorer/src/features/api/rounds.ts index cf5b13a0f8..3ec229deb6 100644 --- a/packages/grant-explorer/src/features/api/rounds.ts +++ b/packages/grant-explorer/src/features/api/rounds.ts @@ -31,10 +31,6 @@ export const useRounds = ( }), ]); - rounds?.map((round) => { - console.log("rounds.ts applications: " + round?.applications?.length); - }); - return rounds.filter( (round) => !spamRounds[round.chainId]?.[round.id.toLowerCase()] && diff --git a/packages/grant-explorer/src/features/discovery/ExploreRoundsPage.tsx b/packages/grant-explorer/src/features/discovery/ExploreRoundsPage.tsx index 9f6719773c..412c750506 100644 --- a/packages/grant-explorer/src/features/discovery/ExploreRoundsPage.tsx +++ b/packages/grant-explorer/src/features/discovery/ExploreRoundsPage.tsx @@ -47,12 +47,6 @@ const ExploreRoundsPage = () => { className="flex-wrap" action={} > -
- {rounds?.data?.map((round) => { - return

{"applications: " + round?.applications?.length}

; - })} -
- diff --git a/packages/grant-explorer/src/features/discovery/RoundCard.tsx b/packages/grant-explorer/src/features/discovery/RoundCard.tsx index 0b4278802d..adb0048af4 100644 --- a/packages/grant-explorer/src/features/discovery/RoundCard.tsx +++ b/packages/grant-explorer/src/features/discovery/RoundCard.tsx @@ -18,6 +18,7 @@ import { RoundDaysDetails } from "./RoundDaysDetails"; import { RoundMatchAmountBadge } from "./RoundMatchAmountBadge"; import { RoundStrategyBadge } from "./RoundStrategyBadge"; import { RoundTimeBadge } from "./RoundTimeBadge"; +import { RoundProjects } from "./RoundProjects"; import { Application, RoundGetRound } from "data-layer"; import { parseChainIdIntoResult, stringToBlobUrl } from "common/dist/chains"; @@ -120,16 +121,6 @@ const RoundCard = ({ round, index, roundType }: RoundCardProps) => { const trackEventValue = getTrackEventValue(roundType, index); - applications.map((application) => { - console.log("applications: " + application.id); - - const app = application as Application; - console.log("casted: ", JSON.stringify(app)); - // return ( - //

{application.id}

- // ) - }); - return (
{
- - {totalApplicationCount} applications - - - {approvedApplications} projects - + {strategyName !== ROUND_PAYOUT_DIRECT && ( | undefined; + totalApplicationCount: number; + approvedApplications: number; +} + +export const RoundProjects: React.FC = ({ + roundStates, + totalApplicationCount, + approvedApplications, +}) => { + if (roundStates?.includes("accepting-applications")) { + return ( + + {totalApplicationCount} applications + + ); + } else { + return ( + + {approvedApplications} projects + + ); + } +}; From 21e35e529a9993d0448aa8ccfea1573f7b4b9781 Mon Sep 17 00:00:00 2001 From: MasterHW <43460021+MasterHW@users.noreply.github.com> Date: Tue, 11 Feb 2025 15:00:37 -0500 Subject: [PATCH 3/4] fixed test --- .../grant-explorer/src/features/discovery/RoundProjects.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/grant-explorer/src/features/discovery/RoundProjects.tsx b/packages/grant-explorer/src/features/discovery/RoundProjects.tsx index 87173d9d4f..6d19be4fc0 100644 --- a/packages/grant-explorer/src/features/discovery/RoundProjects.tsx +++ b/packages/grant-explorer/src/features/discovery/RoundProjects.tsx @@ -15,7 +15,7 @@ export const RoundProjects: React.FC = ({ return ( {totalApplicationCount} applications From 6432be74768a620f92a46e6f205e75305eda7f77 Mon Sep 17 00:00:00 2001 From: gnomadic Date: Tue, 11 Feb 2025 15:04:18 -0500 Subject: [PATCH 4/4] some cleanup --- packages/data-layer/src/data-layer.ts | 8 +------- .../grant-explorer/src/features/discovery/RoundCard.tsx | 6 ++---- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/data-layer/src/data-layer.ts b/packages/data-layer/src/data-layer.ts index 18634bd53f..dac929cc56 100644 --- a/packages/data-layer/src/data-layer.ts +++ b/packages/data-layer/src/data-layer.ts @@ -955,11 +955,7 @@ export class DataLayer { whitelistedPrograms?: string[]; query?: string | undefined; }): Promise<{ rounds: RoundGetRound[] }> { - // if (query === undefined) { - // query = getRoundsQuery; - // } - - const res = await request(this.gsIndexerEndpoint, query, { + return await request(this.gsIndexerEndpoint, query, { orderBy: orderBy ?? "NATURAL", chainIds, first, @@ -970,8 +966,6 @@ export class DataLayer { } : filter, }); - - return res as { rounds: RoundGetRound[] }; } async getProjectCollections(): Promise { diff --git a/packages/grant-explorer/src/features/discovery/RoundCard.tsx b/packages/grant-explorer/src/features/discovery/RoundCard.tsx index adb0048af4..8d07826710 100644 --- a/packages/grant-explorer/src/features/discovery/RoundCard.tsx +++ b/packages/grant-explorer/src/features/discovery/RoundCard.tsx @@ -96,10 +96,8 @@ const RoundCard = ({ round, index, roundType }: RoundCardProps) => { atTimeMs: Date.now(), }); - // const approvedApplicationsCount = applications?.length ?? 0; - const totalApplicationCount = applications?.length ?? 0; - const approvedApplications = + const approvedApplicationCount = applications?.filter( (application) => (application as Application)?.status === "APPROVED" ).length ?? 0; @@ -166,7 +164,7 @@ const RoundCard = ({ round, index, roundType }: RoundCardProps) => { {strategyName !== ROUND_PAYOUT_DIRECT && (