Skip to content

Showing Pending Applications on Round Card #3763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/data-layer/src/data-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,15 +945,17 @@ export class DataLayer {
orderBy,
filter,
whitelistedPrograms,
query = getRoundsQuery,
}: {
chainIds: number[];
first: number;
orderBy?: OrderByRounds;
orderDirection?: "asc" | "desc";
filter?: RoundsQueryVariables["filter"];
whitelistedPrograms?: string[];
query?: string | undefined;
}): Promise<{ rounds: RoundGetRound[] }> {
return await request(this.gsIndexerEndpoint, getRoundsQuery, {
return await request(this.gsIndexerEndpoint, query, {
orderBy: orderBy ?? "NATURAL",
chainIds,
first,
Expand Down
30 changes: 30 additions & 0 deletions packages/data-layer/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion packages/grant-explorer/src/features/api/rounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RoundGetRound[]> => {
const dataLayer = useDataLayer();

Expand All @@ -26,6 +27,7 @@ export const useRounds = (
first: 500,
chainIds,
whitelistedPrograms,
query: gqlQuery,
}),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -19,7 +20,8 @@ const ExploreRoundsPage = () => {
const rounds = useFilterRounds(
filter,
getEnabledChains(),
filter.status.includes("verified")
filter.status.includes("verified"),
getRoundsQueryWithAllApplications
);

const publicRounds = useMemo(
Expand Down
20 changes: 12 additions & 8 deletions packages/grant-explorer/src/features/discovery/RoundCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { RoundDaysDetails } from "./RoundDaysDetails";
import { RoundMatchAmountBadge } from "./RoundMatchAmountBadge";
import { RoundStrategyBadge } from "./RoundStrategyBadge";
import { RoundTimeBadge } from "./RoundTimeBadge";
import { RoundGetRound } from "data-layer";
import { RoundProjects } from "./RoundProjects";
import { Application, RoundGetRound } from "data-layer";
import { parseChainIdIntoResult, stringToBlobUrl } from "common/dist/chains";

type RoundType = "all" | "endingSoon" | "active";
Expand Down Expand Up @@ -95,7 +96,11 @@ const RoundCard = ({ round, index, roundType }: RoundCardProps) => {
atTimeMs: Date.now(),
});

const approvedApplicationsCount = applications?.length ?? 0;
const totalApplicationCount = applications?.length ?? 0;
const approvedApplicationCount =
applications?.filter(
(application) => (application as Application)?.status === "APPROVED"
).length ?? 0;

const getTrackEventValue = (roundType: RoundType, index: number) => {
if (roundType === "all") return "round-card";
Expand Down Expand Up @@ -156,12 +161,11 @@ const RoundCard = ({ round, index, roundType }: RoundCardProps) => {
<div className="border-t" />
<div className="flex justify-between">
<div className="flex gap-2">
<Badge
disabled={approvedApplicationsCount === 0}
data-testid="approved-applications-count"
>
{approvedApplicationsCount} projects
</Badge>
<RoundProjects
roundStates={roundStates}
totalApplicationCount={totalApplicationCount}
approvedApplications={approvedApplicationCount}
/>
{strategyName !== ROUND_PAYOUT_DIRECT && (
<RoundMatchAmountBadge
chainId={chainId}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Badge } from "../common/styles";

interface RoundProjectsProps {
roundStates: Array<"active" | "accepting-applications" | "ended"> | undefined;
totalApplicationCount: number;
approvedApplications: number;
}

export const RoundProjects: React.FC<RoundProjectsProps> = ({
roundStates,
totalApplicationCount,
approvedApplications,
}) => {
if (roundStates?.includes("accepting-applications")) {
return (
<Badge
disabled={totalApplicationCount === 0}
data-testid="applications-count"
>
{totalApplicationCount} applications
</Badge>
);
} else {
return (
<Badge
disabled={approvedApplications === 0}
data-testid="approved-applications-count"
>
{approvedApplications} projects
</Badge>
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export const ROUNDS_ENDING_SOON_FILTER: RoundSelectionParams & {
export const useFilterRounds = (
where: RoundSelectionParams,
chains: TChain[],
onlywWhitelistedPrograms?: boolean
onlywWhitelistedPrograms?: boolean,
gqlQuery?: string | undefined
): SWRResponse<RoundGetRound[]> => {
const chainIds =
where.network === undefined || where.network.trim() === ""
Expand Down Expand Up @@ -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 = (
Expand Down
Loading