Skip to content

Commit

Permalink
add searchType to getNamesForAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Mar 13, 2024
1 parent 19cbffa commit 9e63625
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
20 changes: 20 additions & 0 deletions packages/ensjs/src/functions/subgraph/getNamesForAddress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,26 @@ describe('filter', () => {
expect(name.labelName).toContain('test123')
}
})
it.only('filters by search string - name', async () => {
const result = await getNamesForAddress(publicClient, {
address: accounts[2],
pageSize: 1000,
filter: {
owner: true,
registrant: true,
resolvedAddress: true,
wrappedOwner: true,
searchString: 'wrapped-with-subnames',
searchType: 'name',
},
})

if (!result.length) throw new Error('No names found')
const subnames = result.filter(
(x) => x.parentName === 'wrapped-with-subnames.eth',
)
expect(subnames.length).toBeGreaterThan(0)
})
})

describe.each([
Expand Down
12 changes: 7 additions & 5 deletions packages/ensjs/src/functions/subgraph/getNamesForAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ type GetNamesForAddressRelation = {
}

type GetNamesForAddressFilter = GetNamesForAddressRelation & {
/** Search string filter for subname label */
/** Search string filter for name */
searchString?: string
/** Search string filter type (default: `labelName`) */
searchType?: 'labelName' | 'name'
/** Allows expired names to be included (default: false) */
allowExpired?: boolean
/** Allows reverse record nodes to be included (default: false) */
Expand Down Expand Up @@ -179,8 +181,9 @@ const getNamesForAddress = async (
allowExpired: false,
allowDeleted: false,
allowReverseRecord: false,
searchType: 'labelName',
..._filter,
}
} as const

const subgraphClient = createSubgraphClient({ client })

Expand All @@ -189,6 +192,7 @@ const getNamesForAddress = async (
allowDeleted,
allowReverseRecord,
searchString,
searchType,
...filters
} = filter
const ownerWhereFilters: DomainFilter[] = Object.entries(filters).reduce(
Expand Down Expand Up @@ -281,10 +285,8 @@ const getNamesForAddress = async (
}

if (searchString) {
// using labelName_contains instead of name_contains because name_contains
// includes the parent name
whereFilters.push({
labelName_contains: searchString,
[`${searchType}_contains`]: searchString,
})
}

Expand Down

0 comments on commit 9e63625

Please sign in to comment.