diff --git a/src/graphql/BuildersQueries.graphql b/src/graphql/BuildersQueries.graphql index cd0a9ca..0e72aaa 100644 --- a/src/graphql/BuildersQueries.graphql +++ b/src/graphql/BuildersQueries.graphql @@ -141,3 +141,33 @@ query combinedBuildersList( totalSubnets } } + +# TEMP: To filter by name +query combinedBuildersListFilteredByPredefinedBuilders( + $orderBy: BuildersProject_orderBy + $orderDirection: OrderDirection + $name_in: [String!] = "" + $address: Bytes = "" +) { + buildersProjects( + orderBy: $orderBy + orderDirection: $orderDirection + where: {name_in: $name_in} + ) { + ...BuilderProject + } + + + buildersUsers(where: { + address: $address + buildersProject_: {name_in: $name_in} + }) { + address + id + lastStake + staked + buildersProject { + ...BuilderProject + } + } +} diff --git a/src/pages/Builders/pages/BuildersList/components/BuildersTable.vue b/src/pages/Builders/pages/BuildersList/components/BuildersTable.vue deleted file mode 100644 index e380aea..0000000 --- a/src/pages/Builders/pages/BuildersList/components/BuildersTable.vue +++ /dev/null @@ -1,207 +0,0 @@ - - - - - diff --git a/src/pages/Builders/pages/BuildersList/components/BuildersTable/components/SortingIconButton.vue b/src/pages/Builders/pages/BuildersList/components/BuildersTable/components/SortingIconButton.vue new file mode 100644 index 0000000..44fcc7c --- /dev/null +++ b/src/pages/Builders/pages/BuildersList/components/BuildersTable/components/SortingIconButton.vue @@ -0,0 +1,62 @@ + + + + + diff --git a/src/pages/Builders/pages/BuildersList/components/BuildersTable/index.vue b/src/pages/Builders/pages/BuildersList/components/BuildersTable/index.vue new file mode 100644 index 0000000..90ac26c --- /dev/null +++ b/src/pages/Builders/pages/BuildersList/components/BuildersTable/index.vue @@ -0,0 +1,78 @@ + + + + + diff --git a/src/pages/Builders/pages/BuildersList/index.vue b/src/pages/Builders/pages/BuildersList/index.vue index 505ce32..2c39fee 100644 --- a/src/pages/Builders/pages/BuildersList/index.vue +++ b/src/pages/Builders/pages/BuildersList/index.vue @@ -42,9 +42,8 @@ @@ -120,16 +118,19 @@ import { Pagination, SkeletonTable, } from '@/common' -import BuildersTable from '@/pages/Builders/pages/BuildersList/components/BuildersTable.vue' +import BuildersTable from '@/pages/Builders/pages/BuildersList/components/BuildersTable/index.vue' import BuilderFormModal from '@/pages/Builders/components/BuilderFormModal.vue' import { BuildersProject_OrderBy, CombinedBuildersList, + CombinedBuildersListFilteredByPredefinedBuilders, + CombinedBuildersListFilteredByPredefinedBuildersQuery, + CombinedBuildersListFilteredByPredefinedBuildersQueryVariables, CombinedBuildersListQuery, CombinedBuildersListQueryVariables, OrderDirection, } from '@/types/graphql' -import { ref, provide } from 'vue' +import { provide, ref } from 'vue' import { DEFAULT_PAGE_LIMIT } from '@/const' import { useRoute, useRouter } from 'vue-router' import { useWeb3ProvidersStore } from '@/store' @@ -137,6 +138,14 @@ import { ROUTE_NAMES } from '@/enums' import { useLoad } from '@/composables' import { storeToRefs } from 'pinia' import { useSecondApolloClient } from '@/composables/use-second-apollo-client' +import { NetworkTypes } from '@config' +import predefinedBuildersMeta from '@/assets/predefined-builders-meta.json' + +type LoadBuildersResponse = { + buildersProjects: CombinedBuildersListQuery['buildersProjects'] + userAccountBuildersProjects: CombinedBuildersListQuery['buildersProjects'] + buildersCounters: CombinedBuildersListQuery['counters'][0] +} defineOptions({ inheritAttrs: false, @@ -145,33 +154,105 @@ defineOptions({ const route = useRoute() const router = useRouter() -const { provider } = storeToRefs(useWeb3ProvidersStore()) +const { provider, networkType } = storeToRefs(useWeb3ProvidersStore()) const currentPage = ref(1) -const orderBy = ref(BuildersProject_OrderBy.Id) -const orderDirection = ref(OrderDirection.Desc) +const orderBy = ref(BuildersProject_OrderBy.TotalStaked) +const orderDirection = ref(OrderDirection.Asc) const isCreateBuilderModalShown = ref(false) const buildersApolloClient = useSecondApolloClient() +const { data: allPredefinedBuilders } = useLoad( + { + buildersProjects: [], + userAccountBuildersProjects: [], + buildersCounters: {} as CombinedBuildersListQuery['counters'][0], + }, + async (): Promise => { + const { data } = await buildersApolloClient.value.query< + CombinedBuildersListFilteredByPredefinedBuildersQuery, + CombinedBuildersListFilteredByPredefinedBuildersQueryVariables + >({ + query: CombinedBuildersListFilteredByPredefinedBuilders, + fetchPolicy: 'network-only', + variables: { + orderBy: orderBy.value, + orderDirection: orderDirection.value, + name_in: predefinedBuildersMeta.map(el => el.name), + + address: provider.value.selectedAddress, + }, + }) + + return { + buildersProjects: data.buildersProjects, + userAccountBuildersProjects: data.buildersUsers.map( + el => el.buildersProject, + ), + buildersCounters: { + id: '', + totalBuildersProjects: data.buildersProjects.length, + totalSubnets: 0, + }, + } + }, + { + isLoadOnMount: networkType.value === NetworkTypes.Mainnet, + reloadArgs: [ + orderBy, + orderDirection, + () => route.query.user, + () => route.query.network, + () => provider.value.chainId, + ], + }, +) + +const paginateThroughAllPredefinedBuilders = async (args: { + skip: number + first: number + orderBy: BuildersProject_OrderBy + orderDirection: OrderDirection +}): Promise => { + const buildersProjects = allPredefinedBuilders.value.buildersProjects.slice( + args.skip, + args.skip + args.first, + ) + const userAccountBuildersProjects = + allPredefinedBuilders.value.userAccountBuildersProjects + const buildersCounters = allPredefinedBuilders.value.buildersCounters + + return { + buildersProjects, + userAccountBuildersProjects, + buildersCounters, + } +} + const { data: listData, reload: reloadList, update: updateList, ...buildersProjectsState -} = useLoad<{ - buildersProjects: CombinedBuildersListQuery['buildersProjects'] - userAccountBuildersProjects: CombinedBuildersListQuery['buildersProjects'] - buildersCounters: CombinedBuildersListQuery['counters'][0] -}>( +} = useLoad( { buildersProjects: [], userAccountBuildersProjects: [], buildersCounters: {} as CombinedBuildersListQuery['counters'][0], }, async () => { + if (networkType.value === NetworkTypes.Mainnet) { + return paginateThroughAllPredefinedBuilders({ + first: DEFAULT_PAGE_LIMIT, + skip: currentPage.value * DEFAULT_PAGE_LIMIT - DEFAULT_PAGE_LIMIT, + orderBy: orderBy.value, + orderDirection: orderDirection.value, + }) + } + const { data } = await buildersApolloClient.value.query< CombinedBuildersListQuery, CombinedBuildersListQueryVariables @@ -201,11 +282,15 @@ const { } }, { + isLoadOnMount: networkType.value === NetworkTypes.Testnet, reloadArgs: [ currentPage, () => route.query.user, () => route.query.network, () => provider.value.chainId, + networkType.value === NetworkTypes.Mainnet + ? () => allPredefinedBuilders.value + : undefined, ], }, ) @@ -220,20 +305,6 @@ const handleBuilderCreated = async (poolId: string) => { }) } -const handleChangeSorting = (order: BuildersProject_OrderBy) => { - if (orderBy.value === order) { - orderDirection.value = - orderDirection.value === OrderDirection.Asc - ? OrderDirection.Desc - : OrderDirection.Asc - } else { - orderBy.value = order - orderDirection.value = OrderDirection.Asc - } - - updateList() -} - provide('reloadBuildersProjects', reloadList) provide('updateBuildersProjects', updateList) provide('reloadUserAccountBuildersProjects', reloadList) diff --git a/src/types/graphql/index.ts b/src/types/graphql/index.ts index 73b3a1d..c5cc2e4 100644 --- a/src/types/graphql/index.ts +++ b/src/types/graphql/index.ts @@ -969,6 +969,16 @@ export type CombinedBuildersListQueryVariables = Exact<{ export type CombinedBuildersListQuery = { __typename?: 'Query', buildersProjects: Array<{ __typename?: 'BuildersProject', admin: any, claimLockEnd: any, id: any, minimalDeposit: any, name: string, startsAt: any, totalClaimed: any, totalStaked: any, totalUsers: any, withdrawLockPeriodAfterDeposit: any }>, buildersUsers: Array<{ __typename?: 'BuildersUser', address: any, id: any, lastStake: any, staked: any, buildersProject: { __typename?: 'BuildersProject', admin: any, claimLockEnd: any, id: any, minimalDeposit: any, name: string, startsAt: any, totalClaimed: any, totalStaked: any, totalUsers: any, withdrawLockPeriodAfterDeposit: any } }>, counters: Array<{ __typename?: 'Counter', id: any, totalBuildersProjects: any, totalSubnets: any }> }; +export type CombinedBuildersListFilteredByPredefinedBuildersQueryVariables = Exact<{ + orderBy?: InputMaybe; + orderDirection?: InputMaybe; + name_in?: InputMaybe | Scalars['String']>; + address?: InputMaybe; +}>; + + +export type CombinedBuildersListFilteredByPredefinedBuildersQuery = { __typename?: 'Query', buildersProjects: Array<{ __typename?: 'BuildersProject', admin: any, claimLockEnd: any, id: any, minimalDeposit: any, name: string, startsAt: any, totalClaimed: any, totalStaked: any, totalUsers: any, withdrawLockPeriodAfterDeposit: any }>, buildersUsers: Array<{ __typename?: 'BuildersUser', address: any, id: any, lastStake: any, staked: any, buildersProject: { __typename?: 'BuildersProject', admin: any, claimLockEnd: any, id: any, minimalDeposit: any, name: string, startsAt: any, totalClaimed: any, totalStaked: any, totalUsers: any, withdrawLockPeriodAfterDeposit: any } }> }; + export const BuilderProject = gql` fragment BuilderProject on BuildersProject { admin @@ -1100,5 +1110,25 @@ export const CombinedBuildersList = gql` totalBuildersProjects totalSubnets } +} + ${BuilderProject}`; +export const CombinedBuildersListFilteredByPredefinedBuilders = gql` + query combinedBuildersListFilteredByPredefinedBuilders($orderBy: BuildersProject_orderBy, $orderDirection: OrderDirection, $name_in: [String!] = "", $address: Bytes = "") { + buildersProjects( + orderBy: $orderBy + orderDirection: $orderDirection + where: {name_in: $name_in} + ) { + ...BuilderProject + } + buildersUsers(where: {address: $address, buildersProject_: {name_in: $name_in}}) { + address + id + lastStake + staked + buildersProject { + ...BuilderProject + } + } } ${BuilderProject}`; \ No newline at end of file