Merge pull request #2 from jejolare-dev/feature/add-find-pair-page-from-old-repo
feat: add find pair page from old repo
This commit is contained in:
commit
bec9f220c1
3 changed files with 58 additions and 1 deletions
51
src/pages/dex/trading/find-pair/index.tsx
Normal file
51
src/pages/dex/trading/find-pair/index.tsx
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
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;
|
||||
|
||||
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, API_URL);
|
||||
|
||||
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 (
|
||||
<div>
|
||||
<h1 className={styles.title}>Error: {error}</h1>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
export default Page;
|
||||
6
src/styles/FindPair.module.scss
Normal file
6
src/styles/FindPair.module.scss
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
.title {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ export async function findPairID(
|
|||
second: string,
|
||||
host: string | undefined = undefined,
|
||||
): Promise<number | undefined> {
|
||||
const findPairURL = `${host ? `https://${host}` : ''}/api/dex/find-pair`;
|
||||
const findPairURL = `${host ?? ''}/api/dex/find-pair`;
|
||||
|
||||
console.log('Find pair URL:', findPairURL);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue