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 4 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
54 changes: 43 additions & 11 deletions packages/data-layer/src/data-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Round,
RoundOverview,
SearchBasedProjectCategory,
Tags,
TimestampVariables,
V2Round,
v2Project,
Expand All @@ -28,10 +29,11 @@ import {
import {
getApplicationsByProjectId,
getProgramName,
getProgramsByUser,
getProjectById,
getProjects,
getProjectsAndRolesByAddress,
getV1ProjectsByUser,
getV2ProjectsByUser,
getRoundByIdAndChainId,
} from "./queries";

Expand Down Expand Up @@ -146,13 +148,41 @@ export class DataLayer {
chainId,
};

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,
getV1ProjectsByUser,
requestVariables,
);

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

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

const programs = response.projects;
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 Expand Up @@ -351,14 +381,16 @@ export class DataLayer {
roundId: string;
chainId: number;
}): Promise<V2Round> {

const requestVariables = {
roundId,
chainId
chainId,
};

const response : {rounds: V2Round[]} =
await request(this.gsIndexerEndpoint, getRoundByIdAndChainId, requestVariables);
const response: { rounds: V2Round[] } = await request(
this.gsIndexerEndpoint,
getRoundByIdAndChainId,
requestVariables,
);

return response.rounds[0] ?? [];
}
Expand Down
35 changes: 32 additions & 3 deletions packages/data-layer/src/queries.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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 in allo v1
* @param $address - The address of the user
* @param $chainId - The network ID of the chain
*
* @returns The programs
*/
export const getProgramsByUser = gql`
export const getV1ProjectsByUser = gql`
bhargavaparoksham marked this conversation as resolved.
Show resolved Hide resolved
query ($address: String!, $chainId: Int!) {
projects(
filter: {
Expand All @@ -31,6 +30,36 @@ export const getProgramsByUser = gql`
}
`;

/**
* Manager: Get all the projects that a user is a part of in allo v2
* @param $address - The address of the user
* @param $chainId - The network ID of the chain
*
* @returns The programs
*/
export const getV2ProjectsByUser = gql`
query ($address: String!, $chainId: Int!) {
projects(
filter: {
tags: { contains: "allo-v2" }
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
Expand Down
Loading