Skip to content

Commit f214340

Browse files
committed
feat: add Workerpool details and deals functionality with GraphQL queries and components
1 parent 5a159f1 commit f214340

File tree

10 files changed

+627
-1
lines changed

10 files changed

+627
-1
lines changed

src/graphql/gql.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ type Documents = {
2929
"\n query NextTasks($length: Int = 20, $skip: Int = 0) {\n tasks(\n first: $length\n skip: $skip\n orderBy: timestamp\n orderDirection: desc\n ) {\n taskid: id\n }\n }\n": typeof types.NextTasksDocument,
3030
"\n query Tasks($length: Int = 20, $skip: Int = 0) {\n tasks(\n first: $length\n skip: $skip\n orderBy: timestamp\n orderDirection: desc\n ) {\n taskid: id\n index\n finalDeadline\n status\n timestamp\n deal {\n requester {\n address: id\n }\n beneficiary {\n address: id\n }\n app {\n address: id\n }\n dataset {\n address: id\n }\n workerpool {\n address: id\n }\n category {\n catid: id\n workClockTimeRef\n }\n }\n }\n }\n": typeof types.TasksDocument,
3131
"\n query NextWorkerpools($length: Int = 20, $skip: Int = 0) {\n workerpools(\n first: $length\n skip: $skip\n orderBy: timestamp\n orderDirection: desc\n ) {\n address: id\n }\n }\n": typeof types.NextWorkerpoolsDocument,
32+
"\n query NextWorkerpoolDeals(\n $length: Int = 20\n $skip: Int = 0\n $workerpoolAddress: ID!\n ) {\n workerpool(id: $workerpoolAddress) {\n address: id\n deals: usages(\n first: $length\n skip: $skip\n orderBy: timestamp\n orderDirection: desc\n ) {\n dealid: id\n }\n }\n }\n": typeof types.NextWorkerpoolDealsDocument,
33+
"\n query WorkerpoolDeals(\n $length: Int = 20\n $skip: Int = 0\n $workerpoolAddress: ID!\n ) {\n workerpool(id: $workerpoolAddress) {\n address: id\n deals: usages(\n orderBy: timestamp\n orderDirection: desc\n first: $length\n skip: $skip\n ) {\n dealid: id\n timestamp\n requester {\n address: id\n }\n beneficiary {\n address: id\n }\n callback {\n address: id\n }\n app {\n address: id\n name\n }\n dataset {\n address: id\n name\n }\n workerpool {\n address: id\n description\n }\n category {\n catid: id\n workClockTimeRef\n }\n startTime\n appPrice\n datasetPrice\n workerpoolPrice\n botSize\n trust\n completedTasksCount\n claimedTasksCount\n }\n }\n }\n": typeof types.WorkerpoolDealsDocument,
34+
"\n query Workerpool($workerpoolAddress: ID!, $workerpoolAddressString: String!) {\n workerpool(id: $workerpoolAddress) {\n address: id\n owner {\n address: id\n }\n description\n transfers(\n where: { workerpool: $workerpoolAddressString }\n orderBy: timestamp\n orderDirection: asc\n ) {\n workerpool {\n address: id\n }\n from {\n address: id\n }\n to {\n address: id\n }\n transaction {\n txHash: id\n timestamp\n blockNumber\n }\n }\n }\n }\n": typeof types.WorkerpoolDocument,
3235
"\n query Workerpools($length: Int = 20, $skip: Int = 0) {\n workerpools(\n first: $length\n skip: $skip\n orderBy: timestamp\n orderDirection: desc\n ) {\n address: id\n owner {\n address: id\n }\n timestamp\n description\n workerStakeRatio\n schedulerRewardRatio\n transfers(orderBy: timestamp, orderDirection: desc) {\n transaction {\n txHash: id\n timestamp\n blockNumber\n }\n }\n }\n }\n": typeof types.WorkerpoolsDocument,
3336
};
3437
const documents: Documents = {
@@ -46,6 +49,9 @@ const documents: Documents = {
4649
"\n query NextTasks($length: Int = 20, $skip: Int = 0) {\n tasks(\n first: $length\n skip: $skip\n orderBy: timestamp\n orderDirection: desc\n ) {\n taskid: id\n }\n }\n": types.NextTasksDocument,
4750
"\n query Tasks($length: Int = 20, $skip: Int = 0) {\n tasks(\n first: $length\n skip: $skip\n orderBy: timestamp\n orderDirection: desc\n ) {\n taskid: id\n index\n finalDeadline\n status\n timestamp\n deal {\n requester {\n address: id\n }\n beneficiary {\n address: id\n }\n app {\n address: id\n }\n dataset {\n address: id\n }\n workerpool {\n address: id\n }\n category {\n catid: id\n workClockTimeRef\n }\n }\n }\n }\n": types.TasksDocument,
4851
"\n query NextWorkerpools($length: Int = 20, $skip: Int = 0) {\n workerpools(\n first: $length\n skip: $skip\n orderBy: timestamp\n orderDirection: desc\n ) {\n address: id\n }\n }\n": types.NextWorkerpoolsDocument,
52+
"\n query NextWorkerpoolDeals(\n $length: Int = 20\n $skip: Int = 0\n $workerpoolAddress: ID!\n ) {\n workerpool(id: $workerpoolAddress) {\n address: id\n deals: usages(\n first: $length\n skip: $skip\n orderBy: timestamp\n orderDirection: desc\n ) {\n dealid: id\n }\n }\n }\n": types.NextWorkerpoolDealsDocument,
53+
"\n query WorkerpoolDeals(\n $length: Int = 20\n $skip: Int = 0\n $workerpoolAddress: ID!\n ) {\n workerpool(id: $workerpoolAddress) {\n address: id\n deals: usages(\n orderBy: timestamp\n orderDirection: desc\n first: $length\n skip: $skip\n ) {\n dealid: id\n timestamp\n requester {\n address: id\n }\n beneficiary {\n address: id\n }\n callback {\n address: id\n }\n app {\n address: id\n name\n }\n dataset {\n address: id\n name\n }\n workerpool {\n address: id\n description\n }\n category {\n catid: id\n workClockTimeRef\n }\n startTime\n appPrice\n datasetPrice\n workerpoolPrice\n botSize\n trust\n completedTasksCount\n claimedTasksCount\n }\n }\n }\n": types.WorkerpoolDealsDocument,
54+
"\n query Workerpool($workerpoolAddress: ID!, $workerpoolAddressString: String!) {\n workerpool(id: $workerpoolAddress) {\n address: id\n owner {\n address: id\n }\n description\n transfers(\n where: { workerpool: $workerpoolAddressString }\n orderBy: timestamp\n orderDirection: asc\n ) {\n workerpool {\n address: id\n }\n from {\n address: id\n }\n to {\n address: id\n }\n transaction {\n txHash: id\n timestamp\n blockNumber\n }\n }\n }\n }\n": types.WorkerpoolDocument,
4955
"\n query Workerpools($length: Int = 20, $skip: Int = 0) {\n workerpools(\n first: $length\n skip: $skip\n orderBy: timestamp\n orderDirection: desc\n ) {\n address: id\n owner {\n address: id\n }\n timestamp\n description\n workerStakeRatio\n schedulerRewardRatio\n transfers(orderBy: timestamp, orderDirection: desc) {\n transaction {\n txHash: id\n timestamp\n blockNumber\n }\n }\n }\n }\n": types.WorkerpoolsDocument,
5056
};
5157

@@ -105,6 +111,18 @@ export function graphql(source: "\n query Tasks($length: Int = 20, $skip: Int =
105111
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
106112
*/
107113
export function graphql(source: "\n query NextWorkerpools($length: Int = 20, $skip: Int = 0) {\n workerpools(\n first: $length\n skip: $skip\n orderBy: timestamp\n orderDirection: desc\n ) {\n address: id\n }\n }\n"): typeof import('./graphql').NextWorkerpoolsDocument;
114+
/**
115+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
116+
*/
117+
export function graphql(source: "\n query NextWorkerpoolDeals(\n $length: Int = 20\n $skip: Int = 0\n $workerpoolAddress: ID!\n ) {\n workerpool(id: $workerpoolAddress) {\n address: id\n deals: usages(\n first: $length\n skip: $skip\n orderBy: timestamp\n orderDirection: desc\n ) {\n dealid: id\n }\n }\n }\n"): typeof import('./graphql').NextWorkerpoolDealsDocument;
118+
/**
119+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
120+
*/
121+
export function graphql(source: "\n query WorkerpoolDeals(\n $length: Int = 20\n $skip: Int = 0\n $workerpoolAddress: ID!\n ) {\n workerpool(id: $workerpoolAddress) {\n address: id\n deals: usages(\n orderBy: timestamp\n orderDirection: desc\n first: $length\n skip: $skip\n ) {\n dealid: id\n timestamp\n requester {\n address: id\n }\n beneficiary {\n address: id\n }\n callback {\n address: id\n }\n app {\n address: id\n name\n }\n dataset {\n address: id\n name\n }\n workerpool {\n address: id\n description\n }\n category {\n catid: id\n workClockTimeRef\n }\n startTime\n appPrice\n datasetPrice\n workerpoolPrice\n botSize\n trust\n completedTasksCount\n claimedTasksCount\n }\n }\n }\n"): typeof import('./graphql').WorkerpoolDealsDocument;
122+
/**
123+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
124+
*/
125+
export function graphql(source: "\n query Workerpool($workerpoolAddress: ID!, $workerpoolAddressString: String!) {\n workerpool(id: $workerpoolAddress) {\n address: id\n owner {\n address: id\n }\n description\n transfers(\n where: { workerpool: $workerpoolAddressString }\n orderBy: timestamp\n orderDirection: asc\n ) {\n workerpool {\n address: id\n }\n from {\n address: id\n }\n to {\n address: id\n }\n transaction {\n txHash: id\n timestamp\n blockNumber\n }\n }\n }\n }\n"): typeof import('./graphql').WorkerpoolDocument;
108126
/**
109127
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
110128
*/

src/graphql/graphql.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8468,6 +8468,32 @@ export type NextWorkerpoolsQueryVariables = Exact<{
84688468

84698469
export type NextWorkerpoolsQuery = { __typename?: 'Query', workerpools: Array<{ __typename?: 'Workerpool', address: string }> };
84708470

8471+
export type NextWorkerpoolDealsQueryVariables = Exact<{
8472+
length?: InputMaybe<Scalars['Int']['input']>;
8473+
skip?: InputMaybe<Scalars['Int']['input']>;
8474+
workerpoolAddress: Scalars['ID']['input'];
8475+
}>;
8476+
8477+
8478+
export type NextWorkerpoolDealsQuery = { __typename?: 'Query', workerpool?: { __typename?: 'Workerpool', address: string, deals: Array<{ __typename?: 'Deal', dealid: string }> } | null };
8479+
8480+
export type WorkerpoolDealsQueryVariables = Exact<{
8481+
length?: InputMaybe<Scalars['Int']['input']>;
8482+
skip?: InputMaybe<Scalars['Int']['input']>;
8483+
workerpoolAddress: Scalars['ID']['input'];
8484+
}>;
8485+
8486+
8487+
export type WorkerpoolDealsQuery = { __typename?: 'Query', workerpool?: { __typename?: 'Workerpool', address: string, deals: Array<{ __typename?: 'Deal', timestamp: any, startTime: any, appPrice: any, datasetPrice: any, workerpoolPrice: any, botSize: any, trust: any, completedTasksCount: any, claimedTasksCount: any, dealid: string, requester: { __typename?: 'Account', address: string }, beneficiary: { __typename?: 'Account', address: string }, callback: { __typename?: 'Account', address: string }, app: { __typename?: 'App', name: string, address: string }, dataset?: { __typename?: 'Dataset', name: string, address: string } | null, workerpool: { __typename?: 'Workerpool', description: string, address: string }, category: { __typename?: 'Category', workClockTimeRef: any, catid: string } }> } | null };
8488+
8489+
export type WorkerpoolQueryVariables = Exact<{
8490+
workerpoolAddress: Scalars['ID']['input'];
8491+
workerpoolAddressString: Scalars['String']['input'];
8492+
}>;
8493+
8494+
8495+
export type WorkerpoolQuery = { __typename?: 'Query', workerpool?: { __typename?: 'Workerpool', description: string, address: string, owner: { __typename?: 'Account', address: string }, transfers: Array<{ __typename?: 'WorkerpoolTransfer', workerpool: { __typename?: 'Workerpool', address: string }, from: { __typename?: 'Account', address: string }, to: { __typename?: 'Account', address: string }, transaction: { __typename?: 'Transaction', timestamp: any, blockNumber: any, txHash: string } }> } | null };
8496+
84718497
export type WorkerpoolsQueryVariables = Exact<{
84728498
length?: InputMaybe<Scalars['Int']['input']>;
84738499
skip?: InputMaybe<Scalars['Int']['input']>;
@@ -8812,6 +8838,101 @@ export const NextWorkerpoolsDocument = new TypedDocumentString(`
88128838
}
88138839
}
88148840
`) as unknown as TypedDocumentString<NextWorkerpoolsQuery, NextWorkerpoolsQueryVariables>;
8841+
export const NextWorkerpoolDealsDocument = new TypedDocumentString(`
8842+
query NextWorkerpoolDeals($length: Int = 20, $skip: Int = 0, $workerpoolAddress: ID!) {
8843+
workerpool(id: $workerpoolAddress) {
8844+
address: id
8845+
deals: usages(
8846+
first: $length
8847+
skip: $skip
8848+
orderBy: timestamp
8849+
orderDirection: desc
8850+
) {
8851+
dealid: id
8852+
}
8853+
}
8854+
}
8855+
`) as unknown as TypedDocumentString<NextWorkerpoolDealsQuery, NextWorkerpoolDealsQueryVariables>;
8856+
export const WorkerpoolDealsDocument = new TypedDocumentString(`
8857+
query WorkerpoolDeals($length: Int = 20, $skip: Int = 0, $workerpoolAddress: ID!) {
8858+
workerpool(id: $workerpoolAddress) {
8859+
address: id
8860+
deals: usages(
8861+
orderBy: timestamp
8862+
orderDirection: desc
8863+
first: $length
8864+
skip: $skip
8865+
) {
8866+
dealid: id
8867+
timestamp
8868+
requester {
8869+
address: id
8870+
}
8871+
beneficiary {
8872+
address: id
8873+
}
8874+
callback {
8875+
address: id
8876+
}
8877+
app {
8878+
address: id
8879+
name
8880+
}
8881+
dataset {
8882+
address: id
8883+
name
8884+
}
8885+
workerpool {
8886+
address: id
8887+
description
8888+
}
8889+
category {
8890+
catid: id
8891+
workClockTimeRef
8892+
}
8893+
startTime
8894+
appPrice
8895+
datasetPrice
8896+
workerpoolPrice
8897+
botSize
8898+
trust
8899+
completedTasksCount
8900+
claimedTasksCount
8901+
}
8902+
}
8903+
}
8904+
`) as unknown as TypedDocumentString<WorkerpoolDealsQuery, WorkerpoolDealsQueryVariables>;
8905+
export const WorkerpoolDocument = new TypedDocumentString(`
8906+
query Workerpool($workerpoolAddress: ID!, $workerpoolAddressString: String!) {
8907+
workerpool(id: $workerpoolAddress) {
8908+
address: id
8909+
owner {
8910+
address: id
8911+
}
8912+
description
8913+
transfers(
8914+
where: {workerpool: $workerpoolAddressString}
8915+
orderBy: timestamp
8916+
orderDirection: asc
8917+
) {
8918+
workerpool {
8919+
address: id
8920+
}
8921+
from {
8922+
address: id
8923+
}
8924+
to {
8925+
address: id
8926+
}
8927+
transaction {
8928+
txHash: id
8929+
timestamp
8930+
blockNumber
8931+
}
8932+
}
8933+
}
8934+
}
8935+
`) as unknown as TypedDocumentString<WorkerpoolQuery, WorkerpoolQueryVariables>;
88158936
export const WorkerpoolsDocument = new TypedDocumentString(`
88168937
query Workerpools($length: Int = 20, $skip: Int = 0) {
88178938
workerpools(
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { DETAIL_TABLE_LENGTH, TABLE_REFETCH_INTERVAL } from '@/config';
2+
import { execute } from '@/graphql/execute';
3+
import { useQuery } from '@tanstack/react-query';
4+
import { LoaderCircle } from 'lucide-react';
5+
import { useState } from 'react';
6+
import { DataTable } from '@/components/DataTable';
7+
import { PaginatedNavigation } from '@/components/PaginatedNavigation';
8+
import { ErrorAlert } from '@/modules/ErrorAlert';
9+
import { columns } from '@/modules/deals/dealsTable/columns';
10+
import useUserStore from '@/stores/useUser.store';
11+
import { nextWorkerpoolDealsQuery } from './nextWorkerpoolDealsQuery';
12+
import { workerpoolDealsQuery } from './workerpoolDealsQuery';
13+
14+
function useWorkerpoolDealsData({
15+
workerpoolAddress,
16+
currentPage,
17+
}: {
18+
workerpoolAddress: string;
19+
currentPage: number;
20+
}) {
21+
const { chainId } = useUserStore();
22+
const skip = currentPage * DETAIL_TABLE_LENGTH;
23+
24+
const { data, isLoading, isRefetching, isError, errorUpdateCount } = useQuery(
25+
{
26+
queryKey: ['workerpool', 'deals', workerpoolAddress],
27+
queryFn: () =>
28+
execute(workerpoolDealsQuery, chainId, {
29+
length: DETAIL_TABLE_LENGTH,
30+
skip,
31+
workerpoolAddress,
32+
}),
33+
refetchInterval: TABLE_REFETCH_INTERVAL,
34+
}
35+
);
36+
37+
const { data: nextData } = useQuery({
38+
queryKey: [chainId, 'deals-next', currentPage],
39+
queryFn: () =>
40+
execute(nextWorkerpoolDealsQuery, chainId, {
41+
length: DETAIL_TABLE_LENGTH * 2,
42+
skip: (currentPage + 1) * DETAIL_TABLE_LENGTH,
43+
workerpoolAddress,
44+
}),
45+
refetchInterval: TABLE_REFETCH_INTERVAL,
46+
});
47+
48+
const nextDeals = nextData?.workerpool?.deals ?? [];
49+
50+
const additionalPages = Math.ceil(nextDeals.length / DETAIL_TABLE_LENGTH);
51+
52+
const formattedDeal =
53+
data?.workerpool?.deals.map((deal) => ({
54+
...deal,
55+
destination: `/deal/${deal.dealid}`,
56+
})) ?? [];
57+
58+
return {
59+
data: formattedDeal,
60+
isLoading,
61+
isRefetching,
62+
isError,
63+
additionalPages,
64+
hasPastError: isError || errorUpdateCount > 0,
65+
};
66+
}
67+
68+
export function WorkerpoolDealsTable({
69+
workerpoolAddress,
70+
}: {
71+
workerpoolAddress: string;
72+
}) {
73+
const [currentPage, setCurrentPage] = useState(0);
74+
const {
75+
data: deals,
76+
isError,
77+
isLoading,
78+
isRefetching,
79+
additionalPages,
80+
hasPastError,
81+
} = useWorkerpoolDealsData({ workerpoolAddress, currentPage });
82+
83+
const filteredColumns = columns.filter(
84+
(col) => col.accessorKey !== 'dataset.address'
85+
);
86+
87+
return (
88+
<div className="space-y-6">
89+
<h2 className="flex items-center gap-2 font-extrabold">
90+
Latests deals
91+
{!deals && isError && (
92+
<span className="text-muted-foreground text-sm font-light">
93+
(outdated)
94+
</span>
95+
)}
96+
{(isLoading || isRefetching) && (
97+
<LoaderCircle className="animate-spin" />
98+
)}
99+
</h2>
100+
{hasPastError && !deals.length ? (
101+
<ErrorAlert message="A error occurred during workerpool deals loading." />
102+
) : (
103+
<DataTable
104+
columns={filteredColumns}
105+
data={deals}
106+
tableLength={DETAIL_TABLE_LENGTH}
107+
/>
108+
)}
109+
<PaginatedNavigation
110+
currentPage={currentPage + 1}
111+
totalPages={currentPage + 1 + additionalPages}
112+
onPageChange={(newPage) => setCurrentPage(newPage - 1)}
113+
/>
114+
</div>
115+
);
116+
}

0 commit comments

Comments
 (0)