Skip to content

Commit

Permalink
Merge pull request #519 from beethovenxfi/feature/add-user-address-to…
Browse files Browse the repository at this point in the history
…-pools-query

Add user address filter to pools query
  • Loading branch information
franzns authored Nov 15, 2023
2 parents 7539083 + 1e0cecb commit 37ff70c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
54 changes: 46 additions & 8 deletions modules/pool/lib/pool-gql-loader.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,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':
Expand Down Expand Up @@ -207,6 +208,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: {
Expand All @@ -232,11 +262,15 @@ export class PoolGqlLoaderService {
mode: 'insensitive',
},
categories: {
every: {
category: {
notIn: ['BLACK_LISTED', ...(where?.categoryNotIn || [])],
},
},
...(where?.categoryNotIn
? {
every: {
category: {
notIn: where.categoryNotIn,
},
},
}
: {}),
...(where?.categoryIn
? {
some: {
Expand Down Expand Up @@ -272,18 +306,22 @@ export class PoolGqlLoaderService {
if (!textSearch) {
return {
...baseQuery,
where: filterArgs,
where: {
...filterArgs,
...userArgs,
},
};
}

return {
...baseQuery,
where: {
OR: [
{ name: textSearch, ...filterArgs },
{ symbol: textSearch, ...filterArgs },
{ name: textSearch, ...filterArgs, ...userArgs },
{ symbol: textSearch, ...filterArgs, ...userArgs },
{
...filterArgs,
...userArgs,
allTokens: {
some: {
OR: [
Expand Down
2 changes: 2 additions & 0 deletions modules/pool/pool.gql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extend type Query {
orderDirection: GqlPoolOrderDirection
where: GqlPoolFilter
textSearch: String
userAddress: String
): [GqlPoolMinimal!]!
poolGetPoolsCount(
first: Int
Expand All @@ -15,6 +16,7 @@ extend type Query {
orderDirection: GqlPoolOrderDirection
where: GqlPoolFilter
textSearch: String
userAddress: String
): Int!
poolGetSwaps(first: Int, skip: Int, where: GqlPoolSwapFilter): [GqlPoolSwap!]!
poolGetBatchSwaps(first: Int, skip: Int, where: GqlPoolSwapFilter): [GqlPoolBatchSwap!]!
Expand Down

0 comments on commit 37ff70c

Please sign in to comment.