Skip to content

Commit

Permalink
Merge branch 'main' into 2825-explorer-v2---view-round-explorer-homep…
Browse files Browse the repository at this point in the history
…age-fetch-rounds-from-the-indexer-instead-of-subgraph
  • Loading branch information
vacekj committed Feb 16, 2024
2 parents f7dd1be + 7b303a3 commit dcee717
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
45 changes: 38 additions & 7 deletions packages/data-layer/src/data-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
Round,
RoundGetRound,
SearchBasedProjectCategory,
Tags,
TimestampVariables,
v2Project,
V2Round,
Expand All @@ -32,10 +33,10 @@ import {
getApplication,
getApplicationsByProjectId,
getProgramName,
getProgramsByUser,
getProjectById,
getProjects,
getProjectsAndRolesByAddress,
getProgramByUserAndTag,
getRoundByIdAndChainId,
getRoundsByProgramIdAndUserAddress,
getRoundsQuery,
Expand Down Expand Up @@ -147,19 +148,49 @@ export class DataLayer {
chainId: number;
alloVersion: AlloVersion;
}): Promise<{ programs: Program[] } | null> {
const filterByTag = alloVersion === "allo-v1" ? "program" : "allo-v2";
const requestVariables = {
alloVersion,
address,
chainId,
filterByTag,
};

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

if (alloVersion === "allo-v1") {
let response: { projects: Program[] } = { projects: [] };

response = await request(
this.gsIndexerEndpoint,
getProgramByUserAndTag,
requestVariables,
);

const programs = response.projects;
programs = response.projects;
} else if (alloVersion === "allo-v2") {
let response: { projects: v2Project[] } = { projects: [] };

response = await request(
this.gsIndexerEndpoint,
getProgramByUserAndTag,
requestVariables,
);

const projects = response.projects;

programs = projects.map((project) => {
return {
id: project.id,
chainId: project.chainId,
metadata: {
name: project.metadata?.title,
},
tags: project.tags as Tags[],
roles: project.roles,
};
});
}

if (!programs) return null;

Expand Down
10 changes: 5 additions & 5 deletions packages/data-layer/src/queries.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { gql } from "graphql-request";

/**
* Get all the programs that a user is a part of
* @param $alloVersion - The version of Allo
* Manager: Get all the programs that a user is a part of
* @param $address - The address of the user
* @param $chainId - The network ID of the chain
* @param $tag - The tag of the program
*
* @returns The programs
*/
export const getProgramsByUser = gql`
query ($address: String!, $chainId: Int!) {
export const getProgramByUserAndTag = gql`
query ($address: String!, $chainId: Int!, $filterByTag: String!) {
projects(
filter: {
tags: { contains: "program" }
tags: { contains: [$filterByTag] }
roles: { some: { address: { equalTo: $address } } }
and: { chainId: { equalTo: $chainId } }
}
Expand Down

0 comments on commit dcee717

Please sign in to comment.