2023-01-17 09:59:12 +00:00
|
|
|
import { useState } from 'react';
|
2022-08-25 14:23:57 +00:00
|
|
|
import classNames from 'classnames';
|
2022-11-08 07:23:38 +00:00
|
|
|
import { NavLink, Link } from 'react-router-dom';
|
2022-12-22 14:24:20 +00:00
|
|
|
import {
|
|
|
|
DApp,
|
|
|
|
NetworkSwitcher,
|
|
|
|
TOKEN_GOVERNANCE,
|
|
|
|
useLinks,
|
|
|
|
} from '@vegaprotocol/environment';
|
2022-06-08 08:47:31 +00:00
|
|
|
import { t } from '@vegaprotocol/react-helpers';
|
2023-02-06 11:18:14 +00:00
|
|
|
import { useGlobalStore } from '../../stores';
|
2022-08-31 04:35:46 +00:00
|
|
|
import { VegaWalletConnectButton } from '../vega-wallet-connect-button';
|
2022-12-06 16:00:37 +00:00
|
|
|
import {
|
2023-01-19 22:15:55 +00:00
|
|
|
Drawer,
|
2022-12-06 16:00:37 +00:00
|
|
|
getNavLinkClassNames,
|
|
|
|
getActiveNavLinkClassNames,
|
|
|
|
Nav,
|
2023-01-19 22:15:55 +00:00
|
|
|
NewTab,
|
|
|
|
ThemeSwitcher,
|
2022-12-06 16:00:37 +00:00
|
|
|
} from '@vegaprotocol/ui-toolkit';
|
2023-01-19 22:15:55 +00:00
|
|
|
import { Vega } from '../icons/vega';
|
|
|
|
import type { HTMLAttributeAnchorTarget } from 'react';
|
|
|
|
import { Links, Routes } from '../../pages/client-router';
|
2022-03-14 13:18:11 +00:00
|
|
|
|
2022-10-28 15:13:14 +00:00
|
|
|
type NavbarTheme = 'inherit' | 'dark' | 'yellow';
|
2022-08-31 04:35:46 +00:00
|
|
|
interface NavbarProps {
|
2022-10-28 15:13:14 +00:00
|
|
|
navbarTheme?: NavbarTheme;
|
2022-08-31 04:35:46 +00:00
|
|
|
}
|
|
|
|
|
2023-01-17 09:59:12 +00:00
|
|
|
const LinkList = ({
|
|
|
|
navbarTheme,
|
|
|
|
className = 'flex',
|
|
|
|
dataTestId = 'navbar-links',
|
|
|
|
onNavigate,
|
|
|
|
}: {
|
|
|
|
navbarTheme: NavbarTheme;
|
|
|
|
className?: string;
|
|
|
|
dataTestId?: string;
|
|
|
|
onNavigate?: () => void;
|
|
|
|
}) => {
|
2022-12-22 14:24:20 +00:00
|
|
|
const tokenLink = useLinks(DApp.Token);
|
2022-10-14 15:42:53 +00:00
|
|
|
const { marketId } = useGlobalStore((store) => ({
|
2022-09-05 14:25:33 +00:00
|
|
|
marketId: store.marketId,
|
|
|
|
}));
|
2022-12-22 14:24:20 +00:00
|
|
|
const tradingPath = marketId
|
|
|
|
? Links[Routes.MARKET](marketId)
|
|
|
|
: Links[Routes.MARKET]();
|
2022-03-14 13:18:11 +00:00
|
|
|
return (
|
2023-01-17 09:59:12 +00:00
|
|
|
<div className={className} data-testid={dataTestId}>
|
2022-12-15 07:45:03 +00:00
|
|
|
<AppNavLink
|
|
|
|
name={t('Markets')}
|
2022-12-22 14:24:20 +00:00
|
|
|
path={Links[Routes.MARKETS]()}
|
2022-12-15 07:45:03 +00:00
|
|
|
navbarTheme={navbarTheme}
|
2023-01-17 09:59:12 +00:00
|
|
|
onClick={onNavigate}
|
2022-12-15 07:45:03 +00:00
|
|
|
end
|
|
|
|
/>
|
2022-12-06 16:00:37 +00:00
|
|
|
<AppNavLink
|
|
|
|
name={t('Trading')}
|
|
|
|
path={tradingPath}
|
|
|
|
navbarTheme={navbarTheme}
|
2023-01-17 09:59:12 +00:00
|
|
|
onClick={onNavigate}
|
2022-12-22 14:24:20 +00:00
|
|
|
end
|
2022-12-06 16:00:37 +00:00
|
|
|
/>
|
|
|
|
<AppNavLink
|
|
|
|
name={t('Portfolio')}
|
2022-12-22 14:24:20 +00:00
|
|
|
path={Links[Routes.PORTFOLIO]()}
|
2022-12-06 16:00:37 +00:00
|
|
|
navbarTheme={navbarTheme}
|
2023-01-17 09:59:12 +00:00
|
|
|
onClick={onNavigate}
|
2022-12-06 16:00:37 +00:00
|
|
|
/>
|
2022-12-08 08:46:44 +00:00
|
|
|
<a
|
2022-12-22 14:24:20 +00:00
|
|
|
href={tokenLink(TOKEN_GOVERNANCE)}
|
2022-12-08 08:46:44 +00:00
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
2023-01-17 09:59:12 +00:00
|
|
|
className={classNames(
|
|
|
|
'w-full md:w-auto',
|
|
|
|
getActiveNavLinkClassNames(false, navbarTheme)
|
|
|
|
)}
|
2022-12-08 08:46:44 +00:00
|
|
|
>
|
2023-01-17 09:59:12 +00:00
|
|
|
<span className="flex items-center justify-between w-full gap-2 pr-3 md:pr-0">
|
2022-12-06 16:00:37 +00:00
|
|
|
{t('Governance')}
|
2022-12-08 08:46:44 +00:00
|
|
|
<NewTab />
|
|
|
|
</span>
|
|
|
|
</a>
|
2023-01-17 09:59:12 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const MobileMenuBar = ({ navbarTheme }: { navbarTheme: NavbarTheme }) => {
|
|
|
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
|
|
|
const [container, setContainer] = useState<HTMLElement | null>(null);
|
|
|
|
|
|
|
|
const menuButton = (
|
|
|
|
<button
|
|
|
|
className={classNames(
|
|
|
|
'flex flex-col justify-around gap-3 p-2 relative z-30 h-[34px]',
|
|
|
|
{
|
|
|
|
'z-50': drawerOpen,
|
|
|
|
}
|
|
|
|
)}
|
|
|
|
onClick={() => setDrawerOpen(!drawerOpen)}
|
|
|
|
data-testid="button-menu-drawer"
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={classNames('w-[26px] h-[2px] transition-all', {
|
|
|
|
'translate-y-0 rotate-0 bg-white': !drawerOpen,
|
|
|
|
'bg-black': !drawerOpen && navbarTheme === 'yellow',
|
|
|
|
'translate-y-[7.5px] rotate-45 bg-black dark:bg-white': drawerOpen,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
<div
|
|
|
|
className={classNames('w-[26px] h-[2px] transition-all', {
|
|
|
|
'translate-y-0 rotate-0 bg-white': !drawerOpen,
|
|
|
|
'bg-black': !drawerOpen && navbarTheme === 'yellow',
|
|
|
|
'-translate-y-[7.5px] -rotate-45 bg-black dark:bg-white': drawerOpen,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="flex overflow-hidden md:hidden" ref={setContainer}>
|
|
|
|
<Drawer
|
|
|
|
dataTestId="menu-drawer"
|
|
|
|
open={drawerOpen}
|
|
|
|
onChange={setDrawerOpen}
|
|
|
|
container={container}
|
|
|
|
trigger={menuButton}
|
|
|
|
>
|
|
|
|
<div className="border-l border-default px-4 py-2 gap-4 flex flex-col w-full h-full bg-white dark:bg-black dark:text-white justify-start">
|
|
|
|
<div className="w-full h-1"></div>
|
|
|
|
<div className="px-2 pt-10 w-full flex flex-col items-stretch">
|
|
|
|
<NetworkSwitcher />
|
|
|
|
<div className="w-full pt-8 h-1 border-b border-default"></div>
|
|
|
|
</div>
|
|
|
|
<LinkList
|
|
|
|
className="flex flex-col"
|
|
|
|
navbarTheme={navbarTheme}
|
|
|
|
dataTestId="mobile-navbar-links"
|
|
|
|
onNavigate={() => setDrawerOpen(false)}
|
|
|
|
/>
|
|
|
|
<div className="flex flex-col px-2 justify-between">
|
|
|
|
<div className="w-full h-1 border-t border-default py-5"></div>
|
|
|
|
<ThemeSwitcher withMobile />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Drawer>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Navbar = ({ navbarTheme = 'inherit' }: NavbarProps) => {
|
|
|
|
const titleContent = (
|
|
|
|
<div className="hidden md:block">
|
|
|
|
<NetworkSwitcher />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
return (
|
|
|
|
<Nav
|
|
|
|
navbarTheme={navbarTheme}
|
|
|
|
title={t('Console')}
|
|
|
|
titleContent={titleContent}
|
|
|
|
icon={
|
|
|
|
<Link to="/">
|
|
|
|
<Vega className="w-13" />
|
|
|
|
</Link>
|
|
|
|
}
|
|
|
|
>
|
2023-02-06 11:18:14 +00:00
|
|
|
<LinkList className="hidden md:flex md:px-2" navbarTheme={navbarTheme} />
|
2023-01-17 09:59:12 +00:00
|
|
|
<div className="flex items-center gap-2 ml-auto overflow-hidden">
|
2022-12-06 16:00:37 +00:00
|
|
|
<VegaWalletConnectButton />
|
2023-01-17 09:59:12 +00:00
|
|
|
<ThemeSwitcher className="hidden md:block" />
|
|
|
|
<MobileMenuBar navbarTheme={navbarTheme} />
|
2022-08-31 04:35:46 +00:00
|
|
|
</div>
|
2022-12-06 16:00:37 +00:00
|
|
|
</Nav>
|
2022-03-14 13:18:11 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-11-08 07:23:38 +00:00
|
|
|
interface AppNavLinkProps {
|
2022-03-14 13:18:11 +00:00
|
|
|
name: string;
|
|
|
|
path: string;
|
2022-10-28 15:13:14 +00:00
|
|
|
navbarTheme: NavbarTheme;
|
2022-06-06 16:19:56 +00:00
|
|
|
testId?: string;
|
2022-10-26 16:11:04 +00:00
|
|
|
target?: HTMLAttributeAnchorTarget;
|
2022-12-15 07:45:03 +00:00
|
|
|
end?: boolean;
|
2023-01-17 09:59:12 +00:00
|
|
|
onClick?: () => void;
|
2022-03-14 13:18:11 +00:00
|
|
|
}
|
|
|
|
|
2022-11-08 07:23:38 +00:00
|
|
|
const AppNavLink = ({
|
2022-10-26 16:11:04 +00:00
|
|
|
name,
|
|
|
|
path,
|
2022-10-28 15:13:14 +00:00
|
|
|
navbarTheme,
|
2022-10-26 16:11:04 +00:00
|
|
|
target,
|
|
|
|
testId = name,
|
2022-12-15 07:45:03 +00:00
|
|
|
end,
|
2023-01-17 09:59:12 +00:00
|
|
|
onClick,
|
2022-11-08 07:23:38 +00:00
|
|
|
}: AppNavLinkProps) => {
|
2023-01-17 09:59:12 +00:00
|
|
|
const borderClasses = classNames(
|
|
|
|
'absolute h-[2px] md:h-1 w-full bottom-[-1px] left-0',
|
|
|
|
{
|
|
|
|
'bg-black dark:bg-vega-yellow': navbarTheme !== 'yellow',
|
|
|
|
'bg-black dark:bg-vega-yellow md:dark:bg-black': navbarTheme === 'yellow',
|
|
|
|
}
|
|
|
|
);
|
2022-03-14 13:18:11 +00:00
|
|
|
return (
|
2022-11-08 07:23:38 +00:00
|
|
|
<NavLink
|
|
|
|
data-testid={testId}
|
2022-11-29 00:02:24 +00:00
|
|
|
to={{ pathname: path }}
|
2022-12-08 08:46:44 +00:00
|
|
|
className={getNavLinkClassNames(navbarTheme)}
|
2023-01-17 09:59:12 +00:00
|
|
|
onClick={onClick}
|
2022-11-08 07:23:38 +00:00
|
|
|
target={target}
|
2022-12-15 07:45:03 +00:00
|
|
|
end={end}
|
2022-11-08 07:23:38 +00:00
|
|
|
>
|
|
|
|
{({ isActive }) => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{name}
|
|
|
|
{isActive && <span className={borderClasses} />}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</NavLink>
|
2022-03-14 13:18:11 +00:00
|
|
|
);
|
|
|
|
};
|