|
7 | 7 | TableRow, |
8 | 8 | } from "@/components/ui/table"; |
9 | 9 | import type { Address } from "thirdweb"; |
| 10 | +import { checksumAddress } from "thirdweb/utils"; |
10 | 11 | import { getRoutes } from "../../../utils"; |
11 | 12 | import { ChainlistPagination } from "../client/pagination"; |
12 | 13 | import { RouteListCard } from "../server/routelist-card"; |
@@ -34,28 +35,83 @@ async function getRoutesToRender(params: SearchParams) { |
34 | 35 | originTokenAddress?: Address; |
35 | 36 | destinationChainId?: number; |
36 | 37 | destinationTokenAddress?: Address; |
| 38 | + originTextQuery?: string; |
| 39 | + destinationTextQuery?: string; |
37 | 40 | }> = {}; |
38 | 41 |
|
39 | 42 | if (params.type === "origin" || typeof params.type === "undefined") { |
40 | 43 | if (params.query?.startsWith("0x")) { |
41 | 44 | filters.originTokenAddress = params.query as Address; |
42 | | - } else if (params.query) { |
| 45 | + } else if (Number.isInteger(Number(params.query))) { |
43 | 46 | filters.originChainId = Number(params.query); |
| 47 | + } else if (params.query) { |
| 48 | + filters.originTextQuery = params.query; |
44 | 49 | } |
45 | 50 | } else if (params.type === "destination") { |
46 | 51 | if (params.query?.startsWith("0x")) { |
47 | 52 | filters.destinationTokenAddress = params.query as Address; |
48 | | - } else if (params.query) { |
| 53 | + } else if (Number.isInteger(Number(params.query))) { |
49 | 54 | filters.destinationChainId = Number(params.query); |
| 55 | + } else if (params.query) { |
| 56 | + filters.destinationTextQuery = params.query; |
50 | 57 | } |
51 | 58 | } |
52 | 59 | // 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 }); |
56 | 61 |
|
57 | 62 | const totalCount = routes.length; |
58 | 63 |
|
| 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 | + |
59 | 115 | return { |
60 | 116 | routesToRender: routes, |
61 | 117 | totalCount, |
@@ -154,13 +210,21 @@ export async function RoutesData(props: { |
154 | 210 | out of{" "} |
155 | 211 | {filteredCount !== totalCount ? ( |
156 | 212 | <> |
157 | | - <span className="text-accent-foreground">{filteredCount}</span>{" "} |
| 213 | + <span className="text-accent-foreground"> |
| 214 | + {filteredCount.toLocaleString()} |
| 215 | + </span>{" "} |
158 | 216 | 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 | + ) |
160 | 221 | </> |
161 | 222 | ) : ( |
162 | 223 | <> |
163 | | - <span className="text-accent-foreground">{totalCount}</span> routes. |
| 224 | + <span className="text-accent-foreground"> |
| 225 | + {totalCount.toLocaleString()} |
| 226 | + </span>{" "} |
| 227 | + routes. |
164 | 228 | </> |
165 | 229 | )} |
166 | 230 | </p> |
|
0 commit comments