Skip to content

Commit

Permalink
Split create address filter into two
Browse files Browse the repository at this point in the history
  • Loading branch information
jm42 committed Apr 13, 2024
1 parent a8c793b commit 48e7e0c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
5 changes: 3 additions & 2 deletions packages/poaps/src/PoapsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
createBetweenFilter,
createEqFilter,
createInFilter,
createNotNullAddressFilter,
createOrderBy,
nextCursor,
PaginatedResult,
Expand Down Expand Up @@ -73,9 +74,9 @@ export class PoapsClient {
offset,
orderBy: createOrderBy<PoapsSortFields>(sortField, sortDir),
where: {
...createAddressFilter(
...createAddressFilter('collector_address', collectorAddress),
...createNotNullAddressFilter(
'collector_address',
collectorAddress,
filterZeroAddress,
filterDeadAddress,
),
Expand Down
51 changes: 27 additions & 24 deletions packages/utils/src/queries/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,40 +42,43 @@ export function createBoolFilter(
: {};
}

// eslint-disable-next-line complexity
export function createAddressFilter(
key: string,
value?: string,
filterZeroAddress?: boolean,
filterDeadAddress?: boolean,
): FieldFilter<
Partial<EqFilter<string>> &
Partial<NeqFilter<string>> &
Partial<NinFilter<string>>
> {
return filterZeroAddress || filterDeadAddress || value
): FieldFilter<Partial<EqFilter<string>>> {
return value
? {
[key]: {
...(filterZeroAddress && filterDeadAddress
? {
_nin: [
'0x0000000000000000000000000000000000000000',
'0x000000000000000000000000000000000000dead',
],
}
: {}),
...(filterZeroAddress && !filterDeadAddress
? { _neq: '0x0000000000000000000000000000000000000000' }
: {}),
...(!filterZeroAddress && filterDeadAddress
? { _neq: '0x000000000000000000000000000000000000dead' }
: {}),
...(value ? { _eq: value.toLowerCase() } : {}),
_eq: value.toLowerCase(),
},
}
: {};
}

export function createNotNullAddressFilter(
key: string,
filterZeroAddress = true,
filterDeadAddress = true,
): FieldFilter<Partial<NeqFilter<string>> & Partial<NinFilter<string>>> {
if (filterZeroAddress && filterDeadAddress) {
return {
[key]: {
_nin: [
'0x0000000000000000000000000000000000000000',
'0x000000000000000000000000000000000000dead',
],
},
};
}
if (filterZeroAddress) {
return { [key]: { _neq: '0x0000000000000000000000000000000000000000' } };
}
if (filterDeadAddress) {
return { [key]: { _neq: '0x000000000000000000000000000000000000dead' } };
}
return {};
}

export function createInFilter(
key: string,
values?: Array<Value>,
Expand Down

0 comments on commit 48e7e0c

Please sign in to comment.