Skip to content

Commit

Permalink
return address results too
Browse files Browse the repository at this point in the history
  • Loading branch information
efstajas committed Jan 10, 2025
1 parent dbed3f1 commit 9a80a74
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/search-bar/components/result.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
{@html pickLabel(item)}
</div>
</a>
{:else if item.type === 'ens'}
{:else if item.type === 'address'}
<a class="search-result typo-text" href={`/app/${item.address}`}>
<IdentityBadge size="medium" disableTooltip={true} address={item.address} />
</a>
Expand Down
20 changes: 16 additions & 4 deletions src/lib/components/search-bar/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ensStore from '$lib/stores/ens/ens.store';
import mapFilterUndefined from '$lib/utils/map-filter-undefined';
import { BASE_URL } from '$lib/utils/base-url';
import network from '$lib/stores/wallet/network';
import { isAddress } from 'ethers';

const client = new MeiliSearch({
host: `${BASE_URL}/api/search`,
Expand Down Expand Up @@ -52,8 +53,7 @@ async function getEnsResult(q: string): Promise<Result | undefined> {

if (lookup) {
return {
type: 'ens',
name: q,
type: 'address',
address: lookup,
};
}
Expand All @@ -64,6 +64,17 @@ async function getEnsResult(q: string): Promise<Result | undefined> {
return undefined;
}

function getAddressResult(q: string): Result | undefined {
if (isAddress(q)) {
return {
type: 'address',
address: q,
};
}

return undefined;
}

export async function search(q: string): Promise<Result[]> {
const commonOptions: Partial<FederatedMultiSearchParams['queries'][number]> = {
attributesToHighlight: ['name'],
Expand Down Expand Up @@ -91,10 +102,11 @@ export async function search(q: string): Promise<Result[]> {

const parsedHits: Result[] = resultsSchema.parse(hits);

const [gitUrlResult, ensResult] = await Promise.all([
const [gitUrlResult, ensResult, addressResult] = await Promise.all([
getGitUrlResults(q, parsedHits),
getEnsResult(q),
getAddressResult(q),
]);

return mapFilterUndefined([ensResult, gitUrlResult, ...parsedHits], (v) => v);
return mapFilterUndefined([addressResult, ensResult, gitUrlResult, ...parsedHits], (v) => v);
}

0 comments on commit 9a80a74

Please sign in to comment.