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';
|
2023-02-28 18:56:29 +00:00
|
|
|
import { t } from '@vegaprotocol/i18n';
|
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,
|
|
|
|
});
|
|
|
|
|
2023-04-26 15:17:23 +00:00
|
|
|
const LazySettings = dynamic(() => import('../client-pages/settings'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
2023-05-19 21:27:45 +00:00
|
|
|
const LazyDisclaimer = dynamic(() => import('../client-pages/disclaimer'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
2022-11-08 07:23:38 +00:00
|
|
|
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',
|
2023-04-26 15:17:23 +00:00
|
|
|
LIQUIDITY = 'liquidity/:marketId',
|
|
|
|
SETTINGS = 'settings',
|
2023-05-19 21:27:45 +00:00
|
|
|
DISCLAIMER = 'disclaimer',
|
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,
|
2023-04-18 12:55:11 +00:00
|
|
|
[Routes.LIQUIDITY]: (marketId: string | null | undefined) =>
|
|
|
|
marketId
|
|
|
|
? trimEnd(`${Routes.LIQUIDITY}/${marketId}`, '/')
|
|
|
|
: Routes.LIQUIDITY,
|
2023-04-26 15:17:23 +00:00
|
|
|
[Routes.SETTINGS]: () => Routes.SETTINGS,
|
2023-05-19 21:27:45 +00:00
|
|
|
[Routes.DISCLAIMER]: () => Routes.DISCLAIMER,
|
2022-12-22 14:24:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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 />,
|
2023-04-18 12:55:11 +00:00
|
|
|
children: [
|
|
|
|
{
|
|
|
|
index: true,
|
|
|
|
element: <LazyLiquidity />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ':marketId',
|
|
|
|
element: <LazyLiquidity />,
|
|
|
|
},
|
|
|
|
],
|
2022-11-08 07:23:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: Routes.PORTFOLIO,
|
|
|
|
element: <LazyPortfolio />,
|
|
|
|
},
|
2023-04-26 15:17:23 +00:00
|
|
|
{
|
|
|
|
path: Routes.SETTINGS,
|
|
|
|
element: <LazySettings />,
|
|
|
|
},
|
2023-05-19 21:27:45 +00:00
|
|
|
{
|
|
|
|
path: Routes.DISCLAIMER,
|
|
|
|
element: <LazyDisclaimer />,
|
|
|
|
},
|
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>
|
|
|
|
);
|
|
|
|
};
|