c2d2985e92
* fix: orderbook decimal places issue (#2235) * fix: positions table fixes notional dp (#2144) * fix: update decimals on position notional size * fix: normalize values * fix: fix positions unit tests * fix: remove liquidation price * fix: positions linting issue * fix: remove liquidation price test * fix: remove total summary row * fix: remove comments * fix: cypress test to not show trailing 0s * fix: add back liq. price est as cell only * fix: remove not used params * chore: merge with release/testnet * fix: orderbook dp * Update libs/positions/src/lib/positions-table.spec.tsx * fix: governance navbar link (#2247) * fix: governance navbar link * fix(#2245): fix gov link a tag no navlink * fix(#2245): remove export getActiveNavLinkClassNames Co-authored-by: m.ray <16125548+MadalinaRaicu@users.noreply.github.com>
152 lines
4.2 KiB
TypeScript
152 lines
4.2 KiB
TypeScript
import classNames from 'classnames';
|
|
import { NavLink, Link } from 'react-router-dom';
|
|
import { NetworkSwitcher, useEnvironment } from '@vegaprotocol/environment';
|
|
import { t } from '@vegaprotocol/react-helpers';
|
|
import { useGlobalStore } from '../../stores/global';
|
|
import { VegaWalletConnectButton } from '../vega-wallet-connect-button';
|
|
import { ThemeSwitcher } from '@vegaprotocol/ui-toolkit';
|
|
import { Vega } from '../icons/vega';
|
|
import type { HTMLAttributeAnchorTarget } from 'react';
|
|
import testnetBg from '../../assets/green-cloud.png';
|
|
import { Routes } from '../../pages/client-router';
|
|
|
|
type NavbarTheme = 'inherit' | 'dark' | 'yellow';
|
|
interface NavbarProps {
|
|
theme: 'light' | 'dark';
|
|
toggleTheme: () => void;
|
|
navbarTheme?: NavbarTheme;
|
|
}
|
|
|
|
export const Navbar = ({
|
|
theme,
|
|
toggleTheme,
|
|
navbarTheme = 'inherit',
|
|
}: NavbarProps) => {
|
|
const { VEGA_TOKEN_URL } = useEnvironment();
|
|
const { marketId } = useGlobalStore((store) => ({
|
|
marketId: store.marketId,
|
|
}));
|
|
const tradingPath = marketId ? `/markets/${marketId}` : '/markets';
|
|
|
|
const themeWrapperClasses = classNames({
|
|
dark: navbarTheme === 'dark',
|
|
});
|
|
|
|
const isYellow = navbarTheme === 'yellow';
|
|
const navbarClasses = classNames(
|
|
'flex items-stretch border-b px-4 border-default',
|
|
{
|
|
'dark:bg-black dark:text-white': !isYellow,
|
|
'bg-vega-yellow text-black bg-right-top bg-no-repeat bg-contain':
|
|
isYellow,
|
|
}
|
|
);
|
|
|
|
return (
|
|
<div className={themeWrapperClasses}>
|
|
<div
|
|
className={navbarClasses}
|
|
style={{
|
|
backgroundImage: isYellow ? `url("${testnetBg.src}")` : '',
|
|
}}
|
|
>
|
|
<div className="flex gap-4 items-center">
|
|
<Link to="/">
|
|
<Vega className="w-13" />
|
|
</Link>
|
|
<NetworkSwitcher />
|
|
</div>
|
|
<nav className="flex items-center flex-1 px-2">
|
|
<AppNavLink
|
|
name={t('Trading')}
|
|
path={tradingPath}
|
|
navbarTheme={navbarTheme}
|
|
/>
|
|
<AppNavLink
|
|
name={t('Portfolio')}
|
|
path={Routes.PORTFOLIO}
|
|
navbarTheme={navbarTheme}
|
|
/>
|
|
<a
|
|
href={`${VEGA_TOKEN_URL}/governance`}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className={getActiveNavLinkClassNames(false, navbarTheme, true)}
|
|
>
|
|
{t('Governance')}
|
|
</a>
|
|
</nav>
|
|
<div className="flex items-center gap-2 ml-auto">
|
|
<VegaWalletConnectButton />
|
|
<ThemeSwitcher theme={theme} onToggle={toggleTheme} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
interface AppNavLinkProps {
|
|
name: string;
|
|
path: string;
|
|
navbarTheme: NavbarTheme;
|
|
testId?: string;
|
|
alignRight?: boolean;
|
|
target?: HTMLAttributeAnchorTarget;
|
|
}
|
|
|
|
const AppNavLink = ({
|
|
name,
|
|
path,
|
|
navbarTheme,
|
|
alignRight,
|
|
target,
|
|
testId = name,
|
|
}: AppNavLinkProps) => {
|
|
const borderClasses = classNames('absolute h-1 w-full bottom-[-1px] left-0', {
|
|
'bg-black dark:bg-vega-yellow': navbarTheme !== 'yellow',
|
|
'bg-black': navbarTheme === 'yellow',
|
|
});
|
|
return (
|
|
<NavLink
|
|
data-testid={testId}
|
|
to={{ pathname: path }}
|
|
className={getNavLinkClassNames(navbarTheme, alignRight)}
|
|
target={target}
|
|
>
|
|
{({ isActive }) => {
|
|
return (
|
|
<>
|
|
{name}
|
|
{isActive && <span className={borderClasses} />}
|
|
</>
|
|
);
|
|
}}
|
|
</NavLink>
|
|
);
|
|
};
|
|
|
|
function getNavLinkClassNames(
|
|
navbarTheme: string,
|
|
alignRight = false
|
|
): (props: { isActive?: boolean }) => string | undefined {
|
|
return ({ isActive = false }) => {
|
|
return getActiveNavLinkClassNames(isActive, navbarTheme, alignRight);
|
|
};
|
|
}
|
|
|
|
const getActiveNavLinkClassNames = (
|
|
isActive: boolean,
|
|
navbarTheme: string,
|
|
alignRight = false
|
|
): string | undefined => {
|
|
return classNames('mx-2 py-3 self-end relative', {
|
|
'cursor-default': isActive,
|
|
'text-black dark:text-white': isActive && navbarTheme !== 'yellow',
|
|
'text-neutral-500 dark:text-neutral-400 hover:text-black dark:hover:text-neutral-300':
|
|
!isActive && navbarTheme !== 'yellow',
|
|
'ml-auto': alignRight,
|
|
'text-black': isActive && navbarTheme === 'yellow',
|
|
'text-black/60 hover:text-black': !isActive && navbarTheme === 'yellow',
|
|
});
|
|
};
|