Skip to content

Commit 04943d7

Browse files
authored
[Dashboard] Feature: Token symbol search (#6617)
1 parent 2606da6 commit 04943d7

File tree

3 files changed

+74
-35
lines changed

3 files changed

+74
-35
lines changed

apps/dashboard/src/app/(dashboard)/(bridge)/routes/components/client/search.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const SearchInput: React.FC = () => {
4747
<div className="group relative w-full">
4848
<SearchIcon className="-translate-y-1/2 absolute top-[50%] left-3 size-4 text-muted-foreground" />
4949
<Input
50-
placeholder="Search by token address or chain ID"
50+
placeholder="Search with anything!"
5151
className="h-10 rounded-lg bg-card py-2 pl-9 lg:min-w-[300px]"
5252
defaultValue={searchParams?.get("query") || ""}
5353
onChange={(e) => handleSearch(e.target.value)}

apps/dashboard/src/app/(dashboard)/(bridge)/routes/components/server/routes-table.tsx

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
TableRow,
88
} from "@/components/ui/table";
99
import type { Address } from "thirdweb";
10+
import { checksumAddress } from "thirdweb/utils";
1011
import { getRoutes } from "../../../utils";
1112
import { ChainlistPagination } from "../client/pagination";
1213
import { RouteListCard } from "../server/routelist-card";
@@ -34,28 +35,83 @@ async function getRoutesToRender(params: SearchParams) {
3435
originTokenAddress?: Address;
3536
destinationChainId?: number;
3637
destinationTokenAddress?: Address;
38+
originTextQuery?: string;
39+
destinationTextQuery?: string;
3740
}> = {};
3841

3942
if (params.type === "origin" || typeof params.type === "undefined") {
4043
if (params.query?.startsWith("0x")) {
4144
filters.originTokenAddress = params.query as Address;
42-
} else if (params.query) {
45+
} else if (Number.isInteger(Number(params.query))) {
4346
filters.originChainId = Number(params.query);
47+
} else if (params.query) {
48+
filters.originTextQuery = params.query;
4449
}
4550
} else if (params.type === "destination") {
4651
if (params.query?.startsWith("0x")) {
4752
filters.destinationTokenAddress = params.query as Address;
48-
} else if (params.query) {
53+
} else if (Number.isInteger(Number(params.query))) {
4954
filters.destinationChainId = Number(params.query);
55+
} else if (params.query) {
56+
filters.destinationTextQuery = params.query;
5057
}
5158
}
5259
// Temporary, will update this after the /routes endpoint
53-
filters.limit = 50_000;
54-
55-
const routes = await getRoutes(filters);
60+
let routes = await getRoutes({ limit: 100_000 });
5661

5762
const totalCount = routes.length;
5863

64+
if (filters.originChainId) {
65+
routes = routes.filter(
66+
(route) => route.originToken.chainId === filters.originChainId,
67+
);
68+
}
69+
if (filters.originTokenAddress) {
70+
const originTokenAddress = filters.originTokenAddress;
71+
routes = routes.filter(
72+
(route) =>
73+
checksumAddress(route.originToken.address) ===
74+
checksumAddress(originTokenAddress),
75+
);
76+
}
77+
if (filters.destinationChainId) {
78+
routes = routes.filter(
79+
(route) => route.destinationToken.chainId === filters.destinationChainId,
80+
);
81+
}
82+
if (filters.destinationTokenAddress) {
83+
const destinationTokenAddress = filters.destinationTokenAddress;
84+
routes = routes.filter(
85+
(route) =>
86+
checksumAddress(route.destinationToken.address) ===
87+
checksumAddress(destinationTokenAddress),
88+
);
89+
}
90+
91+
if (filters.originTextQuery) {
92+
const originTextQuery = filters.originTextQuery.toLowerCase();
93+
routes = routes.filter((route) => {
94+
return (
95+
route.originToken.name.toLowerCase().includes(originTextQuery) ||
96+
route.originToken.symbol.toLowerCase().includes(originTextQuery)
97+
);
98+
});
99+
}
100+
101+
if (filters.destinationTextQuery) {
102+
const destinationTextQuery = filters.destinationTextQuery.toLowerCase();
103+
routes = routes.filter((route) => {
104+
return (
105+
route.destinationToken.name
106+
.toLowerCase()
107+
.includes(destinationTextQuery) ||
108+
route.destinationToken.symbol
109+
.toLowerCase()
110+
.includes(destinationTextQuery)
111+
);
112+
});
113+
}
114+
59115
return {
60116
routesToRender: routes,
61117
totalCount,
@@ -154,13 +210,21 @@ export async function RoutesData(props: {
154210
out of{" "}
155211
{filteredCount !== totalCount ? (
156212
<>
157-
<span className="text-accent-foreground">{filteredCount}</span>{" "}
213+
<span className="text-accent-foreground">
214+
{filteredCount.toLocaleString()}
215+
</span>{" "}
158216
routes that match filters. (Total:{" "}
159-
<span className="text-accent-foreground">{totalCount}</span>)
217+
<span className="text-accent-foreground">
218+
{totalCount.toLocaleString()}
219+
</span>
220+
)
160221
</>
161222
) : (
162223
<>
163-
<span className="text-accent-foreground">{totalCount}</span> routes.
224+
<span className="text-accent-foreground">
225+
{totalCount.toLocaleString()}
226+
</span>{" "}
227+
routes.
164228
</>
165229
)}
166230
</p>

apps/dashboard/src/app/(dashboard)/(bridge)/utils.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,18 @@ import "server-only";
22

33
import { BRIDGE_URL, DASHBOARD_THIRDWEB_SECRET_KEY } from "@/constants/env";
44
import { getAuthToken } from "app/api/lib/getAuthToken";
5-
import type { Address } from "thirdweb";
65
import type { Route } from "./types/route";
76

87
export async function getRoutes({
98
limit,
10-
offset,
11-
originChainId,
12-
originTokenAddress,
13-
destinationChainId,
14-
destinationTokenAddress,
159
}: {
1610
limit?: number;
17-
offset?: number;
18-
originChainId?: number;
19-
originTokenAddress?: Address;
20-
destinationChainId?: number;
21-
destinationTokenAddress?: Address;
2211
} = {}) {
2312
const url = new URL(`${BRIDGE_URL}/v1/routes`);
2413
if (limit) {
2514
url.searchParams.set("limit", limit.toString());
2615
}
27-
if (offset) {
28-
url.searchParams.set("offset", offset.toString());
29-
}
30-
if (originChainId) {
31-
url.searchParams.set("originChainId", originChainId.toString());
32-
}
33-
if (originTokenAddress) {
34-
url.searchParams.set("originTokenAddress", originTokenAddress);
35-
}
36-
if (destinationChainId) {
37-
url.searchParams.set("destinationChainId", destinationChainId.toString());
38-
}
39-
if (destinationTokenAddress) {
40-
url.searchParams.set("destinationTokenAddress", destinationTokenAddress);
41-
}
16+
// It's faster to filter client side, doesn't seem to be a big performance boost to paginate/filter server side
4217
const token = await getAuthToken();
4318
const routesResponse = await fetch(url, {
4419
headers: token

0 commit comments

Comments
 (0)