Skip to content

Commit

Permalink
fix: remove redirect loader (#189)
Browse files Browse the repository at this point in the history
* feat: add not found page

* feat: add page middleware
  • Loading branch information
VanishMax authored Dec 6, 2024
1 parent 32f5512 commit 8f1a5a7
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 50 deletions.
1 change: 1 addition & 0 deletions app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { NotFoundPage as default } from '@/pages/not-found';
6 changes: 0 additions & 6 deletions app/page.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions app/trade/page.ts

This file was deleted.

6 changes: 6 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Redirects "/" and "/trade" paths to "/trade/:primary/:numeraire"
export const config = {
matcher: ['/', '/trade'],
};

export { tradeMiddleware as middleware } from '@/pages/trade/index.server';
1 change: 1 addition & 0 deletions src/pages/not-found/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { NotFoundPage } from './page';
15 changes: 15 additions & 0 deletions src/pages/not-found/link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use client';

import Link from 'next/link';
import { PagePath } from '@/shared/const/pages';
import { Button } from '@penumbra-zone/ui/Button';

export const GoBackLink = () => {
return (
<div className='w-full desktop:w-48 desktop:mt-0'>
<Link href={PagePath.Trade}>
<Button>Go back</Button>
</Link>
</div>
);
};
21 changes: 21 additions & 0 deletions src/pages/not-found/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { XCircle } from 'lucide-react';
import { Text } from '@penumbra-zone/ui/Text';
import { PenumbraWaves } from '@/pages/explore/ui/waves';
import { GoBackLink } from './link';

export const NotFoundPage = () => {
return (
<div>
<PenumbraWaves />

<section className='h-[calc(100dvh_-_80px)] max-w-[1062px] flex flex-col items-center justify-center desktop:justify-start gap-6 pt-8 px-4 mx-auto text-neutral-light'>
<div className='flex flex-col gap-4 grow justify-center items-center desktop:justify-start desktop:grow-0'>
<XCircle className='size-12' />
<Text large>Page not found</Text>
</div>

<GoBackLink />
</section>
</div>
);
};
23 changes: 23 additions & 0 deletions src/pages/trade/api/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { NextResponse, NextRequest } from 'next/server';
import { ChainRegistryClient } from '@penumbra-labs/registry';
import { getClientSideEnv } from '@/shared/api/env/getClientSideEnv';
import { assetPatterns } from '@penumbra-zone/types/assets';

export const tradeMiddleware = async (request: NextRequest) => {
const { PENUMBRA_CHAIN_ID } = getClientSideEnv();

const chainRegistryClient = new ChainRegistryClient();
const registry = await chainRegistryClient.remote.get(PENUMBRA_CHAIN_ID);
const allAssets = registry
.getAllAssets()
.filter(m => !assetPatterns.delegationToken.matches(m.display))
.toSorted((a, b) => Number(b.priorityScore - a.priorityScore));

const baseAsset = allAssets[0]?.symbol;
const quoteAsset = allAssets[1]?.symbol;
if (!baseAsset || !quoteAsset) {
return NextResponse.redirect(new URL('not-found', request.url));
}

return NextResponse.redirect(new URL(`/trade/${baseAsset}/${quoteAsset}`, request.url));
};
1 change: 1 addition & 0 deletions src/pages/trade/index.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { tradeMiddleware } from './api/middleware';
41 changes: 0 additions & 41 deletions src/pages/trade/redirect.tsx

This file was deleted.

0 comments on commit 8f1a5a7

Please sign in to comment.