Skip to content

Commit

Permalink
fix loading app request for explorer (#3359)
Browse files Browse the repository at this point in the history
  • Loading branch information
boudra authored Apr 24, 2024
1 parent c3259de commit e91e658
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 25 deletions.
22 changes: 22 additions & 0 deletions packages/data-layer/src/data-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
getRoundForExplorer,
getRoundsQuery,
getDonationsByDonorAddress,
getApplicationsForExplorer,
} from "./queries";
import { mergeCanonicalAndLinkedProjects } from "./utils";

Expand Down Expand Up @@ -370,6 +371,27 @@ export class DataLayer {
return response.application ?? null;
}

async getApplicationsForExplorer({
roundId,
chainId,
}: {
roundId: string;
chainId: number;
}): Promise<Application[]> {
const requestVariables = {
roundId,
chainId,
};

const response: { applications: Application[] } = await request(
this.gsIndexerEndpoint,
getApplicationsForExplorer,
requestVariables,
);

return response.applications ?? [];
}

/**
* Returns a list of applications identified by their chainId, roundId, and id.
* @param expandedRefs
Expand Down
34 changes: 34 additions & 0 deletions packages/data-layer/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,40 @@ export const getApplication = gql`
}
`;

export const getApplicationsForExplorer = gql`
query Applications($chainId: Int!, $roundId: String!) {
applications(
first: 1000
condition: { chainId: $chainId, roundId: $roundId, status: APPROVED }
) {
id
chainId
roundId
projectId
status
totalAmountDonatedInUsd
uniqueDonorsCount
totalDonationsCount
round {
strategyName
donationsStartTime
donationsEndTime
applicationsStartTime
applicationsEndTime
matchTokenAddress
roundMetadata
}
metadata
project: canonicalProject {
tags
id
metadata
anchorAddress
}
}
}
`;

export const getApplicationsByRoundIdAndProjectIds = gql`
query Application(
$chainId: Int!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import useSWR from "swr";
import { Application, DataLayer } from "data-layer";
import { DataLayer } from "data-layer";

type Params = {
chainId?: number;
roundId?: string;
projectIds?: string[];
};

export function useRoundApprovedApplications(
Expand All @@ -15,24 +14,14 @@ export function useRoundApprovedApplications(
return useSWR(
shouldFetch ? ["allApprovedApplications", params] : null,
async () => {
const validatedParams = (projectId: string) => {
return {
chainId: params.chainId as number,
roundId: params.roundId as string,
applicationId: projectId as string,
};
};
if (!params.projectIds) return;
if (params.chainId === undefined || params.roundId === undefined) {
return null;
}

const arr = params.projectIds?.map((projectId) => {
return dataLayer.getApplication(validatedParams(projectId));
return await dataLayer.getApplicationsForExplorer({
roundId: params.roundId,
chainId: params.chainId,
});
return Promise.all(arr).then(
(applications) =>
applications.filter(
(application) => application?.status === "APPROVED"
) as Application[] | undefined
);
}
);
}
8 changes: 1 addition & 7 deletions packages/grant-explorer/src/features/round/ViewRoundPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -612,16 +612,13 @@ const ProjectList = (props: {
setCurrentProjectAddedToCart: React.Dispatch<React.SetStateAction<Project>>;
setShowCartNotification: React.Dispatch<React.SetStateAction<boolean>>;
}): JSX.Element => {
const { projects, roundRoutePath, round, chainId, roundId } = props;
const { projects, roundRoutePath, chainId, roundId } = props;
const dataLayer = useDataLayer();

const { data: applications } = useRoundApprovedApplications(
{
chainId,
roundId,
projectIds: round.approvedProjects?.map(
(proj) => proj.grantApplicationId
),
},
dataLayer
);
Expand Down Expand Up @@ -882,9 +879,6 @@ const RoundStatsTabContent = ({
{
chainId,
roundId,
projectIds: round.approvedProjects?.map(
(proj) => proj.grantApplicationId
),
},
dataLayer
);
Expand Down

0 comments on commit e91e658

Please sign in to comment.