From a96914401531c8c4879d6b2bd193440faff18a25 Mon Sep 17 00:00:00 2001 From: Spandan Barve Date: Mon, 23 Oct 2023 15:48:19 +0530 Subject: [PATCH 01/12] Add queries to proposals - getAllProposalsByServiceID - getAllProposalsByUSer --- .../client/src/proposals/graphql/index.ts | 89 +++++++++++++++++++ packages/client/src/proposals/index.ts | 18 +++- packages/client/src/proposals/types/index.ts | 10 ++- 3 files changed, 113 insertions(+), 4 deletions(-) diff --git a/packages/client/src/proposals/graphql/index.ts b/packages/client/src/proposals/graphql/index.ts index 2d3ba50..30b3213 100644 --- a/packages/client/src/proposals/graphql/index.ts +++ b/packages/client/src/proposals/graphql/index.ts @@ -35,3 +35,92 @@ export const getProposalById = (id: string) => ` } } `; + +export const getAllProposalsByServiceId = (id: string) => ` +{ + proposals(where: {service_: {id: "${id}"}}) { + service { + id, + cid + buyer { + id + } + platform { + id + } + } + cid + id + status + rateToken { + address + decimals + name + symbol + } + rateAmount + createdAt + updatedAt + seller { + id + handle + address + cid + rating + userStats { + numReceivedReviews + } + } + description { + id + about + expectedHours + startDate + video_url + } + expirationDate + platform { + id + } + } +} +`; + +export const getAllProposalsByUser = (id: string) => ` +{ + proposals(where: {seller: "${id}", status: "Pending"}) { + id + rateAmount + rateToken { + address + decimals + name + symbol + } + status + cid + createdAt + seller { + id + handle + } + service { + id + cid + createdAt + buyer { + id + handle + } + } + description { + id + about + expectedHours + startDate + video_url + } + expirationDate + } + } +`; diff --git a/packages/client/src/proposals/index.ts b/packages/client/src/proposals/index.ts index f0eb2e6..59143d7 100644 --- a/packages/client/src/proposals/index.ts +++ b/packages/client/src/proposals/index.ts @@ -4,7 +4,7 @@ import { Platform } from '../platform'; import { ClientTransactionResponse } from '../types'; import { getSignature } from '../utils/signature'; import { ViemClient } from '../viem'; -import { getProposalById } from './graphql'; +import { getAllProposalsByServiceId, getAllProposalsByUser, getProposalById } from './graphql'; import { CreateProposalArgs, ProposalDetails } from './types'; export class Proposal { @@ -40,6 +40,22 @@ export class Proposal { return null; } + public async getByServiceId(serviceId: string): Promise { + const query = getAllProposalsByServiceId(serviceId) + + const response = await this.graphQlClient.get(query); + + return response?.data?.proposals || null + } + + public async getByUser(userId: string): Promise { + const query = getAllProposalsByUser(userId) + + const response = await this.graphQlClient.get(query); + + return response?.data?.proposals || null + } + public async getSignature(args: CreateProposalArgs): Promise { return getSignature('createProposal', args, this.signatureApiUrl); } diff --git a/packages/client/src/proposals/types/index.ts b/packages/client/src/proposals/types/index.ts index 9536ae9..d0f8519 100644 --- a/packages/client/src/proposals/types/index.ts +++ b/packages/client/src/proposals/types/index.ts @@ -1,4 +1,4 @@ -import { ClientTransactionResponse } from '../../types'; +import { ClientTransactionResponse } from "../../types"; export type ProposalDetails = { about: string; @@ -17,13 +17,17 @@ export interface IProposal { getOne(proposalId: string): Promise; + getByServiceId(serviceId: string): Promise; + + getByUser(userId: string): Promise; + create( proposalDetails: ProposalDetails, userId: string, serviceId: string, rateToken: string, rateAmount: string, - expirationDate: string, + expirationDate: string ): Promise; update( @@ -32,7 +36,7 @@ export interface IProposal { serviceId: string, rateToken: string, rateAmount: string, - expirationDate: string, + expirationDate: string ): Promise; upload(proposalDetails: ProposalDetails): Promise; From 2bc31c3eb61d703febe7fc321caffc3f53e13d21 Mon Sep 17 00:00:00 2001 From: Spandan Barve Date: Mon, 23 Oct 2023 16:08:51 +0530 Subject: [PATCH 02/12] Added user queries to client --- packages/client/src/index.ts | 18 +++ packages/client/src/users/graphql/index.ts | 122 +++++++++++++++++++++ packages/client/src/users/index.ts | 56 ++++++++++ packages/client/src/users/types/index.ts | 11 ++ 4 files changed, 207 insertions(+) create mode 100644 packages/client/src/users/graphql/index.ts create mode 100644 packages/client/src/users/index.ts create mode 100644 packages/client/src/users/types/index.ts diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 114260b..1071f88 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -18,6 +18,8 @@ import { IEscrow } from './escrow/types'; import { IService, Service } from './services'; import { IReview } from './review/types'; import { Review } from './review'; +import { IUser } from './users/types'; +import { User } from './users'; /** * Main client for interacting with the TalentLayer protocol. @@ -139,4 +141,20 @@ export class TalentLayerClient { this.chainId, ); } + + /** + * Provides access to user functionalities. + * @type {IUser} + */ + + // @ts-ignore + get user(): IUser { + return new User( + this.graphQlClient, + this.ipfsClient, + this.viemClient, + this.platformID, + this.signatureApiUrl, + ); + } } diff --git a/packages/client/src/users/graphql/index.ts b/packages/client/src/users/graphql/index.ts new file mode 100644 index 0000000..376e933 --- /dev/null +++ b/packages/client/src/users/graphql/index.ts @@ -0,0 +1,122 @@ +export const getUsers = ( + numberPerPage?: number, + offset?: number, + searchQuery?: string +) => { + const pagination = numberPerPage + ? "first: " + numberPerPage + ", skip: " + offset + : ""; + let condition = ", where: {"; + condition += searchQuery ? `, handle_contains_nocase: "${searchQuery}"` : ""; + condition += "}"; + + return ` + { + users(orderBy: rating, orderDirection: desc ${pagination} ${condition}) { + id + address + handle + userStats { + numReceivedReviews + } + rating + } + } + `; +}; + +export const getUserById = (id: string) => ` +{ + user(id: "${id}") { + id + address + handle + rating + delegates + userStats { + numReceivedReviews + } + updatedAt + createdAt + description { + about + role + name + country + headline + id + image_url + video_url + title + timezone + skills_raw + web3mailPreferences{ + activeOnNewService + activeOnNewProposal + activeOnProposalValidated + activeOnFundRelease + activeOnReview + activeOnPlatformMarketing + activeOnProtocolMarketing + } + } + } +} +`; + +export const getUserByAddress = (address: string) => ` +{ + users(where: {address: "${address.toLocaleLowerCase()}"}, first: 1) { + id + address + handle + rating + delegates + userStats { + numReceivedReviews + } + updatedAt + createdAt + description { + about + role + name + country + headline + id + image_url + video_url + title + timezone + skills_raw + web3mailPreferences{ + activeOnNewService + activeOnNewProposal + activeOnProposalValidated + activeOnFundRelease + activeOnReview + activeOnPlatformMarketing + activeOnProtocolMarketing + } + } + } +} +`; + +export const getUserTotalGains = (id: string) => ` +{ + user(id: "${id}") { + totalGains{ + id + totalGain + token { + id + name + symbol + decimals + } + } + } +} +`; + diff --git a/packages/client/src/users/index.ts b/packages/client/src/users/index.ts new file mode 100644 index 0000000..24b71b5 --- /dev/null +++ b/packages/client/src/users/index.ts @@ -0,0 +1,56 @@ +import GraphQLClient from "../graphql"; +import IPFSClient from "../ipfs"; +import { ViemClient } from "../viem"; +import { getUserById, getUserTotalGains, getUsers } from "./graphql"; + +export class User { + graphQlClient: GraphQLClient; + ipfsClient: IPFSClient; + viemClient: ViemClient; + platformID: number; + signatureApiUrl?: string; + + constructor( + graphQlClient: GraphQLClient, + ipfsClient: IPFSClient, + viemClient: ViemClient, + platformId: number, + signatureApiUrl?: string + ) { + this.graphQlClient = graphQlClient; + this.platformID = platformId; + this.ipfsClient = ipfsClient; + this.viemClient = viemClient; + this.signatureApiUrl = signatureApiUrl; + } + + public async getOne(userId: string): Promise { + const query = getUserById(userId); + + const response = await this.graphQlClient.get(query); + + return response?.data?.user || null; + } + + public async getUsers(params: { + numberPerPage?: number; + offset?: number; + searchQuery?: string; + }): Promise { + const query = getUsers( + params.numberPerPage, + params.offset, + params.searchQuery + ); + + return this.graphQlClient.get(query); + } + + public async getTotalGains(userId: string): Promise { + const query = getUserTotalGains(userId); + + const response = await this.graphQlClient.get(query); + + return response?.data?.user?.totalGains || null; + } +} diff --git a/packages/client/src/users/types/index.ts b/packages/client/src/users/types/index.ts new file mode 100644 index 0000000..20d933a --- /dev/null +++ b/packages/client/src/users/types/index.ts @@ -0,0 +1,11 @@ +export interface IUser { + getOne(userId: string): Promise; + + getUsers(params: { + numberPerPage?: number; + offset?: number; + searchQuery?: string; + }): Promise; + + getTotalGains(userId: string): Promise; +} From 4430664adb5324053526e6fd605daa6c96093a9f Mon Sep 17 00:00:00 2001 From: Spandan Barve Date: Mon, 23 Oct 2023 16:09:46 +0530 Subject: [PATCH 03/12] fix typo - incorect type --- packages/client/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 1071f88..3ae0c6b 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -95,7 +95,7 @@ export class TalentLayerClient { /** * Provides access to service functionalities. - * @type {IDispute} + * @type {IService} */ // @ts-ignore From e51011df5e2678feff37985c9d3d322d660ce7cf Mon Sep 17 00:00:00 2001 From: Spandan Barve Date: Mon, 23 Oct 2023 16:34:27 +0530 Subject: [PATCH 04/12] Add fees queries to client --- packages/client/src/fees/graphql/index.ts | 16 ++ packages/client/src/fees/index.ts | 52 ++++++ packages/client/src/fees/types/index.ts | 8 + packages/client/src/index.ts | 18 ++ packages/client/src/ipfs/index.ts | 16 +- .../client/src/proposals/graphql/index.ts | 164 +++++++++--------- packages/client/src/viem/index.ts | 16 +- 7 files changed, 192 insertions(+), 98 deletions(-) create mode 100644 packages/client/src/fees/graphql/index.ts create mode 100644 packages/client/src/fees/index.ts create mode 100644 packages/client/src/fees/types/index.ts diff --git a/packages/client/src/fees/graphql/index.ts b/packages/client/src/fees/graphql/index.ts new file mode 100644 index 0000000..0b7784f --- /dev/null +++ b/packages/client/src/fees/graphql/index.ts @@ -0,0 +1,16 @@ +export const getProtocolAndPlatformsFees = ( + originServicePlatformId: string, + originValidatedProposalPlatformId: string, +) => ` + { + protocols { + protocolEscrowFeeRate + } + servicePlatform: platform(id:${originServicePlatformId}){ + originServiceFeeRate + } + proposalPlatform: platform(id:${originValidatedProposalPlatformId}){ + originValidatedProposalFeeRate + } + } + `; diff --git a/packages/client/src/fees/index.ts b/packages/client/src/fees/index.ts new file mode 100644 index 0000000..b36092a --- /dev/null +++ b/packages/client/src/fees/index.ts @@ -0,0 +1,52 @@ +import GraphQLClient from '../graphql'; +import IPFSClient from '../ipfs'; +import { ViemClient } from '../viem'; +import { getProtocolAndPlatformsFees } from './graphql'; + +export class Fees { + graphQlClient: GraphQLClient; + ipfsClient: IPFSClient; + viemClient: ViemClient; + platformID: number; + signatureApiUrl?: string; + + constructor( + graphQlClient: GraphQLClient, + ipfsClient: IPFSClient, + viemClient: ViemClient, + platformId: number, + signatureApiUrl?: string, + ) { + this.graphQlClient = graphQlClient; + this.platformID = platformId; + this.ipfsClient = ipfsClient; + this.viemClient = viemClient; + this.signatureApiUrl = signatureApiUrl; + } + + public async getMintFees(): Promise { + const query = ` + { + protocols { + userMintFee, + shortHandlesMaxPrice + } + } + `; + + const response = await this.graphQlClient.get(query); + + return response?.data || null; + } + + public async getProtocolAndPlatformsFees( + originServicePlatformId: string, + originValidatedProposalPlatformId: string, + ): Promise { + const query = getProtocolAndPlatformsFees(originServicePlatformId, originValidatedProposalPlatformId); + + const response = await this.graphQlClient.get(query); + + return response?.data || null; + } +} diff --git a/packages/client/src/fees/types/index.ts b/packages/client/src/fees/types/index.ts new file mode 100644 index 0000000..2c2bf40 --- /dev/null +++ b/packages/client/src/fees/types/index.ts @@ -0,0 +1,8 @@ +export interface IFees { + getMintFees(): Promise; + + getProtocolAndPlatformsFees( + originServicePlatformId: string, + originValidatedProposalPlatformId: string, + ): Promise; +} diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 3ae0c6b..3164c85 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -20,6 +20,8 @@ import { IReview } from './review/types'; import { Review } from './review'; import { IUser } from './users/types'; import { User } from './users'; +import { IFees } from './fees/types'; +import { Fees } from './fees'; /** * Main client for interacting with the TalentLayer protocol. @@ -157,4 +159,20 @@ export class TalentLayerClient { this.signatureApiUrl, ); } + + /** + * Provides access to user functionalities. + * @type {IFees} + */ + + // @ts-ignore + get fees(): IFees { + return new Fees( + this.graphQlClient, + this.ipfsClient, + this.viemClient, + this.platformID, + this.signatureApiUrl, + ); + } } diff --git a/packages/client/src/ipfs/index.ts b/packages/client/src/ipfs/index.ts index 490505b..94e8c59 100644 --- a/packages/client/src/ipfs/index.ts +++ b/packages/client/src/ipfs/index.ts @@ -10,14 +10,14 @@ export default class IPFSClient { const authorization = 'Basic ' + btoa(ipfsClientConfig.clientId + ':' + ipfsClientConfig.clientSecret); this.authorization = authorization; - import('ipfs-http-client').then(({ create }) => { - this.ipfs = create({ - url: ipfsClientConfig.baseUrl, - headers: { - authorization, - }, - }); - }); + // import('ipfs-http-client').then(({ create }) => { + // this.ipfs = create({ + // url: ipfsClientConfig.baseUrl, + // headers: { + // authorization, + // }, + // }); + // }); } public async post(data: string): Promise { diff --git a/packages/client/src/proposals/graphql/index.ts b/packages/client/src/proposals/graphql/index.ts index 30b3213..9b2f81b 100644 --- a/packages/client/src/proposals/graphql/index.ts +++ b/packages/client/src/proposals/graphql/index.ts @@ -37,90 +37,90 @@ export const getProposalById = (id: string) => ` `; export const getAllProposalsByServiceId = (id: string) => ` -{ - proposals(where: {service_: {id: "${id}"}}) { - service { - id, - cid - buyer { - id - } - platform { + { + proposals(where: {service_: {id: "${id}"}}) { + service { + id, + cid + buyer { + id + } + platform { + id + } + } + cid id + status + rateToken { + address + decimals + name + symbol + } + rateAmount + createdAt + updatedAt + seller { + id + handle + address + cid + rating + userStats { + numReceivedReviews + } + } + description { + id + about + expectedHours + startDate + video_url + } + expirationDate + platform { + id + } } } - cid - id - status - rateToken { - address - decimals - name - symbol - } - rateAmount - createdAt - updatedAt - seller { - id - handle - address - cid - rating - userStats { - numReceivedReviews - } - } - description { - id - about - expectedHours - startDate - video_url - } - expirationDate - platform { - id - } - } -} -`; + `; export const getAllProposalsByUser = (id: string) => ` -{ - proposals(where: {seller: "${id}", status: "Pending"}) { - id - rateAmount - rateToken { - address - decimals - name - symbol - } - status - cid - createdAt - seller { - id - handle - } - service { - id - cid - createdAt - buyer { - id - handle - } - } - description { - id - about - expectedHours - startDate - video_url - } - expirationDate - } - } -`; + { + proposals(where: {seller: "${id}", status: "Pending"}) { + id + rateAmount + rateToken { + address + decimals + name + symbol + } + status + cid + createdAt + seller { + id + handle + } + service { + id + cid + createdAt + buyer { + id + handle + } + } + description { + id + about + expectedHours + startDate + video_url + } + expirationDate + } + } + `; diff --git a/packages/client/src/viem/index.ts b/packages/client/src/viem/index.ts index a0367de..d7e7c76 100644 --- a/packages/client/src/viem/index.ts +++ b/packages/client/src/viem/index.ts @@ -63,14 +63,14 @@ export class ViemClient { } // @ts-ignore - let browserProvider = globalThis?.ethereum || window?.ethereum; - if (browserProvider) { - this.client = createWalletClient({ - chain: chains[this.chainId], - transport: custom(browserProvider), - }); - return true; - } + // let browserProvider = globalThis?.ethereum || window?.ethereum; + // if (browserProvider) { + // this.client = createWalletClient({ + // chain: chains[this.chainId], + // transport: custom(browserProvider), + // }); + // return true; + // } return false; } From b145b078bd3a4433f3e9ee64e72dd7c32e420274 Mon Sep 17 00:00:00 2001 From: Spandan Barve Date: Mon, 23 Oct 2023 16:44:22 +0530 Subject: [PATCH 05/12] Added getReviews to services in client --- .../client/src/services/graphql/queries.ts | 22 +++++++++++++++++++ packages/client/src/services/index.ts | 10 +++++++++ 2 files changed, 32 insertions(+) diff --git a/packages/client/src/services/graphql/queries.ts b/packages/client/src/services/graphql/queries.ts index 58a1957..fc70950 100644 --- a/packages/client/src/services/graphql/queries.ts +++ b/packages/client/src/services/graphql/queries.ts @@ -1,5 +1,27 @@ import { IProps } from '../types'; +export const getReviewsByService = (serviceId: string) => ` +{ + reviews(where: { service: "${serviceId}" }, orderBy: id, orderDirection: desc) { + id + rating + createdAt + service { + id + status + } + to { + id + handle + } + description{ + id + content + } + } +} +`; + export const getFilteredServiceDescriptionCondition = (params: IProps): string => { let condition = ', where: {'; condition += params.serviceStatus ? `service_: {status:"${params.serviceStatus}"}` : ''; diff --git a/packages/client/src/services/index.ts b/packages/client/src/services/index.ts index c46a866..db2a7e9 100644 --- a/packages/client/src/services/index.ts +++ b/packages/client/src/services/index.ts @@ -7,6 +7,7 @@ import { ViemClient } from '../viem'; import { getFilteredServiceCondition, getFilteredServiceDescriptionCondition, + getReviewsByService, } from './graphql/queries'; import { ICreateServiceSignature, IProps, ServiceDetails } from './types'; @@ -19,6 +20,7 @@ export interface IService { ): Promise; updloadServiceDataToIpfs(serviceData: ServiceDetails): Promise; getServices(params: IProps): Promise; + getServiceReviews(serviceId: string): Promise; search(params: IProps): Promise; } @@ -92,6 +94,14 @@ export class Service { return this.graphQlClient.get(query); } + public async getServiceReviews(serviceId: string): Promise { + const query = getReviewsByService(serviceId); + + const response = await this.graphQlClient.get(query); + + return response?.data || null; + } + public async search(params: IProps): Promise { const pagination = params.numberPerPage ? 'first: ' + params.numberPerPage + ' skip: ' + params.offset From e34265b8043e67a65c60ab82e9b647deb05961f4 Mon Sep 17 00:00:00 2001 From: Spandan Barve Date: Mon, 23 Oct 2023 16:52:28 +0530 Subject: [PATCH 06/12] add getPayments to services in client --- .../client/src/services/graphql/queries.ts | 24 +++++++++++++++++++ packages/client/src/services/index.ts | 10 ++++++++ 2 files changed, 34 insertions(+) diff --git a/packages/client/src/services/graphql/queries.ts b/packages/client/src/services/graphql/queries.ts index fc70950..5550a54 100644 --- a/packages/client/src/services/graphql/queries.ts +++ b/packages/client/src/services/graphql/queries.ts @@ -22,6 +22,30 @@ export const getReviewsByService = (serviceId: string) => ` } `; +export const getPaymentsByService = (serviceId: string, paymentType?: string) => { + let condition = `where: {service: "${serviceId}"`; + paymentType ? (condition += `, paymentType: "${paymentType}"`) : ''; + condition += '}, orderBy: id, orderDirection: asc'; + const query = ` + { + payments(${condition}) { + id + amount + rateToken { + address + decimals + name + symbol + } + paymentType + transactionHash + createdAt + } + } + `; + return query; +}; + export const getFilteredServiceDescriptionCondition = (params: IProps): string => { let condition = ', where: {'; condition += params.serviceStatus ? `service_: {status:"${params.serviceStatus}"}` : ''; diff --git a/packages/client/src/services/index.ts b/packages/client/src/services/index.ts index db2a7e9..37fdb57 100644 --- a/packages/client/src/services/index.ts +++ b/packages/client/src/services/index.ts @@ -7,6 +7,7 @@ import { ViemClient } from '../viem'; import { getFilteredServiceCondition, getFilteredServiceDescriptionCondition, + getPaymentsByService, getReviewsByService, } from './graphql/queries'; import { ICreateServiceSignature, IProps, ServiceDetails } from './types'; @@ -21,6 +22,7 @@ export interface IService { updloadServiceDataToIpfs(serviceData: ServiceDetails): Promise; getServices(params: IProps): Promise; getServiceReviews(serviceId: string): Promise; + getServicePayments(serviceId: string, paymentType?: string): Promise search(params: IProps): Promise; } @@ -102,6 +104,14 @@ export class Service { return response?.data || null; } + public async getServicePayments(serviceId: string, paymentType?: string): Promise { + const query = getPaymentsByService(serviceId, paymentType); + + const response = await this.graphQlClient.get(query); + + return response?.data?.payments || null + } + public async search(params: IProps): Promise { const pagination = params.numberPerPage ? 'first: ' + params.numberPerPage + ' skip: ' + params.offset From 5f6e144e1f9891625d53a144cde57a850a7c9fca Mon Sep 17 00:00:00 2001 From: Spandan Barve Date: Mon, 23 Oct 2023 16:56:51 +0530 Subject: [PATCH 07/12] add payments query to users in client --- packages/client/src/users/graphql/index.ts | 56 +++++++++++++++++----- packages/client/src/users/index.ts | 30 ++++++++---- packages/client/src/users/types/index.ts | 2 + 3 files changed, 67 insertions(+), 21 deletions(-) diff --git a/packages/client/src/users/graphql/index.ts b/packages/client/src/users/graphql/index.ts index 376e933..dbbc050 100644 --- a/packages/client/src/users/graphql/index.ts +++ b/packages/client/src/users/graphql/index.ts @@ -1,14 +1,8 @@ -export const getUsers = ( - numberPerPage?: number, - offset?: number, - searchQuery?: string -) => { - const pagination = numberPerPage - ? "first: " + numberPerPage + ", skip: " + offset - : ""; - let condition = ", where: {"; - condition += searchQuery ? `, handle_contains_nocase: "${searchQuery}"` : ""; - condition += "}"; +export const getUsers = (numberPerPage?: number, offset?: number, searchQuery?: string) => { + const pagination = numberPerPage ? 'first: ' + numberPerPage + ', skip: ' + offset : ''; + let condition = ', where: {'; + condition += searchQuery ? `, handle_contains_nocase: "${searchQuery}"` : ''; + condition += '}'; return ` { @@ -120,3 +114,43 @@ export const getUserTotalGains = (id: string) => ` } `; +export const getPaymentsForUser = ( + userId: string, + numberPerPage?: number, + offset?: number, + startDate?: string, + endDate?: string, +) => { + const pagination = numberPerPage ? 'first: ' + numberPerPage + ', skip: ' + offset : ''; + + const startDataCondition = startDate ? `, createdAt_gte: "${startDate}"` : ''; + const endDateCondition = endDate ? `, createdAt_lte: "${endDate}"` : ''; + + const query = ` + { + payments(where: { + service_: {seller: "${userId}"} + ${startDataCondition} + ${endDateCondition} + }, + orderBy: createdAt orderDirection: desc ${pagination} ) { + id, + rateToken { + address + decimals + name + symbol + } + amount + transactionHash + paymentType + createdAt + service { + id, + cid + } + } + } + `; + return query; +}; diff --git a/packages/client/src/users/index.ts b/packages/client/src/users/index.ts index 24b71b5..fe78f83 100644 --- a/packages/client/src/users/index.ts +++ b/packages/client/src/users/index.ts @@ -1,7 +1,7 @@ -import GraphQLClient from "../graphql"; -import IPFSClient from "../ipfs"; -import { ViemClient } from "../viem"; -import { getUserById, getUserTotalGains, getUsers } from "./graphql"; +import GraphQLClient from '../graphql'; +import IPFSClient from '../ipfs'; +import { ViemClient } from '../viem'; +import { getPaymentsForUser, getUserById, getUserTotalGains, getUsers } from './graphql'; export class User { graphQlClient: GraphQLClient; @@ -15,7 +15,7 @@ export class User { ipfsClient: IPFSClient, viemClient: ViemClient, platformId: number, - signatureApiUrl?: string + signatureApiUrl?: string, ) { this.graphQlClient = graphQlClient; this.platformID = platformId; @@ -37,11 +37,7 @@ export class User { offset?: number; searchQuery?: string; }): Promise { - const query = getUsers( - params.numberPerPage, - params.offset, - params.searchQuery - ); + const query = getUsers(params.numberPerPage, params.offset, params.searchQuery); return this.graphQlClient.get(query); } @@ -53,4 +49,18 @@ export class User { return response?.data?.user?.totalGains || null; } + + public async getPayments( + userId: string, + numberPerPage?: number, + offset?: number, + startDate?: string, + endDate?: string, + ): Promise { + const query = getPaymentsForUser(userId, numberPerPage, offset, startDate, endDate) + + const response = await this.graphQlClient.get(query); + + return response?.data?.payments || null + } } diff --git a/packages/client/src/users/types/index.ts b/packages/client/src/users/types/index.ts index 20d933a..88225f3 100644 --- a/packages/client/src/users/types/index.ts +++ b/packages/client/src/users/types/index.ts @@ -8,4 +8,6 @@ export interface IUser { }): Promise; getTotalGains(userId: string): Promise; + + getPayments(userId: string, numberPerPage?: number, offset?: number, startDate?: string, endDate?: string): Promise } From 823cc27bb61c899e4e202b7413dac5643187f7f0 Mon Sep 17 00:00:00 2001 From: Spandan Barve Date: Mon, 23 Oct 2023 16:57:36 +0530 Subject: [PATCH 08/12] fix accidentally commited commenting of ipfs and viem files --- packages/client/src/ipfs/index.ts | 16 ++++++++-------- packages/client/src/viem/index.ts | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/client/src/ipfs/index.ts b/packages/client/src/ipfs/index.ts index 94e8c59..490505b 100644 --- a/packages/client/src/ipfs/index.ts +++ b/packages/client/src/ipfs/index.ts @@ -10,14 +10,14 @@ export default class IPFSClient { const authorization = 'Basic ' + btoa(ipfsClientConfig.clientId + ':' + ipfsClientConfig.clientSecret); this.authorization = authorization; - // import('ipfs-http-client').then(({ create }) => { - // this.ipfs = create({ - // url: ipfsClientConfig.baseUrl, - // headers: { - // authorization, - // }, - // }); - // }); + import('ipfs-http-client').then(({ create }) => { + this.ipfs = create({ + url: ipfsClientConfig.baseUrl, + headers: { + authorization, + }, + }); + }); } public async post(data: string): Promise { diff --git a/packages/client/src/viem/index.ts b/packages/client/src/viem/index.ts index d7e7c76..a0367de 100644 --- a/packages/client/src/viem/index.ts +++ b/packages/client/src/viem/index.ts @@ -63,14 +63,14 @@ export class ViemClient { } // @ts-ignore - // let browserProvider = globalThis?.ethereum || window?.ethereum; - // if (browserProvider) { - // this.client = createWalletClient({ - // chain: chains[this.chainId], - // transport: custom(browserProvider), - // }); - // return true; - // } + let browserProvider = globalThis?.ethereum || window?.ethereum; + if (browserProvider) { + this.client = createWalletClient({ + chain: chains[this.chainId], + transport: custom(browserProvider), + }); + return true; + } return false; } From a288310f704ff08b1a1fdbebdf76941403be516c Mon Sep 17 00:00:00 2001 From: Spandan Barve Date: Sat, 28 Oct 2023 15:57:41 +0530 Subject: [PATCH 09/12] Addressing reviews --- packages/client/src/escrow/graphql/queries.ts | 24 +++ packages/client/src/escrow/index.ts | 36 +++- packages/client/src/escrow/types/index.ts | 5 + packages/client/src/fees/graphql/index.ts | 16 -- packages/client/src/fees/index.ts | 52 ------ packages/client/src/fees/types/index.ts | 8 - packages/client/src/profile/graphql/index.ts | 118 +++++++++++++ packages/client/src/profile/index.ts | 57 ++++++- packages/client/src/profile/types/index.ts | 9 + .../client/src/proposals/graphql/index.ts | 160 +++++++++--------- packages/client/src/reviews/graphql/index.ts | 21 +++ .../client/src/{review => reviews}/index.ts | 9 + .../src/{review => reviews}/types/index.ts | 2 + .../client/src/services/graphql/queries.ts | 46 ----- packages/client/src/services/index.ts | 18 -- packages/client/src/users/graphql/index.ts | 156 ----------------- packages/client/src/users/index.ts | 66 -------- packages/client/src/users/types/index.ts | 13 -- 18 files changed, 352 insertions(+), 464 deletions(-) delete mode 100644 packages/client/src/fees/graphql/index.ts delete mode 100644 packages/client/src/fees/index.ts delete mode 100644 packages/client/src/fees/types/index.ts create mode 100644 packages/client/src/reviews/graphql/index.ts rename packages/client/src/{review => reviews}/index.ts (83%) rename packages/client/src/{review => reviews}/types/index.ts (85%) delete mode 100644 packages/client/src/users/graphql/index.ts delete mode 100644 packages/client/src/users/index.ts delete mode 100644 packages/client/src/users/types/index.ts diff --git a/packages/client/src/escrow/graphql/queries.ts b/packages/client/src/escrow/graphql/queries.ts index e17d9a2..9a71ca4 100644 --- a/packages/client/src/escrow/graphql/queries.ts +++ b/packages/client/src/escrow/graphql/queries.ts @@ -14,3 +14,27 @@ export const getProtocolAndPlatformsFees = ( } } `; + +export const getPaymentsByService = (serviceId: string, paymentType?: string) => { + let condition = `where: {service: "${serviceId}"`; + paymentType ? (condition += `, paymentType: "${paymentType}"`) : ''; + condition += '}, orderBy: id, orderDirection: asc'; + const query = ` + { + payments(${condition}) { + id + amount + rateToken { + address + decimals + name + symbol + } + paymentType + transactionHash + createdAt + } + } + `; + return query; +}; diff --git a/packages/client/src/escrow/index.ts b/packages/client/src/escrow/index.ts index 5264347..b3977d5 100644 --- a/packages/client/src/escrow/index.ts +++ b/packages/client/src/escrow/index.ts @@ -6,7 +6,7 @@ import { Service } from '../services'; import { ClientTransactionResponse, NetworkEnum, RateToken } from '../types'; import { calculateApprovalAmount } from '../utils/fees'; import { ViemClient } from '../viem'; -import { getProtocolAndPlatformsFees } from './graphql/queries'; +import { getPaymentsByService, getProtocolAndPlatformsFees } from './graphql/queries'; export class Escrow { graphQlClient: GraphQLClient; @@ -59,21 +59,21 @@ export class Escrow { let tx, cid = proposal.cid; - const protocolAndPlatformsFeesResponse = await this.graphQlClient.get( - getProtocolAndPlatformsFees(proposal.service.platform.id, proposal.platform.id), + const protocolAndPlatformsFees = await this.getProtocolAndPlatformsFees( + proposal.service.platform.id, proposal.platform.id ); - console.log('SDK: fees', protocolAndPlatformsFeesResponse); + console.log('SDK: fees', protocolAndPlatformsFees); - if (!protocolAndPlatformsFeesResponse.data) { + if (!protocolAndPlatformsFees.data) { throw Error('Unable to fetch fees'); } const approvalAmount = calculateApprovalAmount( proposal.rateAmount, - protocolAndPlatformsFeesResponse.data.servicePlatform.originServiceFeeRate, - protocolAndPlatformsFeesResponse.data.proposalPlatform.originValidatedProposalFeeRate, - protocolAndPlatformsFeesResponse.data.protocols[0].protocolEscrowFeeRate, + protocolAndPlatformsFees.servicePlatform.originServiceFeeRate, + protocolAndPlatformsFees.proposalPlatform.originValidatedProposalFeeRate, + protocolAndPlatformsFees.protocols[0].protocolEscrowFeeRate, ); console.log('SDK: escrow seeking approval for amount: ', approvalAmount); @@ -187,4 +187,24 @@ export class Escrow { return tx; } + + public async getProtocolAndPlatformsFees( + originServicePlatformId: string, + originValidatedProposalPlatformId: string, + ): Promise { + const query = getProtocolAndPlatformsFees(originServicePlatformId, originValidatedProposalPlatformId); + + const response = await this.graphQlClient.get(query); + + return response?.data || null; + } + + public async getByService(serviceId: string, paymentType?: string): Promise { + const query = getPaymentsByService(serviceId, paymentType); + + const response = await this.graphQlClient.get(query); + + return response?.data?.payments || null + } + } diff --git a/packages/client/src/escrow/types/index.ts b/packages/client/src/escrow/types/index.ts index af6fdee..9e74b15 100644 --- a/packages/client/src/escrow/types/index.ts +++ b/packages/client/src/escrow/types/index.ts @@ -8,4 +8,9 @@ export interface IEscrow { ): Promise; release(serviceId: string, amount: bigint, userId: number): Promise; reimburse(serviceId: string, amount: bigint, userId: number): Promise; + getProtocolAndPlatformsFees( + originServicePlatformId: string, + originValidatedProposalPlatformId: string, + ): Promise; + getByService(serviceId: string, paymentType?: string): Promise; } diff --git a/packages/client/src/fees/graphql/index.ts b/packages/client/src/fees/graphql/index.ts deleted file mode 100644 index 0b7784f..0000000 --- a/packages/client/src/fees/graphql/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -export const getProtocolAndPlatformsFees = ( - originServicePlatformId: string, - originValidatedProposalPlatformId: string, -) => ` - { - protocols { - protocolEscrowFeeRate - } - servicePlatform: platform(id:${originServicePlatformId}){ - originServiceFeeRate - } - proposalPlatform: platform(id:${originValidatedProposalPlatformId}){ - originValidatedProposalFeeRate - } - } - `; diff --git a/packages/client/src/fees/index.ts b/packages/client/src/fees/index.ts deleted file mode 100644 index b36092a..0000000 --- a/packages/client/src/fees/index.ts +++ /dev/null @@ -1,52 +0,0 @@ -import GraphQLClient from '../graphql'; -import IPFSClient from '../ipfs'; -import { ViemClient } from '../viem'; -import { getProtocolAndPlatformsFees } from './graphql'; - -export class Fees { - graphQlClient: GraphQLClient; - ipfsClient: IPFSClient; - viemClient: ViemClient; - platformID: number; - signatureApiUrl?: string; - - constructor( - graphQlClient: GraphQLClient, - ipfsClient: IPFSClient, - viemClient: ViemClient, - platformId: number, - signatureApiUrl?: string, - ) { - this.graphQlClient = graphQlClient; - this.platformID = platformId; - this.ipfsClient = ipfsClient; - this.viemClient = viemClient; - this.signatureApiUrl = signatureApiUrl; - } - - public async getMintFees(): Promise { - const query = ` - { - protocols { - userMintFee, - shortHandlesMaxPrice - } - } - `; - - const response = await this.graphQlClient.get(query); - - return response?.data || null; - } - - public async getProtocolAndPlatformsFees( - originServicePlatformId: string, - originValidatedProposalPlatformId: string, - ): Promise { - const query = getProtocolAndPlatformsFees(originServicePlatformId, originValidatedProposalPlatformId); - - const response = await this.graphQlClient.get(query); - - return response?.data || null; - } -} diff --git a/packages/client/src/fees/types/index.ts b/packages/client/src/fees/types/index.ts deleted file mode 100644 index 2c2bf40..0000000 --- a/packages/client/src/fees/types/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface IFees { - getMintFees(): Promise; - - getProtocolAndPlatformsFees( - originServicePlatformId: string, - originValidatedProposalPlatformId: string, - ): Promise; -} diff --git a/packages/client/src/profile/graphql/index.ts b/packages/client/src/profile/graphql/index.ts index 1d9b87d..1f5ef51 100644 --- a/packages/client/src/profile/graphql/index.ts +++ b/packages/client/src/profile/graphql/index.ts @@ -30,3 +30,121 @@ export const getProfileByAddress = (address: Hash) => } } `; + +export const getProfiles = (numberPerPage?: number, offset?: number, searchQuery?: string) => { + const pagination = numberPerPage ? 'first: ' + numberPerPage + ', skip: ' + offset : ''; + let condition = ', where: {'; + condition += searchQuery ? `, handle_contains_nocase: "${searchQuery}"` : ''; + condition += '}'; + + return ` + { + users(orderBy: rating, orderDirection: desc ${pagination} ${condition}) { + id + address + handle + userStats { + numReceivedReviews + } + rating + } + } + `; +}; + +export const getProfileById = (id: string) => ` + { + user(id: "${id}") { + id + address + handle + rating + delegates + userStats { + numReceivedReviews + } + updatedAt + createdAt + description { + about + role + name + country + headline + id + image_url + video_url + title + timezone + skills_raw + web3mailPreferences{ + activeOnNewService + activeOnNewProposal + activeOnProposalValidated + activeOnFundRelease + activeOnReview + activeOnPlatformMarketing + activeOnProtocolMarketing + } + } + } + } + `; + +export const getUserTotalGains = (id: string) => ` + { + user(id: "${id}") { + totalGains{ + id + totalGain + token { + id + name + symbol + decimals + } + } + } + } + `; + +export const getPaymentsForUser = ( + userId: string, + numberPerPage?: number, + offset?: number, + startDate?: string, + endDate?: string, +) => { + const pagination = numberPerPage ? 'first: ' + numberPerPage + ', skip: ' + offset : ''; + + const startDataCondition = startDate ? `, createdAt_gte: "${startDate}"` : ''; + const endDateCondition = endDate ? `, createdAt_lte: "${endDate}"` : ''; + + const query = ` + { + payments(where: { + service_: {seller: "${userId}"} + ${startDataCondition} + ${endDateCondition} + }, + orderBy: createdAt orderDirection: desc ${pagination} ) { + id, + rateToken { + address + decimals + name + symbol + } + amount + transactionHash + paymentType + createdAt + service { + id, + cid + } + } + } + `; + return query; +}; diff --git a/packages/client/src/profile/index.ts b/packages/client/src/profile/index.ts index d9fe239..56b4b2f 100644 --- a/packages/client/src/profile/index.ts +++ b/packages/client/src/profile/index.ts @@ -4,7 +4,7 @@ import IPFSClient from '../ipfs'; import { getProtocolById } from '../platform/graphql/queries'; import { ClientTransactionResponse } from '../types'; import { ViemClient } from '../viem'; -import { getProfileByAddress } from './graphql'; +import { getPaymentsForUser, getProfileByAddress, getProfileById, getProfiles, getUserTotalGains } from './graphql'; import { TalentLayerProfile } from './types'; export class Profile { @@ -37,6 +37,14 @@ export class Profile { return null; } + + public async getById(userId: string): Promise { + const query = getProfileById(userId); + + const response = await this.graphQlClient.get(query); + + return response?.data?.user || null; + } public async upload(profileData: TalentLayerProfile): Promise { return this.ipfsClient.post(JSON.stringify(profileData)); @@ -84,4 +92,51 @@ export class Profile { BigInt(fee), ); } + + public async getUsers(params: { + numberPerPage?: number; + offset?: number; + searchQuery?: string; + }): Promise { + const query = getProfiles(params.numberPerPage, params.offset, params.searchQuery); + + return this.graphQlClient.get(query); + } + + public async getTotalGains(userId: string): Promise { + const query = getUserTotalGains(userId); + + const response = await this.graphQlClient.get(query); + + return response?.data?.user?.totalGains || null; + } + + public async getPayments( + userId: string, + numberPerPage?: number, + offset?: number, + startDate?: string, + endDate?: string, + ): Promise { + const query = getPaymentsForUser(userId, numberPerPage, offset, startDate, endDate) + + const response = await this.graphQlClient.get(query); + + return response?.data?.payments || null + } + + public async getMintFees(): Promise { + const query = ` + { + protocols { + userMintFee, + shortHandlesMaxPrice + } + } + `; + + const response = await this.graphQlClient.get(query); + + return response?.data || null; + } } diff --git a/packages/client/src/profile/types/index.ts b/packages/client/src/profile/types/index.ts index 55009ad..4a9ebf3 100644 --- a/packages/client/src/profile/types/index.ts +++ b/packages/client/src/profile/types/index.ts @@ -14,6 +14,15 @@ export type TalentLayerProfile = { export interface IProfile { upload(profileData: TalentLayerProfile): Promise; getByAddress(address: `0x${string}`): Promise; + getById(userId: string): Promise; create(handle: string): Promise; update(profileData: TalentLayerProfile, userId: string): Promise; + getUsers(params: { + numberPerPage?: number; + offset?: number; + searchQuery?: string; + }): Promise; + getTotalGains(userId: string): Promise; + getPayments(userId: string, numberPerPage?: number, offset?: number, startDate?: string, endDate?: string): Promise + getMintFees(): Promise; } diff --git a/packages/client/src/proposals/graphql/index.ts b/packages/client/src/proposals/graphql/index.ts index 9b2f81b..0ea655b 100644 --- a/packages/client/src/proposals/graphql/index.ts +++ b/packages/client/src/proposals/graphql/index.ts @@ -37,90 +37,90 @@ export const getProposalById = (id: string) => ` `; export const getAllProposalsByServiceId = (id: string) => ` - { - proposals(where: {service_: {id: "${id}"}}) { - service { - id, - cid - buyer { - id - } - platform { - id - } - } - cid +{ + proposals(where: {service_: {id: "${id}"}}) { + service { + id, + cid + buyer { id - status - rateToken { - address - decimals - name - symbol - } - rateAmount + } + platform { + id + } + } + cid + id + status + rateToken { + address + decimals + name + symbol + } + rateAmount + createdAt + updatedAt + seller { + id + handle + address + cid + rating + userStats { + numReceivedReviews + } + } + description { + id + about + expectedHours + startDate + video_url + } + expirationDate + platform { + id + } + } +} +`; + +export const getAllProposalsByUser = (id: string) => ` + { + proposals(where: {seller: "${id}", status: "Pending"}) { + id + rateAmount + rateToken { + address + decimals + name + symbol + } + status + cid + createdAt + seller { + id + handle + } + service { + id + cid createdAt - updatedAt - seller { + buyer { id handle - address - cid - rating - userStats { - numReceivedReviews - } - } - description { - id - about - expectedHours - startDate - video_url - } - expirationDate - platform { - id } } + description { + id + about + expectedHours + startDate + video_url + } + expirationDate } - `; - -export const getAllProposalsByUser = (id: string) => ` - { - proposals(where: {seller: "${id}", status: "Pending"}) { - id - rateAmount - rateToken { - address - decimals - name - symbol - } - status - cid - createdAt - seller { - id - handle - } - service { - id - cid - createdAt - buyer { - id - handle - } - } - description { - id - about - expectedHours - startDate - video_url - } - expirationDate - } - } - `; + } +`; diff --git a/packages/client/src/reviews/graphql/index.ts b/packages/client/src/reviews/graphql/index.ts new file mode 100644 index 0000000..c2bdb8b --- /dev/null +++ b/packages/client/src/reviews/graphql/index.ts @@ -0,0 +1,21 @@ +export const getReviewsByService = (serviceId: string) => ` +{ + reviews(where: { service: "${serviceId}" }, orderBy: id, orderDirection: desc) { + id + rating + createdAt + service { + id + status + } + to { + id + handle + } + description{ + id + content + } + } +} +`; diff --git a/packages/client/src/review/index.ts b/packages/client/src/reviews/index.ts similarity index 83% rename from packages/client/src/review/index.ts rename to packages/client/src/reviews/index.ts index 4dfb5f3..eaab44f 100644 --- a/packages/client/src/review/index.ts +++ b/packages/client/src/reviews/index.ts @@ -2,6 +2,7 @@ import GraphQLClient from '../graphql'; import IPFSClient from '../ipfs'; import { ClientTransactionResponse } from '../types'; import { ViemClient } from '../viem'; +import { getReviewsByService } from './graphql'; import { ReviewDetails } from './types'; export class Review { @@ -55,4 +56,12 @@ export class Review { throw new Error(Review.CREATE_ERROR); } + + public async getByService(serviceId: string): Promise { + const query = getReviewsByService(serviceId); + + const response = await this.graphQlClient.get(query); + + return response?.data || null; + } } diff --git a/packages/client/src/review/types/index.ts b/packages/client/src/reviews/types/index.ts similarity index 85% rename from packages/client/src/review/types/index.ts rename to packages/client/src/reviews/types/index.ts index 9995345..e0f2c88 100644 --- a/packages/client/src/review/types/index.ts +++ b/packages/client/src/reviews/types/index.ts @@ -12,4 +12,6 @@ export interface IReview { serviceId: string, userId: string, ): Promise; + + getByService(serviceId: string): Promise } diff --git a/packages/client/src/services/graphql/queries.ts b/packages/client/src/services/graphql/queries.ts index 5550a54..58a1957 100644 --- a/packages/client/src/services/graphql/queries.ts +++ b/packages/client/src/services/graphql/queries.ts @@ -1,51 +1,5 @@ import { IProps } from '../types'; -export const getReviewsByService = (serviceId: string) => ` -{ - reviews(where: { service: "${serviceId}" }, orderBy: id, orderDirection: desc) { - id - rating - createdAt - service { - id - status - } - to { - id - handle - } - description{ - id - content - } - } -} -`; - -export const getPaymentsByService = (serviceId: string, paymentType?: string) => { - let condition = `where: {service: "${serviceId}"`; - paymentType ? (condition += `, paymentType: "${paymentType}"`) : ''; - condition += '}, orderBy: id, orderDirection: asc'; - const query = ` - { - payments(${condition}) { - id - amount - rateToken { - address - decimals - name - symbol - } - paymentType - transactionHash - createdAt - } - } - `; - return query; -}; - export const getFilteredServiceDescriptionCondition = (params: IProps): string => { let condition = ', where: {'; condition += params.serviceStatus ? `service_: {status:"${params.serviceStatus}"}` : ''; diff --git a/packages/client/src/services/index.ts b/packages/client/src/services/index.ts index 37fdb57..fbeb013 100644 --- a/packages/client/src/services/index.ts +++ b/packages/client/src/services/index.ts @@ -7,8 +7,6 @@ import { ViemClient } from '../viem'; import { getFilteredServiceCondition, getFilteredServiceDescriptionCondition, - getPaymentsByService, - getReviewsByService, } from './graphql/queries'; import { ICreateServiceSignature, IProps, ServiceDetails } from './types'; @@ -96,22 +94,6 @@ export class Service { return this.graphQlClient.get(query); } - public async getServiceReviews(serviceId: string): Promise { - const query = getReviewsByService(serviceId); - - const response = await this.graphQlClient.get(query); - - return response?.data || null; - } - - public async getServicePayments(serviceId: string, paymentType?: string): Promise { - const query = getPaymentsByService(serviceId, paymentType); - - const response = await this.graphQlClient.get(query); - - return response?.data?.payments || null - } - public async search(params: IProps): Promise { const pagination = params.numberPerPage ? 'first: ' + params.numberPerPage + ' skip: ' + params.offset diff --git a/packages/client/src/users/graphql/index.ts b/packages/client/src/users/graphql/index.ts deleted file mode 100644 index dbbc050..0000000 --- a/packages/client/src/users/graphql/index.ts +++ /dev/null @@ -1,156 +0,0 @@ -export const getUsers = (numberPerPage?: number, offset?: number, searchQuery?: string) => { - const pagination = numberPerPage ? 'first: ' + numberPerPage + ', skip: ' + offset : ''; - let condition = ', where: {'; - condition += searchQuery ? `, handle_contains_nocase: "${searchQuery}"` : ''; - condition += '}'; - - return ` - { - users(orderBy: rating, orderDirection: desc ${pagination} ${condition}) { - id - address - handle - userStats { - numReceivedReviews - } - rating - } - } - `; -}; - -export const getUserById = (id: string) => ` -{ - user(id: "${id}") { - id - address - handle - rating - delegates - userStats { - numReceivedReviews - } - updatedAt - createdAt - description { - about - role - name - country - headline - id - image_url - video_url - title - timezone - skills_raw - web3mailPreferences{ - activeOnNewService - activeOnNewProposal - activeOnProposalValidated - activeOnFundRelease - activeOnReview - activeOnPlatformMarketing - activeOnProtocolMarketing - } - } - } -} -`; - -export const getUserByAddress = (address: string) => ` -{ - users(where: {address: "${address.toLocaleLowerCase()}"}, first: 1) { - id - address - handle - rating - delegates - userStats { - numReceivedReviews - } - updatedAt - createdAt - description { - about - role - name - country - headline - id - image_url - video_url - title - timezone - skills_raw - web3mailPreferences{ - activeOnNewService - activeOnNewProposal - activeOnProposalValidated - activeOnFundRelease - activeOnReview - activeOnPlatformMarketing - activeOnProtocolMarketing - } - } - } -} -`; - -export const getUserTotalGains = (id: string) => ` -{ - user(id: "${id}") { - totalGains{ - id - totalGain - token { - id - name - symbol - decimals - } - } - } -} -`; - -export const getPaymentsForUser = ( - userId: string, - numberPerPage?: number, - offset?: number, - startDate?: string, - endDate?: string, -) => { - const pagination = numberPerPage ? 'first: ' + numberPerPage + ', skip: ' + offset : ''; - - const startDataCondition = startDate ? `, createdAt_gte: "${startDate}"` : ''; - const endDateCondition = endDate ? `, createdAt_lte: "${endDate}"` : ''; - - const query = ` - { - payments(where: { - service_: {seller: "${userId}"} - ${startDataCondition} - ${endDateCondition} - }, - orderBy: createdAt orderDirection: desc ${pagination} ) { - id, - rateToken { - address - decimals - name - symbol - } - amount - transactionHash - paymentType - createdAt - service { - id, - cid - } - } - } - `; - return query; -}; diff --git a/packages/client/src/users/index.ts b/packages/client/src/users/index.ts deleted file mode 100644 index fe78f83..0000000 --- a/packages/client/src/users/index.ts +++ /dev/null @@ -1,66 +0,0 @@ -import GraphQLClient from '../graphql'; -import IPFSClient from '../ipfs'; -import { ViemClient } from '../viem'; -import { getPaymentsForUser, getUserById, getUserTotalGains, getUsers } from './graphql'; - -export class User { - graphQlClient: GraphQLClient; - ipfsClient: IPFSClient; - viemClient: ViemClient; - platformID: number; - signatureApiUrl?: string; - - constructor( - graphQlClient: GraphQLClient, - ipfsClient: IPFSClient, - viemClient: ViemClient, - platformId: number, - signatureApiUrl?: string, - ) { - this.graphQlClient = graphQlClient; - this.platformID = platformId; - this.ipfsClient = ipfsClient; - this.viemClient = viemClient; - this.signatureApiUrl = signatureApiUrl; - } - - public async getOne(userId: string): Promise { - const query = getUserById(userId); - - const response = await this.graphQlClient.get(query); - - return response?.data?.user || null; - } - - public async getUsers(params: { - numberPerPage?: number; - offset?: number; - searchQuery?: string; - }): Promise { - const query = getUsers(params.numberPerPage, params.offset, params.searchQuery); - - return this.graphQlClient.get(query); - } - - public async getTotalGains(userId: string): Promise { - const query = getUserTotalGains(userId); - - const response = await this.graphQlClient.get(query); - - return response?.data?.user?.totalGains || null; - } - - public async getPayments( - userId: string, - numberPerPage?: number, - offset?: number, - startDate?: string, - endDate?: string, - ): Promise { - const query = getPaymentsForUser(userId, numberPerPage, offset, startDate, endDate) - - const response = await this.graphQlClient.get(query); - - return response?.data?.payments || null - } -} diff --git a/packages/client/src/users/types/index.ts b/packages/client/src/users/types/index.ts deleted file mode 100644 index 88225f3..0000000 --- a/packages/client/src/users/types/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface IUser { - getOne(userId: string): Promise; - - getUsers(params: { - numberPerPage?: number; - offset?: number; - searchQuery?: string; - }): Promise; - - getTotalGains(userId: string): Promise; - - getPayments(userId: string, numberPerPage?: number, offset?: number, startDate?: string, endDate?: string): Promise -} From 04fd7cbbf2a8b96af8744ff2b747542d125cc2ec Mon Sep 17 00:00:00 2001 From: Spandan Barve Date: Sat, 28 Oct 2023 16:04:42 +0530 Subject: [PATCH 10/12] Used new changes in index.ts --- packages/client/src/index.ts | 40 ++------------------------- packages/client/src/services/index.ts | 2 -- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 3164c85..4ead8ce 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -16,12 +16,8 @@ import { IProfile } from './profile/types'; import { Escrow } from './escrow'; import { IEscrow } from './escrow/types'; import { IService, Service } from './services'; -import { IReview } from './review/types'; -import { Review } from './review'; -import { IUser } from './users/types'; -import { User } from './users'; -import { IFees } from './fees/types'; -import { Fees } from './fees'; +import { IReview } from './reviews/types'; +import { Review } from './reviews'; /** * Main client for interacting with the TalentLayer protocol. @@ -143,36 +139,4 @@ export class TalentLayerClient { this.chainId, ); } - - /** - * Provides access to user functionalities. - * @type {IUser} - */ - - // @ts-ignore - get user(): IUser { - return new User( - this.graphQlClient, - this.ipfsClient, - this.viemClient, - this.platformID, - this.signatureApiUrl, - ); - } - - /** - * Provides access to user functionalities. - * @type {IFees} - */ - - // @ts-ignore - get fees(): IFees { - return new Fees( - this.graphQlClient, - this.ipfsClient, - this.viemClient, - this.platformID, - this.signatureApiUrl, - ); - } } diff --git a/packages/client/src/services/index.ts b/packages/client/src/services/index.ts index fbeb013..c46a866 100644 --- a/packages/client/src/services/index.ts +++ b/packages/client/src/services/index.ts @@ -19,8 +19,6 @@ export interface IService { ): Promise; updloadServiceDataToIpfs(serviceData: ServiceDetails): Promise; getServices(params: IProps): Promise; - getServiceReviews(serviceId: string): Promise; - getServicePayments(serviceId: string, paymentType?: string): Promise search(params: IProps): Promise; } From c5739b6f8c90b17a417e6d1d9ffd89584acfcce2 Mon Sep 17 00:00:00 2001 From: Spandan Barve Date: Wed, 1 Nov 2023 22:36:22 +0530 Subject: [PATCH 11/12] updated profile service -> rename getUsers to getBy --- packages/client/src/profile/index.ts | 2 +- packages/client/src/profile/types/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/client/src/profile/index.ts b/packages/client/src/profile/index.ts index 56b4b2f..17094f5 100644 --- a/packages/client/src/profile/index.ts +++ b/packages/client/src/profile/index.ts @@ -93,7 +93,7 @@ export class Profile { ); } - public async getUsers(params: { + public async getBy(params: { numberPerPage?: number; offset?: number; searchQuery?: string; diff --git a/packages/client/src/profile/types/index.ts b/packages/client/src/profile/types/index.ts index 4a9ebf3..d6383fa 100644 --- a/packages/client/src/profile/types/index.ts +++ b/packages/client/src/profile/types/index.ts @@ -17,7 +17,7 @@ export interface IProfile { getById(userId: string): Promise; create(handle: string): Promise; update(profileData: TalentLayerProfile, userId: string): Promise; - getUsers(params: { + getBy(params: { numberPerPage?: number; offset?: number; searchQuery?: string; From 34b048e43c95dc3705fa7156ce295a41de664f49 Mon Sep 17 00:00:00 2001 From: Spandan Barve Date: Thu, 2 Nov 2023 01:45:23 +0530 Subject: [PATCH 12/12] format graphql queries in ts --- packages/client/src/escrow/graphql/queries.ts | 54 ++-- packages/client/src/profile/graphql/index.ts | 234 +++++++++--------- .../client/src/proposals/graphql/index.ts | 56 ++--- 3 files changed, 172 insertions(+), 172 deletions(-) diff --git a/packages/client/src/escrow/graphql/queries.ts b/packages/client/src/escrow/graphql/queries.ts index 9a71ca4..ec670d1 100644 --- a/packages/client/src/escrow/graphql/queries.ts +++ b/packages/client/src/escrow/graphql/queries.ts @@ -2,39 +2,39 @@ export const getProtocolAndPlatformsFees = ( originServicePlatformId: string, originValidatedProposalPlatformId: string, ): string => ` - { - protocols { - protocolEscrowFeeRate - } - servicePlatform: platform(id:${originServicePlatformId}){ - originServiceFeeRate - } - proposalPlatform: platform(id:${originValidatedProposalPlatformId}){ - originValidatedProposalFeeRate - } - } - `; +{ + protocols { + protocolEscrowFeeRate + } + servicePlatform: platform(id:${originServicePlatformId}){ + originServiceFeeRate + } + proposalPlatform: platform(id:${originValidatedProposalPlatformId}){ + originValidatedProposalFeeRate + } +} +`; export const getPaymentsByService = (serviceId: string, paymentType?: string) => { let condition = `where: {service: "${serviceId}"`; paymentType ? (condition += `, paymentType: "${paymentType}"`) : ''; condition += '}, orderBy: id, orderDirection: asc'; const query = ` - { - payments(${condition}) { - id - amount - rateToken { - address - decimals - name - symbol - } - paymentType - transactionHash - createdAt - } +{ + payments(${condition}) { + id + amount + rateToken { + address + decimals + name + symbol } - `; + paymentType + transactionHash + createdAt + } +} +`; return query; }; diff --git a/packages/client/src/profile/graphql/index.ts b/packages/client/src/profile/graphql/index.ts index 1f5ef51..93b889e 100644 --- a/packages/client/src/profile/graphql/index.ts +++ b/packages/client/src/profile/graphql/index.ts @@ -2,34 +2,34 @@ import { Hash } from 'viem'; export const getProfileByAddress = (address: Hash) => ` - { - users(where: {address: "${address.toLocaleLowerCase()}"}, first: 1) { - id - address - handle - rating - delegates - userStats { - numReceivedReviews - } - updatedAt - createdAt - description { - about - role - name - country - headline - id - image_url - video_url - title - timezone - skills_raw - } - } - } - `; +{ + users(where: {address: "${address.toLocaleLowerCase()}"}, first: 1) { + id + address + handle + rating + delegates + userStats { + numReceivedReviews + } + updatedAt + createdAt + description { + about + role + name + country + headline + id + image_url + video_url + title + timezone + skills_raw + } + } +} +`; export const getProfiles = (numberPerPage?: number, offset?: number, searchQuery?: string) => { const pagination = numberPerPage ? 'first: ' + numberPerPage + ', skip: ' + offset : ''; @@ -38,75 +38,75 @@ export const getProfiles = (numberPerPage?: number, offset?: number, searchQuery condition += '}'; return ` - { - users(orderBy: rating, orderDirection: desc ${pagination} ${condition}) { - id - address - handle - userStats { - numReceivedReviews - } - rating - } - } - `; +{ + users(orderBy: rating, orderDirection: desc ${pagination} ${condition}) { + id + address + handle + userStats { + numReceivedReviews + } + rating + } +} +`; }; export const getProfileById = (id: string) => ` - { - user(id: "${id}") { - id - address - handle - rating - delegates - userStats { - numReceivedReviews - } - updatedAt - createdAt - description { - about - role - name - country - headline - id - image_url - video_url - title - timezone - skills_raw - web3mailPreferences{ - activeOnNewService - activeOnNewProposal - activeOnProposalValidated - activeOnFundRelease - activeOnReview - activeOnPlatformMarketing - activeOnProtocolMarketing - } - } - } - } - `; +{ + user(id: "${id}") { + id + address + handle + rating + delegates + userStats { + numReceivedReviews + } + updatedAt + createdAt + description { + about + role + name + country + headline + id + image_url + video_url + title + timezone + skills_raw + web3mailPreferences{ + activeOnNewService + activeOnNewProposal + activeOnProposalValidated + activeOnFundRelease + activeOnReview + activeOnPlatformMarketing + activeOnProtocolMarketing + } + } + } +} +`; export const getUserTotalGains = (id: string) => ` - { - user(id: "${id}") { - totalGains{ - id - totalGain - token { - id - name - symbol - decimals - } - } - } - } - `; +{ + user(id: "${id}") { + totalGains{ + id + totalGain + token { + id + name + symbol + decimals + } + } + } +} +`; export const getPaymentsForUser = ( userId: string, @@ -121,30 +121,30 @@ export const getPaymentsForUser = ( const endDateCondition = endDate ? `, createdAt_lte: "${endDate}"` : ''; const query = ` - { - payments(where: { - service_: {seller: "${userId}"} - ${startDataCondition} - ${endDateCondition} - }, - orderBy: createdAt orderDirection: desc ${pagination} ) { - id, - rateToken { - address - decimals - name - symbol - } - amount - transactionHash - paymentType - createdAt - service { - id, - cid - } - } - } - `; +{ + payments(where: { + service_: {seller: "${userId}"} + ${startDataCondition} + ${endDateCondition} + }, + orderBy: createdAt orderDirection: desc ${pagination} ) { + id, + rateToken { + address + decimals + name + symbol + } + amount + transactionHash + paymentType + createdAt + service { + id, + cid + } + } +} +`; return query; }; diff --git a/packages/client/src/proposals/graphql/index.ts b/packages/client/src/proposals/graphql/index.ts index 0ea655b..0ad8e24 100644 --- a/packages/client/src/proposals/graphql/index.ts +++ b/packages/client/src/proposals/graphql/index.ts @@ -87,40 +87,40 @@ export const getAllProposalsByServiceId = (id: string) => ` `; export const getAllProposalsByUser = (id: string) => ` - { - proposals(where: {seller: "${id}", status: "Pending"}) { +{ + proposals(where: {seller: "${id}", status: "Pending"}) { + id + rateAmount + rateToken { + address + decimals + name + symbol + } + status + cid + createdAt + seller { + id + handle + } + service { id - rateAmount - rateToken { - address - decimals - name - symbol - } - status cid createdAt - seller { + buyer { id handle } - service { - id - cid - createdAt - buyer { - id - handle - } - } - description { - id - about - expectedHours - startDate - video_url - } - expirationDate } + description { + id + about + expectedHours + startDate + video_url + } + expirationDate } +} `;