-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
middleware: route default home page to explore page (#346)
- Loading branch information
Showing
6 changed files
with
40 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Redirects "/" and "/trade" paths to "/trade/:primary/:numeraire" | ||
// Redirects "/" and "/trade" paths to paths defined in the routing middleware. | ||
export const config = { | ||
matcher: ['/', '/trade'], | ||
}; | ||
|
||
export { tradeMiddleware as middleware } from '@/pages/trade/index.server'; | ||
export { routingMiddleware as middleware } from '@/shared/index.server'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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 routingMiddleware = async (request: NextRequest) => { | ||
const { pathname, origin } = request.nextUrl; | ||
|
||
if (pathname === '/') { | ||
// Redirect the default homepage to the 'explore' page. | ||
// TODO: Replace this with a path to a fully designed landing page. | ||
return NextResponse.redirect(`${origin}/explore`); | ||
} | ||
|
||
// Otherwise, route to the default trading pair on the trading page. | ||
if (pathname === '/trade') { | ||
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)); | ||
} | ||
|
||
return NextResponse.next(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { routingMiddleware } from './api/middleware'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters