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';
|
2023-07-24 08:37:18 +00:00
|
|
|
import { Outlet, useRoutes } from 'react-router-dom';
|
2022-11-08 07:23:38 +00:00
|
|
|
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';
|
2023-07-24 08:37:18 +00:00
|
|
|
import { LayoutWithSidebar } from '../components/layouts';
|
2023-09-19 06:15:36 +00:00
|
|
|
import { Deposit } from '../client-pages/deposit';
|
|
|
|
import { Withdraw } from '../client-pages/withdraw';
|
|
|
|
import { Transfer } from '../client-pages/transfer';
|
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-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 = '/',
|
2023-07-24 08:37:18 +00:00
|
|
|
MARKET = '/markets/:marketId',
|
2022-12-22 14:24:20 +00:00
|
|
|
MARKETS = '/markets/all',
|
2022-11-08 07:23:38 +00:00
|
|
|
PORTFOLIO = '/portfolio',
|
2023-07-24 08:37:18 +00:00
|
|
|
LIQUIDITY = '/liquidity/:marketId',
|
|
|
|
DISCLAIMER = '/disclaimer',
|
2023-08-02 17:06:49 +00:00
|
|
|
DEPOSIT = '/deposit',
|
2023-09-19 06:15:36 +00:00
|
|
|
WITHDRAW = '/withdraw',
|
|
|
|
TRANSFER = '/transfer',
|
2022-11-08 07:23:38 +00:00
|
|
|
}
|
|
|
|
|
2022-12-22 14:24:20 +00:00
|
|
|
type ConsoleLinks = { [r in Routes]: (...args: string[]) => string };
|
2023-07-24 08:37:18 +00:00
|
|
|
|
2022-12-22 14:24:20 +00:00
|
|
|
export const Links: ConsoleLinks = {
|
|
|
|
[Routes.HOME]: () => Routes.HOME,
|
2023-07-24 08:37:18 +00:00
|
|
|
[Routes.MARKET]: (marketId: string) =>
|
|
|
|
trimEnd(Routes.MARKET.replace(':marketId', marketId)),
|
2022-12-22 14:24:20 +00:00
|
|
|
[Routes.MARKETS]: () => Routes.MARKETS,
|
|
|
|
[Routes.PORTFOLIO]: () => Routes.PORTFOLIO,
|
2023-07-24 08:37:18 +00:00
|
|
|
[Routes.LIQUIDITY]: (marketId: string) =>
|
|
|
|
trimEnd(Routes.LIQUIDITY.replace(':marketId', marketId)),
|
2023-05-19 21:27:45 +00:00
|
|
|
[Routes.DISCLAIMER]: () => Routes.DISCLAIMER,
|
2023-08-02 17:06:49 +00:00
|
|
|
[Routes.DEPOSIT]: () => Routes.DEPOSIT,
|
2023-09-19 06:15:36 +00:00
|
|
|
[Routes.WITHDRAW]: () => Routes.WITHDRAW,
|
|
|
|
[Routes.TRANSFER]: () => Routes.TRANSFER,
|
2022-12-22 14:24:20 +00:00
|
|
|
};
|
|
|
|
|
2023-09-15 12:36:08 +00:00
|
|
|
export const routerConfig: RouteObject[] = [
|
2022-11-08 07:23:38 +00:00
|
|
|
{
|
2023-07-24 08:37:18 +00:00
|
|
|
path: '/*',
|
|
|
|
element: <LayoutWithSidebar />,
|
2022-12-22 14:24:20 +00:00
|
|
|
children: [
|
2023-07-24 08:37:18 +00:00
|
|
|
// all pages that require the Layout component (Sidebar)
|
2022-12-22 14:24:20 +00:00
|
|
|
{
|
|
|
|
index: true,
|
2023-07-24 08:37:18 +00:00
|
|
|
element: <LazyHome />,
|
2023-09-15 12:36:08 +00:00
|
|
|
id: Routes.HOME,
|
2022-12-22 14:24:20 +00:00
|
|
|
},
|
|
|
|
{
|
2023-07-24 08:37:18 +00:00
|
|
|
path: 'markets',
|
|
|
|
element: <Outlet />,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: 'all',
|
|
|
|
element: <LazyMarkets />,
|
2023-09-15 12:36:08 +00:00
|
|
|
id: Routes.MARKETS,
|
2023-07-24 08:37:18 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ':marketId',
|
|
|
|
element: <LazyMarket />,
|
2023-09-15 12:36:08 +00:00
|
|
|
id: Routes.MARKET,
|
2023-07-24 08:37:18 +00:00
|
|
|
},
|
|
|
|
],
|
2022-12-22 14:24:20 +00:00
|
|
|
},
|
2023-04-18 12:55:11 +00:00
|
|
|
{
|
2023-07-24 08:37:18 +00:00
|
|
|
path: 'portfolio',
|
|
|
|
element: <LazyPortfolio />,
|
2023-09-15 12:36:08 +00:00
|
|
|
id: Routes.PORTFOLIO,
|
2023-04-18 12:55:11 +00:00
|
|
|
},
|
|
|
|
{
|
2023-07-24 08:37:18 +00:00
|
|
|
path: 'liquidity',
|
|
|
|
element: <Outlet />,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: ':marketId',
|
|
|
|
element: <LazyLiquidity />,
|
2023-09-15 12:36:08 +00:00
|
|
|
id: Routes.LIQUIDITY,
|
2023-07-24 08:37:18 +00:00
|
|
|
},
|
|
|
|
],
|
2023-04-18 12:55:11 +00:00
|
|
|
},
|
|
|
|
],
|
2022-11-08 07:23:38 +00:00
|
|
|
},
|
2023-05-19 21:27:45 +00:00
|
|
|
{
|
|
|
|
path: Routes.DISCLAIMER,
|
|
|
|
element: <LazyDisclaimer />,
|
|
|
|
},
|
2023-09-19 06:15:36 +00:00
|
|
|
{ path: Routes.DEPOSIT, element: <Deposit /> },
|
|
|
|
{ path: Routes.WITHDRAW, element: <Withdraw /> },
|
|
|
|
{ path: Routes.TRANSFER, element: <Transfer /> },
|
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={
|
2023-09-19 06:15:36 +00:00
|
|
|
<div className="flex items-center justify-center w-full h-full">
|
2023-01-02 16:01:06 +00:00
|
|
|
<Loader />
|
2022-11-08 07:23:38 +00:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{routes}
|
|
|
|
</Suspense>
|
|
|
|
);
|
|
|
|
};
|