Skip to content

Commit

Permalink
Merge branch '2858-add-synpress' of github.com:gitcoinco/grants-stack…
Browse files Browse the repository at this point in the history
… into 2858-add-synpress
  • Loading branch information
vacekj committed Feb 5, 2024
2 parents ed5814f + 4cef516 commit 1be0600
Show file tree
Hide file tree
Showing 18 changed files with 353 additions and 222 deletions.
2 changes: 1 addition & 1 deletion packages/data-layer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"dev": "tsx watch -r dotenv-flow/config src/index.ts",
"dev": "tsc --watch",
"lint": "eslint --cache --max-warnings=0",
"lint:fix": "eslint --cache --max-warnings=0 --fix",
"lint:all:fix": "eslint --fix --cache --max-warnings=0 src",
Expand Down
58 changes: 55 additions & 3 deletions packages/data-layer/src/data-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as legacy from "./backends/legacy";
import { AlloVersion, PaginationInfo } from "./data-layer.types";
import {
Collection,
Program,
ProjectEventsMap,
Round,
RoundOverview,
Expand All @@ -23,6 +24,7 @@ import {
SearchResult,
} from "./openapi-search-client/index";
import {
getProgramsByUser,
getProjectById,
getProjects,
getProjectsAndRolesByAddress,
Expand Down Expand Up @@ -102,6 +104,56 @@ export class DataLayer {
this.gsIndexerEndpoint = indexer.baseUrl;
}

/**
* Allo v1 & v2 manager queries
*/

/**
* Gets profiles/programs linked to an operator or user.
*
* @example
* Here is an example:
* ```
* const program = await dataLayer.getProgramByUser({
* address: "0x1234",
* chainId: 1,
* alloVersion: "allo-v1",
* });
* ```
* @param address - the address of the user.
* @param chainId - the network ID of the chain.
* @param alloVersion - the version of Allo to use.
*
* @returns Program
*/
async getProgramsByUser({
address,
chainId,
alloVersion,
}: {
address: string;
chainId: number;
alloVersion: AlloVersion;
}): Promise<{ programs: Program[] } | null> {
const requestVariables = {
alloVersion,
address,
chainId,
};

const response: { projects: Program[] } = await request(
this.gsIndexerEndpoint,
getProgramsByUser,
requestVariables,
);

const programs = response.projects;

if (!programs) return null;

return { programs };
}

/**
* Allo v1 & v2 builder queries
*/
Expand Down Expand Up @@ -208,7 +260,7 @@ export class DataLayer {
address: string;
alloVersion: AlloVersion;
chainId: number;
}): Promise<ProjectEventsMap | null> {
}): Promise<ProjectEventsMap | undefined> {
const requestVariables = {
address: address.toLowerCase(),
version: alloVersion,
Expand All @@ -221,9 +273,9 @@ export class DataLayer {
requestVariables,
);

const projects = response.projects;
const projects: v2Project[] = response.projects;

if (projects.length === 0) return null;
if (projects.length === 0) return undefined;

const projectEventsMap: ProjectEventsMap = {};

Expand Down
19 changes: 18 additions & 1 deletion packages/data-layer/src/data.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ export type ProjectRole = {
projectId: string;
};

export type Tags = "allo-v1" | "program update";

/**
* The program type for v1
**/

export type Program = {
id: string;
chainId: number;
metadata: {
name: string;
};
metadataCid?: MetadataPointer;
tags: Tags[];
roles: AddressAndRole[];
};

/**
* The project type for v2
*
Expand Down Expand Up @@ -162,7 +179,7 @@ export type v2Project = {
*
* The tags are used to filter the projects based on the version of Allo.
*/
tags: string[];
tags: [string];
/**
* The block the project was created at
*/
Expand Down
63 changes: 63 additions & 0 deletions packages/data-layer/src/queries.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
import { gql } from "graphql-request";

/**
* Get all the programs that a user is a part of
* @param $alloVersion - The version of Allo
* @param $address - The address of the user
* @param $chainId - The network ID of the chain
*
* @returns The programs
*/
export const getProgramsByUser = gql`
query ($address: String!, $chainId: Int!) {
projects(
filter: {
tags: { contains: "program" }
roles: { some: { address: { equalTo: $address } } }
and: { chainId: { equalTo: $chainId } }
}
) {
id
chainId
metadata
metadataCid
tags
roles {
address
role
createdAtBlock
}
}
}
`;

/**
* Get a program by its programId
* @param $alloVersion - The version of Allo
* @param $programId - The ID of the program
* @param $chainId - The network ID of the chain
*
* @returns The programs
*/
export const getProgramById = gql`
query ($alloVersion: [String!]!, $programId: String!, $chainId: Int!) {
projects(
filter: {
tags: { equalTo: $alloVersion }
tags: { contains: "program" }
id: { equalTo: $programId }
and: { chainId: { equalTo: $chainId } }
}
) {
id
chainId
metadata
metadataCid
tags
roles {
address
role
createdAtBlock
}
}
}
`;

/**
* Get a project by its ID
* @param $alloVersion - The version of Allo
Expand Down
52 changes: 6 additions & 46 deletions packages/grant-explorer/src/features/api/rounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,10 @@ import useSWR, { useSWRConfig, Cache, SWRResponse } from "swr";
import { ChainId, RoundPayoutType } from "common";
import { __deprecated_RoundMetadata } from "./round";
import { MetadataPointer } from "./types";
import { __deprecated_fetchFromIPFS, useDebugMode } from "./utils";
import { __deprecated_fetchFromIPFS } from "./utils";
import { createTimestamp } from "../discovery/utils/createRoundsStatusFilter";
import { useDataLayer } from "data-layer";

const validRounds = [
"0x35c9d05558da3a3f3cddbf34a8e364e59b857004", // "Metacamp Onda 2023 FINAL
"0x984e29dcb4286c2d9cbaa2c238afdd8a191eefbc", // Gitcoin Citizens Round #1
"0x4195cd3cd76cc13faeb94fdad66911b4e0996f38", // Greenpill Q2 2023
].map((a) => a.toLowerCase());

const invalidRounds = [
"0xde272b1a1efaefab2fd168c02b8cf0e3b10680ef", // Meg hello

// https://github.com/gitcoinco/grants-stack/issues/2569
"0x7c1104c39e09e7c6114f3d4e30a180a714deac7d",
"0x79715bf10dab457e06020ec41efae3484cff59dc",
"0x4632ea15ba3c1a7e072996fb316efefb8280381b",
"0xfe36ff9c59788a6a9ad7a979f459d69372dad0e6",
"0xa7149a073db99cd9ac267daf0c4f7767e50acf3f",
"0x4abc6f3322158bcec933f18998709322de7152c2",
"0xae53557089a1d771cd5cebeaf6accbe8f064ff4c",
"0xee3ed186939af2c55d33d242c4588426e368c8d0",
"0x8011e814439b44aa340bc3373df06233f45e3202",
"0xf3cd7429e863a39a9ecab60adc4676c1934076f2",
"0x88fc9d6695bedd34bbbe4ea0e2510573200713c7",
"0xae18f327ce481a7316d28a625d4c378c1f8b03a2",
"0x9b3b1e7edf9c5eea07fb3c7270220be1c3fea111",
"0x4c19261ff6e5736a2677a06741bf1e68995e7c95",
"0x1ebac14c3b3e539b0c1334415c70a923eb7c736f",
"0x3979611e7ca6db8f45b4a768079a88d9138622c1",
"0x0b1e3459cdadc52fca8977cede34f28bc298e3df",
"0x1427a0e71a222b0229a910dc72da01f8f04c7441",
"0xc25994667632d55a8e3dae88737e36f496600434",
"0x21d264139d66dd281dcb0177bbdca5ceeb71ad69",
"0x822742805c0596e883aba99ba2f3117e8c49b94a",
].map((a) => a.toLowerCase());

export type __deprecated_RoundOverview = {
id: string;
chainId: ChainId;
Expand Down Expand Up @@ -94,7 +61,6 @@ export const useRounds = (
chainIds: ChainId[]
): SWRResponse<__deprecated_RoundOverview[]> => {
const { cache, mutate } = useSWRConfig();
const isDebugModeEnabled = useDebugMode();
const dataLayer = useDataLayer();

const prewarmSwrCacheWithRoundsMetadata = async (
Expand Down Expand Up @@ -140,12 +106,14 @@ export const useRounds = (
await prewarmSwrCacheWithRoundsMetadata(rounds);

return rounds;
},
{
revalidateOnFocus: false,
revalidateIfStale: false,
}
);

const data = (
isDebugModeEnabled ? query.data : filterRounds(cache, query.data)
)
const data = query.data
// Limit final results returned
?.slice(0, variables.first ?? query.data?.length);

Expand All @@ -169,14 +137,6 @@ export const filterRounds = (
rounds?: __deprecated_RoundOverview[]
) => {
return rounds?.filter((round) => {
if (validRounds.includes(round.id.toLowerCase())) {
return true;
}

if (invalidRounds.includes(round.id.toLowerCase())) {
return false;
}

// Get the round metadata
const metadata = cache.get(`@"metadata","${round.roundMetaPtr.pointer}",`);
if (metadata?.data?.roundType === "public") {
Expand Down
20 changes: 19 additions & 1 deletion packages/grant-explorer/src/features/discovery/LandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "./hooks/useFilterRounds";
import { toQueryString } from "./RoundsFilter";
import { getEnabledChains } from "../../app/chainConfig";
import { useMemo } from "react";

const LandingPage = () => {
const activeRounds = useFilterRounds(
Expand All @@ -21,6 +22,23 @@ const LandingPage = () => {
getEnabledChains()
);

const filteredActiveRounds: typeof activeRounds.data = useMemo(() => {
if (activeRounds.data === undefined) {
return undefined;
}

const rounds =
activeRounds.data?.filter((round) => {
return (round.projects?.length ?? 0) > 1;
}) ?? [];

rounds.sort((a, b) => {
return (b.projects?.length ?? 0) - (a.projects?.length ?? 0);
});

return rounds;
}, [activeRounds.data]);

return (
<GradientLayout showWalletInteraction>
<LandingHero />
Expand All @@ -33,7 +51,7 @@ const LandingPage = () => {
}
>
<RoundsGrid
{...activeRounds}
{...{ ...activeRounds, data: filteredActiveRounds }}
loadingCount={4}
maxCount={6}
getItemClassName={(_, i) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,5 @@ describe("useFilterRounds", () => {
)?.length
).toBe(5);
expect(filterRounds(cacheMock, MOCKED_ROUNDS)?.length).toBe(0);

expect(
filterRounds(
cacheMock,
MOCKED_ROUNDS.map((r) => ({
...r,
// If RoundID is part of valid rounds
id: "0x35c9d05558da3a3f3cddbf34a8e364e59b857004",
}))
)?.length
).toBe(5);
expect(
filterRounds(
cacheMock,
MOCKED_ROUNDS.map((r) => ({
...r,
// If RoundID is part of invalid rounds
id: "0xde272b1a1efaefab2fd168c02b8cf0e3b10680ef",
}))
)?.length
).toBe(0);
});
});
1 change: 1 addition & 0 deletions packages/round-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"allo-indexer-client": "github:gitcoinco/allo-indexer-client",
"buffer": "^6.0.3",
"common": "workspace:*",
"data-layer": "workspace:*",
"crypto-browserify": "^3.12.0",
"csv-parse": "^5.3.8",
"csv-stringify": "^6.3.2",
Expand Down
Loading

0 comments on commit 1be0600

Please sign in to comment.