Skip to content

Commit df29320

Browse files
authored
add filter by chain id to chains API endpoint (#165)
1 parent f869467 commit df29320

File tree

3 files changed

+82
-65
lines changed

3 files changed

+82
-65
lines changed

app/api/chains/route.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
import { NextResponse } from 'next/server';
1+
import { NextResponse, NextRequest } from 'next/server';
22
import { Chains } from '@/types';
33
import fs from 'fs/promises';
44
import path from 'path';
5+
import { pickBy } from 'es-toolkit';
56

6-
export async function GET() {
7+
export async function GET(_req: NextRequest) {
78
try {
9+
const chainIds = _req.nextUrl.searchParams.get('chain_ids')?.split(',');
810
const filePath = path.join(process.cwd(), 'data', 'chains.json');
911
const jsonData = await fs.readFile(filePath, 'utf8');
12+
1013
const chainsData: Chains = JSON.parse(jsonData);
14+
const filteredChains = chainIds && chainIds.length > 0 ?
15+
pickBy(chainsData, (_, chainId) => chainIds.includes(String(chainId))) :
16+
chainsData;
1117

12-
return NextResponse.json(chainsData);
18+
return NextResponse.json(filteredChains);
1319
} catch (error) {
1420
console.error('Error reading chains data:', error);
1521
return NextResponse.json({ error: 'Failed to load chains data' }, { status: 500 });

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"dependencies": {
1212
"@svgr/webpack": "^8.1.0",
13+
"es-toolkit": "1.41.0",
1314
"next": "^14.2.28",
1415
"react": "^18",
1516
"react-dom": "^18"

yarn.lock

Lines changed: 72 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -994,10 +994,10 @@
994994
"@emnapi/runtime" "^1.4.0"
995995
"@tybys/wasm-util" "^0.9.0"
996996

997-
"@next/env@14.2.5":
998-
version "14.2.5"
999-
resolved "https://registry.yarnpkg.com/@next/env/-/env-14.2.5.tgz#1d9328ab828711d3517d0a1d505acb55e5ef7ad0"
1000-
integrity sha512-/zZGkrTOsraVfYjGP8uM0p6r0BDT6xWpkjdVbcz66PJVSpwXX3yNiRycxAuDfBKGWBrZBXRuK/YVlkNgxHGwmA==
997+
"@next/env@14.2.33":
998+
version "14.2.33"
999+
resolved "https://registry.yarnpkg.com/@next/env/-/env-14.2.33.tgz#ac87a781fd485b740f3f9bd94efc02cb9826f694"
1000+
integrity sha512-CgVHNZ1fRIlxkLhIX22flAZI/HmpDaZ8vwyJ/B0SDPTBuLZ1PJ+DWMjCHhqnExfmSQzA/PbZi8OAc7PAq2w9IA==
10011001

10021002
"@next/eslint-plugin-next@14.2.5":
10031003
version "14.2.5"
@@ -1006,50 +1006,50 @@
10061006
dependencies:
10071007
glob "10.3.10"
10081008

1009-
"@next/swc-darwin-arm64@14.2.5":
1010-
version "14.2.5"
1011-
resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.5.tgz#d0a160cf78c18731c51cc0bff131c706b3e9bb05"
1012-
integrity sha512-/9zVxJ+K9lrzSGli1///ujyRfon/ZneeZ+v4ptpiPoOU+GKZnm8Wj8ELWU1Pm7GHltYRBklmXMTUqM/DqQ99FQ==
1013-
1014-
"@next/swc-darwin-x64@14.2.5":
1015-
version "14.2.5"
1016-
resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.5.tgz#eb832a992407f6e6352eed05a073379f1ce0589c"
1017-
integrity sha512-vXHOPCwfDe9qLDuq7U1OYM2wUY+KQ4Ex6ozwsKxp26BlJ6XXbHleOUldenM67JRyBfVjv371oneEvYd3H2gNSA==
1018-
1019-
"@next/swc-linux-arm64-gnu@14.2.5":
1020-
version "14.2.5"
1021-
resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.5.tgz#098fdab57a4664969bc905f5801ef5a89582c689"
1022-
integrity sha512-vlhB8wI+lj8q1ExFW8lbWutA4M2ZazQNvMWuEDqZcuJJc78iUnLdPPunBPX8rC4IgT6lIx/adB+Cwrl99MzNaA==
1023-
1024-
"@next/swc-linux-arm64-musl@14.2.5":
1025-
version "14.2.5"
1026-
resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.5.tgz#243a1cc1087fb75481726dd289c7b219fa01f2b5"
1027-
integrity sha512-NpDB9NUR2t0hXzJJwQSGu1IAOYybsfeB+LxpGsXrRIb7QOrYmidJz3shzY8cM6+rO4Aojuef0N/PEaX18pi9OA==
1028-
1029-
"@next/swc-linux-x64-gnu@14.2.5":
1030-
version "14.2.5"
1031-
resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.5.tgz#b8a2e436387ee4a52aa9719b718992e0330c4953"
1032-
integrity sha512-8XFikMSxWleYNryWIjiCX+gU201YS+erTUidKdyOVYi5qUQo/gRxv/3N1oZFCgqpesN6FPeqGM72Zve+nReVXQ==
1033-
1034-
"@next/swc-linux-x64-musl@14.2.5":
1035-
version "14.2.5"
1036-
resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.5.tgz#cb8a9adad5fb8df86112cfbd363aab5c6d32757b"
1037-
integrity sha512-6QLwi7RaYiQDcRDSU/os40r5o06b5ue7Jsk5JgdRBGGp8l37RZEh9JsLSM8QF0YDsgcosSeHjglgqi25+m04IQ==
1038-
1039-
"@next/swc-win32-arm64-msvc@14.2.5":
1040-
version "14.2.5"
1041-
resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.5.tgz#81f996c1c38ea0900d4e7719cc8814be8a835da0"
1042-
integrity sha512-1GpG2VhbspO+aYoMOQPQiqc/tG3LzmsdBH0LhnDS3JrtDx2QmzXe0B6mSZZiN3Bq7IOMXxv1nlsjzoS1+9mzZw==
1043-
1044-
"@next/swc-win32-ia32-msvc@14.2.5":
1045-
version "14.2.5"
1046-
resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.5.tgz#f61c74ce823e10b2bc150e648fc192a7056422e0"
1047-
integrity sha512-Igh9ZlxwvCDsu6438FXlQTHlRno4gFpJzqPjSIBZooD22tKeI4fE/YMRoHVJHmrQ2P5YL1DoZ0qaOKkbeFWeMg==
1048-
1049-
"@next/swc-win32-x64-msvc@14.2.5":
1050-
version "14.2.5"
1051-
resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.5.tgz#ed199a920efb510cfe941cd75ed38a7be21e756f"
1052-
integrity sha512-tEQ7oinq1/CjSG9uSTerca3v4AZ+dFa+4Yu6ihaG8Ud8ddqLQgFGcnwYls13H5X5CPDPZJdYxyeMui6muOLd4g==
1009+
"@next/swc-darwin-arm64@14.2.33":
1010+
version "14.2.33"
1011+
resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.33.tgz#9e74a4223f1e5e39ca4f9f85709e0d95b869b298"
1012+
integrity sha512-HqYnb6pxlsshoSTubdXKu15g3iivcbsMXg4bYpjL2iS/V6aQot+iyF4BUc2qA/J/n55YtvE4PHMKWBKGCF/+wA==
1013+
1014+
"@next/swc-darwin-x64@14.2.33":
1015+
version "14.2.33"
1016+
resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.33.tgz#fcf0c45938da9b0cc2ec86357d6aefca90bd17f3"
1017+
integrity sha512-8HGBeAE5rX3jzKvF593XTTFg3gxeU4f+UWnswa6JPhzaR6+zblO5+fjltJWIZc4aUalqTclvN2QtTC37LxvZAA==
1018+
1019+
"@next/swc-linux-arm64-gnu@14.2.33":
1020+
version "14.2.33"
1021+
resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.33.tgz#837f91a740eb4420c06f34c4677645315479d9be"
1022+
integrity sha512-JXMBka6lNNmqbkvcTtaX8Gu5by9547bukHQvPoLe9VRBx1gHwzf5tdt4AaezW85HAB3pikcvyqBToRTDA4DeLw==
1023+
1024+
"@next/swc-linux-arm64-musl@14.2.33":
1025+
version "14.2.33"
1026+
resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.33.tgz#dc8903469e5c887b25e3c2217a048bd30c58d3d4"
1027+
integrity sha512-Bm+QulsAItD/x6Ih8wGIMfRJy4G73tu1HJsrccPW6AfqdZd0Sfm5Imhgkgq2+kly065rYMnCOxTBvmvFY1BKfg==
1028+
1029+
"@next/swc-linux-x64-gnu@14.2.33":
1030+
version "14.2.33"
1031+
resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.33.tgz#344438be592b6b28cc540194274561e41f9933e5"
1032+
integrity sha512-FnFn+ZBgsVMbGDsTqo8zsnRzydvsGV8vfiWwUo1LD8FTmPTdV+otGSWKc4LJec0oSexFnCYVO4hX8P8qQKaSlg==
1033+
1034+
"@next/swc-linux-x64-musl@14.2.33":
1035+
version "14.2.33"
1036+
resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.33.tgz#3379fad5e0181000b2a4fac0b80f7ca4ffe795c8"
1037+
integrity sha512-345tsIWMzoXaQndUTDv1qypDRiebFxGYx9pYkhwY4hBRaOLt8UGfiWKr9FSSHs25dFIf8ZqIFaPdy5MljdoawA==
1038+
1039+
"@next/swc-win32-arm64-msvc@14.2.33":
1040+
version "14.2.33"
1041+
resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.33.tgz#bca8f4dde34656aef8e99f1e5696de255c2f00e5"
1042+
integrity sha512-nscpt0G6UCTkrT2ppnJnFsYbPDQwmum4GNXYTeoTIdsmMydSKFz9Iny2jpaRupTb+Wl298+Rh82WKzt9LCcqSQ==
1043+
1044+
"@next/swc-win32-ia32-msvc@14.2.33":
1045+
version "14.2.33"
1046+
resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.33.tgz#a69c581483ea51dd3b8907ce33bb101fe07ec1df"
1047+
integrity sha512-pc9LpGNKhJ0dXQhZ5QMmYxtARwwmWLpeocFmVG5Z0DzWq5Uf0izcI8tLc+qOpqxO1PWqZ5A7J1blrUIKrIFc7Q==
1048+
1049+
"@next/swc-win32-x64-msvc@14.2.33":
1050+
version "14.2.33"
1051+
resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.33.tgz#f1a40062530c17c35a86d8c430b3ae465eb7cea1"
1052+
integrity sha512-nOjfZMy8B94MdisuzZo9/57xuFVLHJaDj5e/xrduJp9CV2/HrfxTRH2fbyLe+K9QT41WBLUd4iXX3R7jBp0EUg==
10531053

10541054
"@nodelib/fs.scandir@2.1.5":
10551055
version "2.1.5"
@@ -1253,6 +1253,11 @@
12531253
"@types/prop-types" "*"
12541254
csstype "^3.0.2"
12551255

1256+
"@types/tough-cookie@^4.0.5":
1257+
version "4.0.5"
1258+
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.5.tgz#cb6e2a691b70cb177c6e3ae9c1d2e8b2ea8cd304"
1259+
integrity sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==
1260+
12561261
"@typescript-eslint/parser@^5.4.2 || ^6.0.0 || 7.0.0 - 7.2.0":
12571262
version "7.2.0"
12581263
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-7.2.0.tgz#44356312aea8852a3a82deebdacd52ba614ec07a"
@@ -2147,6 +2152,11 @@ es-to-primitive@^1.3.0:
21472152
is-date-object "^1.0.5"
21482153
is-symbol "^1.0.4"
21492154

2155+
es-toolkit@1.41.0:
2156+
version "1.41.0"
2157+
resolved "https://registry.yarnpkg.com/es-toolkit/-/es-toolkit-1.41.0.tgz#84eacd54dcc88261d78005fde7a01c2291b90628"
2158+
integrity sha512-bDd3oRmbVgqZCJS6WmeQieOrzpl3URcWBUVDXxOELlUW2FuW+0glPOz1n0KnRie+PdyvUZcXz2sOn00c6pPRIA==
2159+
21502160
escalade@^3.2.0:
21512161
version "3.2.0"
21522162
resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.2.0.tgz#011a3f69856ba189dffa7dc8fcce99d2a87903e5"
@@ -3194,28 +3204,28 @@ natural-compare@^1.4.0:
31943204
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
31953205
integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==
31963206

3197-
next@14.2.5:
3198-
version "14.2.5"
3199-
resolved "https://registry.yarnpkg.com/next/-/next-14.2.5.tgz#afe4022bb0b752962e2205836587a289270efbea"
3200-
integrity sha512-0f8aRfBVL+mpzfBjYfQuLWh2WyAwtJXCRfkPF4UJ5qd2YwrHczsrSzXU4tRMV0OAxR8ZJZWPFn6uhSC56UTsLA==
3207+
next@^14.2.28:
3208+
version "14.2.33"
3209+
resolved "https://registry.yarnpkg.com/next/-/next-14.2.33.tgz#284bc3de43d9319b7b41d4b69ec9a0ff0905a9e3"
3210+
integrity sha512-GiKHLsD00t4ACm1p00VgrI0rUFAC9cRDGReKyERlM57aeEZkOQGcZTpIbsGn0b562FTPJWmYfKwplfO9EaT6ng==
32013211
dependencies:
3202-
"@next/env" "14.2.5"
3212+
"@next/env" "14.2.33"
32033213
"@swc/helpers" "0.5.5"
32043214
busboy "1.6.0"
32053215
caniuse-lite "^1.0.30001579"
32063216
graceful-fs "^4.2.11"
32073217
postcss "8.4.31"
32083218
styled-jsx "5.1.1"
32093219
optionalDependencies:
3210-
"@next/swc-darwin-arm64" "14.2.5"
3211-
"@next/swc-darwin-x64" "14.2.5"
3212-
"@next/swc-linux-arm64-gnu" "14.2.5"
3213-
"@next/swc-linux-arm64-musl" "14.2.5"
3214-
"@next/swc-linux-x64-gnu" "14.2.5"
3215-
"@next/swc-linux-x64-musl" "14.2.5"
3216-
"@next/swc-win32-arm64-msvc" "14.2.5"
3217-
"@next/swc-win32-ia32-msvc" "14.2.5"
3218-
"@next/swc-win32-x64-msvc" "14.2.5"
3220+
"@next/swc-darwin-arm64" "14.2.33"
3221+
"@next/swc-darwin-x64" "14.2.33"
3222+
"@next/swc-linux-arm64-gnu" "14.2.33"
3223+
"@next/swc-linux-arm64-musl" "14.2.33"
3224+
"@next/swc-linux-x64-gnu" "14.2.33"
3225+
"@next/swc-linux-x64-musl" "14.2.33"
3226+
"@next/swc-win32-arm64-msvc" "14.2.33"
3227+
"@next/swc-win32-ia32-msvc" "14.2.33"
3228+
"@next/swc-win32-x64-msvc" "14.2.33"
32193229

32203230
no-case@^3.0.4:
32213231
version "3.0.4"

0 commit comments

Comments
 (0)