From 7497f1c0b939f321aad8cb5679c9a9ed8df7718f Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 8 Nov 2023 10:06:27 +0800 Subject: [PATCH 1/2] Add user address filter to pools query --- modules/pool/lib/pool-gql-loader.service.ts | 40 +++++++++++++++++++-- modules/pool/pool.gql | 2 ++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/modules/pool/lib/pool-gql-loader.service.ts b/modules/pool/lib/pool-gql-loader.service.ts index b381545ee..4ed99b862 100644 --- a/modules/pool/lib/pool-gql-loader.service.ts +++ b/modules/pool/lib/pool-gql-loader.service.ts @@ -131,6 +131,7 @@ export class PoolGqlLoaderService { private mapQueryArgsToPoolQuery(args: QueryPoolGetPoolsArgs): Prisma.PrismaPoolFindManyArgs { let orderBy: Prisma.PrismaPoolOrderByWithRelationInput = {}; const orderDirection = args.orderDirection || undefined; + const userAddress = args.userAddress; switch (args.orderBy) { case 'totalLiquidity': @@ -206,6 +207,35 @@ export class PoolGqlLoaderService { }); } + const userArgs: Prisma.PrismaPoolWhereInput = userAddress + ? { + OR: [ + { + userWalletBalances: { + some: { + userAddress: { + equals: userAddress, + mode: 'insensitive' as const, + }, + balanceNum: { gt: 0 }, + }, + }, + }, + { + userStakedBalances: { + some: { + userAddress: { + equals: userAddress, + mode: 'insensitive' as const, + }, + balanceNum: { gt: 0 }, + }, + }, + }, + ], + } + : {}; + const filterArgs: Prisma.PrismaPoolWhereInput = { dynamicData: { totalSharesNum: { @@ -271,7 +301,10 @@ export class PoolGqlLoaderService { if (!textSearch) { return { ...baseQuery, - where: filterArgs, + where: { + ...filterArgs, + ...userArgs, + }, }; } @@ -279,10 +312,11 @@ export class PoolGqlLoaderService { ...baseQuery, where: { OR: [ - { name: textSearch, ...filterArgs }, - { symbol: textSearch, ...filterArgs }, + { name: textSearch, ...filterArgs, ...userArgs }, + { symbol: textSearch, ...filterArgs, ...userArgs }, { ...filterArgs, + ...userArgs, allTokens: { some: { OR: [ diff --git a/modules/pool/pool.gql b/modules/pool/pool.gql index af90e7f62..0457a378d 100644 --- a/modules/pool/pool.gql +++ b/modules/pool/pool.gql @@ -7,6 +7,7 @@ extend type Query { orderDirection: GqlPoolOrderDirection where: GqlPoolFilter textSearch: String + userAddress: String ): [GqlPoolMinimal!]! poolGetPoolsCount( first: Int @@ -15,6 +16,7 @@ extend type Query { orderDirection: GqlPoolOrderDirection where: GqlPoolFilter textSearch: String + userAddress: String ): Int! poolGetPoolFilters: [GqlPoolFilterDefinition!]! poolGetSwaps(first: Int, skip: Int, where: GqlPoolSwapFilter): [GqlPoolSwap!]! From 1e0cecb95429421b5b4e53f2b2d196b952c01bb2 Mon Sep 17 00:00:00 2001 From: franz Date: Thu, 9 Nov 2023 13:45:08 +0100 Subject: [PATCH 2/2] include blacklisted pools by default --- modules/pool/lib/pool-gql-loader.service.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/pool/lib/pool-gql-loader.service.ts b/modules/pool/lib/pool-gql-loader.service.ts index 4ed99b862..06b567f3e 100644 --- a/modules/pool/lib/pool-gql-loader.service.ts +++ b/modules/pool/lib/pool-gql-loader.service.ts @@ -261,11 +261,15 @@ export class PoolGqlLoaderService { mode: 'insensitive', }, categories: { - every: { - category: { - notIn: ['BLACK_LISTED', ...(where?.categoryNotIn || [])], - }, - }, + ...(where?.categoryNotIn + ? { + every: { + category: { + notIn: where.categoryNotIn, + }, + }, + } + : {}), ...(where?.categoryIn ? { some: {