From dd4df1ff868db2993701cac899a0a7c50ac02482 Mon Sep 17 00:00:00 2001 From: eagle Date: Fri, 2 Feb 2024 19:20:58 +0530 Subject: [PATCH 1/5] feat: add getProfilesByUser query --- packages/data-layer/src/queries.ts | 34 ++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/data-layer/src/queries.ts b/packages/data-layer/src/queries.ts index 806a1d0ce1..c6bb3ee6e4 100644 --- a/packages/data-layer/src/queries.ts +++ b/packages/data-layer/src/queries.ts @@ -1,8 +1,7 @@ import { gql } from "graphql-request"; /** - * Get all the programs that a user is a part of - * @param $alloVersion - The version of Allo + * 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 * @@ -31,6 +30,37 @@ export const getProgramsByUser = gql` } `; +/** + * Get all the profiles that a user is a part of in allo v2 + * @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 getProfilesByUser = 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 From e26c86e1bfa162df2ae51bc31cee434142aada8b Mon Sep 17 00:00:00 2001 From: eagle Date: Tue, 6 Feb 2024 18:18:58 +0530 Subject: [PATCH 2/5] feat: update getProgramsByUser --- packages/data-layer/src/data-layer.ts | 23 ++++++++++++++--------- packages/data-layer/src/queries.ts | 9 ++++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/data-layer/src/data-layer.ts b/packages/data-layer/src/data-layer.ts index c30efadcde..844d1a5221 100644 --- a/packages/data-layer/src/data-layer.ts +++ b/packages/data-layer/src/data-layer.ts @@ -32,6 +32,8 @@ import { getProjectById, getProjects, getProjectsAndRolesByAddress, + getV1ProjectsByUser, + getV2ProjectsByUser, getRoundByIdAndChainId, } from "./queries"; @@ -146,11 +148,12 @@ export class DataLayer { chainId, }; - const response: { projects: Program[] } = await request( - this.gsIndexerEndpoint, - getProgramsByUser, - requestVariables, - ); + let response: { projects: Program[] } = { projects: [] }; + + const query = + alloVersion === "allo-v1" ? getV1ProjectsByUser : getV2ProjectsByUser; + + response = await request(this.gsIndexerEndpoint, query, requestVariables); const programs = response.projects; @@ -351,14 +354,16 @@ export class DataLayer { roundId: string; chainId: number; }): Promise { - 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] ?? []; } diff --git a/packages/data-layer/src/queries.ts b/packages/data-layer/src/queries.ts index c6bb3ee6e4..4c3a5c1e5b 100644 --- a/packages/data-layer/src/queries.ts +++ b/packages/data-layer/src/queries.ts @@ -1,13 +1,13 @@ import { gql } from "graphql-request"; /** - * Get all the programs that a user is a part of in allo v1 + * 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` query ($address: String!, $chainId: Int!) { projects( filter: { @@ -31,14 +31,13 @@ export const getProgramsByUser = gql` `; /** - * Get all the profiles that a user is a part of in allo v2 - * @param $alloVersion - The version of Allo + * 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 getProfilesByUser = gql` +export const getV2ProjectsByUser = gql` query ($address: String!, $chainId: Int!) { projects( filter: { From 9731c457f6b11769ff2f38cf360179c9add0dc38 Mon Sep 17 00:00:00 2001 From: eagle Date: Fri, 9 Feb 2024 18:34:27 +0530 Subject: [PATCH 3/5] fix: build issues --- packages/data-layer/src/data-layer.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/data-layer/src/data-layer.ts b/packages/data-layer/src/data-layer.ts index 844d1a5221..4b24ca5de5 100644 --- a/packages/data-layer/src/data-layer.ts +++ b/packages/data-layer/src/data-layer.ts @@ -28,7 +28,6 @@ import { import { getApplicationsByProjectId, getProgramName, - getProgramsByUser, getProjectById, getProjects, getProjectsAndRolesByAddress, From 3905bd2b94f073b0669c781a68513e82c7d5fa36 Mon Sep 17 00:00:00 2001 From: eagle Date: Fri, 9 Feb 2024 19:21:09 +0530 Subject: [PATCH 4/5] feat: update getProgramsByUser --- packages/data-layer/src/data-layer.ts | 38 +++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/packages/data-layer/src/data-layer.ts b/packages/data-layer/src/data-layer.ts index 4b24ca5de5..6d06c9a08a 100644 --- a/packages/data-layer/src/data-layer.ts +++ b/packages/data-layer/src/data-layer.ts @@ -15,6 +15,7 @@ import { Round, RoundOverview, SearchBasedProjectCategory, + Tags, TimestampVariables, V2Round, v2Project, @@ -147,14 +148,41 @@ export class DataLayer { chainId, }; - let response: { projects: Program[] } = { projects: [] }; + let programs: Program[] = []; - const query = - alloVersion === "allo-v1" ? getV1ProjectsByUser : getV2ProjectsByUser; + if (alloVersion === "allo-v1") { + let response: { projects: Program[] } = { projects: [] }; - response = await request(this.gsIndexerEndpoint, query, requestVariables); + 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; From 2d4d083b69b4a237ec2b40d1be8a271f24349e12 Mon Sep 17 00:00:00 2001 From: eagle Date: Wed, 14 Feb 2024 18:00:38 +0530 Subject: [PATCH 5/5] fix: address feedback --- packages/data-layer/src/data-layer.ts | 9 +++--- packages/data-layer/src/queries.ts | 45 ++++++--------------------- 2 files changed, 14 insertions(+), 40 deletions(-) diff --git a/packages/data-layer/src/data-layer.ts b/packages/data-layer/src/data-layer.ts index 6d06c9a08a..77f96875be 100644 --- a/packages/data-layer/src/data-layer.ts +++ b/packages/data-layer/src/data-layer.ts @@ -32,8 +32,7 @@ import { getProjectById, getProjects, getProjectsAndRolesByAddress, - getV1ProjectsByUser, - getV2ProjectsByUser, + getProgramByUserAndTag, getRoundByIdAndChainId, } from "./queries"; @@ -142,10 +141,12 @@ 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, }; let programs: Program[] = []; @@ -155,7 +156,7 @@ export class DataLayer { response = await request( this.gsIndexerEndpoint, - getV1ProjectsByUser, + getProgramByUserAndTag, requestVariables, ); @@ -165,7 +166,7 @@ export class DataLayer { response = await request( this.gsIndexerEndpoint, - getV2ProjectsByUser, + getProgramByUserAndTag, requestVariables, ); diff --git a/packages/data-layer/src/queries.ts b/packages/data-layer/src/queries.ts index 4c3a5c1e5b..f645fd7534 100644 --- a/packages/data-layer/src/queries.ts +++ b/packages/data-layer/src/queries.ts @@ -1,47 +1,18 @@ import { gql } from "graphql-request"; /** - * Manager: Get all the programs that a user is a part of in allo v1 + * 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 getV1ProjectsByUser = gql` - query ($address: String!, $chainId: Int!) { +export const getProgramByUserAndTag = gql` + query ($address: String!, $chainId: Int!, $filterByTag: String!) { projects( filter: { - tags: { contains: "program" } - roles: { some: { address: { equalTo: $address } } } - and: { chainId: { equalTo: $chainId } } - } - ) { - id - chainId - metadata - metadataCid - tags - roles { - address - role - createdAtBlock - } - } - } -`; - -/** - * 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" } + tags: { contains: [$filterByTag] } roles: { some: { address: { equalTo: $address } } } and: { chainId: { equalTo: $chainId } } } @@ -278,7 +249,9 @@ export const getBlockNumberQuery = gql` export const getRoundByIdAndChainId = gql` query getRoundByIdAndChainId($roundId: String!, $chainId: Int!) { - rounds(filter: { id: { equalTo: $roundId }, chainId: { equalTo: $chainId } }) { + rounds( + filter: { id: { equalTo: $roundId }, chainId: { equalTo: $chainId } } + ) { id chainId applicationsStartTime @@ -292,4 +265,4 @@ export const getRoundByIdAndChainId = gql` applicationMetadataCid } } -`; \ No newline at end of file +`;