2022-11-08 07:23:38 +00:00
|
|
|
import { Suspense } from 'react';
|
2022-12-22 14:24:20 +00:00
|
|
|
import type { RouteObject } from 'react-router-dom';
|
2022-11-08 07:23:38 +00:00
|
|
|
import { useRoutes } from 'react-router-dom';
|
|
|
|
import dynamic from 'next/dynamic';
|
|
|
|
import { t } from '@vegaprotocol/react-helpers';
|
2023-01-02 16:01:06 +00:00
|
|
|
import { Loader, Splash } from '@vegaprotocol/ui-toolkit';
|
2022-12-22 14:24:20 +00:00
|
|
|
import trimEnd from 'lodash/trimEnd';
|
2022-11-08 07:23:38 +00:00
|
|
|
|
|
|
|
const LazyHome = dynamic(() => import('../client-pages/home'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const LazyLiquidity = dynamic(() => import('../client-pages/liquidity'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const LazyMarkets = dynamic(() => import('../client-pages/markets'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const LazyMarket = dynamic(() => import('../client-pages/market'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const LazyPortfolio = dynamic(() => import('../client-pages/portfolio'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
export enum Routes {
|
|
|
|
HOME = '/',
|
2022-12-22 14:24:20 +00:00
|
|
|
MARKET = '/markets',
|
|
|
|
MARKETS = '/markets/all',
|
2022-11-08 07:23:38 +00:00
|
|
|
PORTFOLIO = '/portfolio',
|
2022-12-22 14:24:20 +00:00
|
|
|
LIQUIDITY = 'liquidity/:marketId',
|
2022-11-08 07:23:38 +00:00
|
|
|
}
|
|
|
|
|
2022-12-22 14:24:20 +00:00
|
|
|
type ConsoleLinks = { [r in Routes]: (...args: string[]) => string };
|
|
|
|
export const Links: ConsoleLinks = {
|
|
|
|
[Routes.HOME]: () => Routes.HOME,
|
|
|
|
[Routes.MARKET]: (marketId: string | null | undefined) =>
|
|
|
|
marketId ? trimEnd(`${Routes.MARKET}/${marketId}`, '/') : Routes.MARKET,
|
|
|
|
[Routes.MARKETS]: () => Routes.MARKETS,
|
|
|
|
[Routes.PORTFOLIO]: () => Routes.PORTFOLIO,
|
|
|
|
[Routes.LIQUIDITY]: (marketId: string) =>
|
|
|
|
Routes.LIQUIDITY.replace(':marketId', marketId),
|
|
|
|
};
|
|
|
|
|
|
|
|
const routerConfig: RouteObject[] = [
|
2022-11-08 07:23:38 +00:00
|
|
|
{
|
|
|
|
index: true,
|
|
|
|
element: <LazyHome />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: Routes.MARKETS,
|
|
|
|
element: <LazyMarkets />,
|
|
|
|
},
|
|
|
|
{
|
2022-12-22 14:24:20 +00:00
|
|
|
path: Routes.MARKET,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
index: true,
|
|
|
|
element: <LazyMarket />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ':marketId',
|
|
|
|
element: <LazyMarket />,
|
|
|
|
},
|
|
|
|
],
|
2022-11-08 07:23:38 +00:00
|
|
|
},
|
|
|
|
{
|
2022-12-22 14:24:20 +00:00
|
|
|
path: Routes.LIQUIDITY,
|
2022-11-08 07:23:38 +00:00
|
|
|
element: <LazyLiquidity />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: Routes.PORTFOLIO,
|
|
|
|
element: <LazyPortfolio />,
|
|
|
|
},
|
2022-12-08 08:47:30 +00:00
|
|
|
{
|
|
|
|
path: '*',
|
|
|
|
element: (
|
|
|
|
<Splash>
|
|
|
|
<p>{t('Not found')}</p>
|
|
|
|
</Splash>
|
|
|
|
),
|
|
|
|
},
|
2022-11-08 07:23:38 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
export const ClientRouter = () => {
|
|
|
|
const routes = useRoutes(routerConfig);
|
|
|
|
return (
|
|
|
|
<Suspense
|
|
|
|
fallback={
|
|
|
|
<div className="w-full h-full flex justify-center items-center">
|
2023-01-02 16:01:06 +00:00
|
|
|
<Loader />
|
2022-11-08 07:23:38 +00:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{routes}
|
|
|
|
</Suspense>
|
|
|
|
);
|
|
|
|
};
|