From 8eb7ce8201f21a9dce2c0611a78caec39d1fc2ea Mon Sep 17 00:00:00 2001 From: Andrew Besedin Date: Fri, 9 Jan 2026 00:27:21 +0300 Subject: [PATCH 1/2] add: add find pair page --- src/pages/dex/trading/find-pair/index.tsx | 53 +++++++++++++++++++++++ src/styles/FindPair.module.scss | 6 +++ 2 files changed, 59 insertions(+) create mode 100644 src/pages/dex/trading/find-pair/index.tsx create mode 100644 src/styles/FindPair.module.scss diff --git a/src/pages/dex/trading/find-pair/index.tsx b/src/pages/dex/trading/find-pair/index.tsx new file mode 100644 index 0000000..cd3249a --- /dev/null +++ b/src/pages/dex/trading/find-pair/index.tsx @@ -0,0 +1,53 @@ +import { GetServerSideProps } from 'next'; + +import { findPairID } from '@/utils/methods'; +import styles from '@/styles/404.module.scss'; + +export const getServerSideProps: GetServerSideProps = async (context) => { + const { first, second } = context.query; + + if (!first || !second) { + return { + notFound: true, // Show a 404 page if parameters are missing + }; + } + + try { + const idFound = await findPairID( + first as string, + second as string, + context.req.headers.host as string, + ); + + console.log('ID found:', idFound); + + if (typeof idFound === 'number') { + return { + redirect: { + destination: `/dex/trading/${idFound}`, + permanent: false, + }, + }; + } + + return { + notFound: true, + }; + } catch (error) { + console.error('Error fetching pair ID:', error); + return { + props: { + error: 'Failed to resolve the pair.', + }, + }; + } +}; + +const Page = ({ error }: { error?: string }) => { + return ( +
+

Error: {error}

+
+ ); +}; +export default Page; diff --git a/src/styles/FindPair.module.scss b/src/styles/FindPair.module.scss new file mode 100644 index 0000000..13e1f82 --- /dev/null +++ b/src/styles/FindPair.module.scss @@ -0,0 +1,6 @@ +.title { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); +} From 972fc15bf4cbaf50f243ad4c9ce158014bd7b5d2 Mon Sep 17 00:00:00 2001 From: Andrew Besedin Date: Fri, 9 Jan 2026 01:04:22 +0300 Subject: [PATCH 2/2] fix: fix fetching pair id in find-pair page --- src/pages/dex/trading/find-pair/index.tsx | 8 +++----- src/utils/methods.ts | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/pages/dex/trading/find-pair/index.tsx b/src/pages/dex/trading/find-pair/index.tsx index cd3249a..24f94cf 100644 --- a/src/pages/dex/trading/find-pair/index.tsx +++ b/src/pages/dex/trading/find-pair/index.tsx @@ -3,6 +3,8 @@ import { GetServerSideProps } from 'next'; import { findPairID } from '@/utils/methods'; import styles from '@/styles/404.module.scss'; +const API_URL = process.env.NEXT_PUBLIC_API_URL; + export const getServerSideProps: GetServerSideProps = async (context) => { const { first, second } = context.query; @@ -13,11 +15,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => { } try { - const idFound = await findPairID( - first as string, - second as string, - context.req.headers.host as string, - ); + const idFound = await findPairID(first as string, second as string, API_URL); console.log('ID found:', idFound); diff --git a/src/utils/methods.ts b/src/utils/methods.ts index 89d6a41..5e86cfb 100644 --- a/src/utils/methods.ts +++ b/src/utils/methods.ts @@ -81,7 +81,7 @@ export async function findPairID( second: string, host: string | undefined = undefined, ): Promise { - const findPairURL = `${host ? `https://${host}` : ''}/api/dex/find-pair`; + const findPairURL = `${host ?? ''}/api/dex/find-pair`; console.log('Find pair URL:', findPairURL);