Skip to content
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

fetch Allo V2 programs from the indexer #2871

Merged
merged 6 commits into from
Feb 15, 2024
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
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 @@ -16,6 +16,7 @@ import {
Round,
RoundOverview,
SearchBasedProjectCategory,
Tags,
TimestampVariables,
v2Project,
V2Round,
Expand All @@ -30,10 +31,10 @@ import {
getApplication,
getApplicationsByProjectId,
getProgramName,
getProgramsByUser,
getProjectById,
getProjects,
getProjectsAndRolesByAddress,
getProgramByUserAndTag,
getRoundByIdAndChainId,
} from "./queries";
import { Address } from "viem";
Expand Down Expand Up @@ -143,19 +144,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
Loading