2022-08-25 14:23:57 +00:00
|
|
|
import classNames from 'classnames';
|
2022-03-14 13:18:11 +00:00
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
import Link from 'next/link';
|
2022-10-26 16:11:04 +00:00
|
|
|
import { NetworkSwitcher, useEnvironment } from '@vegaprotocol/environment';
|
2022-06-08 08:47:31 +00:00
|
|
|
import { t } from '@vegaprotocol/react-helpers';
|
feat: market list mega dropdown (rich popover) (#889)
* feat: use MarketList query only
* fix: remove Market.ts from index
* feat: 30 refactor dialog, market list, change query
* feat: #30 add indicativeVolume, total fees, tooltip, large dialog, tooltip accepts html description
* fix: #30 total fees display in tooltip
* fix: #30 toggle title on dialog open
* fix: #30 fix order, price, high, low utils
* fix: #30 fix test for market utils
* feat: #30 add popover with markets to select
* feat: #30 storybook popover
* feat: #30 remove border on trigger and add some other classes
* fix: #30 fix format check with format:write
* feat: #30 add tooltip on taker fee
* feat: #30 add tooltip on taker fee
* fix: #30 format on select market list
* fix: #30 remove unknown cast in test mock data
* fix: #30 show markets where you have open positions
* fix: #30 double check if open positions
* fix: #30 dialog has only small/large sizes
* feat: #30 add border on trigger and change padding and no wrap
* fix: #30 if fees or factors are not found
* fix: #30 remove markets.cy tests as markets page is now gone
* fix #30 remove view full market list test
* fix: #30 add rotating arrow on market title
* fix: #30 add ease-in-out on popover
* fix: #30 add ease-in-out on popover
* fix: #30 align select a market table
* fix: #30 select a market title
* fix: #30 select a market title
* fix: #30 fix any validateDOMnesting issues
* fix: #30 show loading market data
* fix: #30 add list of header columns
* fix: #30 add list of header columns
* fix: #30 small refactoring after review
* fix: #30 update bold undreline class names
* fix: #30 add large-mobile size
* feat: #30 refactor select markets tables to render array of columns
* fix: #30 remove size from select market dialog
* fix: #30 add extra file for columns
* fix: #30 update formtting
* fix: #30 make sure popup closes on same market navigation
* fix: rename market-utils, add calcCandle methods, store market id on select
* fix: useMemo ondata and marketPositionData + orderbook stories fix
* feat: #30 add open volume positions
* fix: add market summary back
* fix: update formatting
* fix: use currentcolor on arrow
* fix: create all markets page
* fix: add overflow-y auto
* fix: enlarge select market to get started dialog
* fix: revert markets container
* fix: use query to fix flickering on position markets
* fix: edit unordered list in tooltips
* fix: fix tooltip table
* fix: fix home.cy.ts
* chore: skip /markets tests
2022-08-11 11:56:35 +00:00
|
|
|
import { useGlobalStore } from '../../stores/global';
|
2022-08-31 04:35:46 +00:00
|
|
|
import { VegaWalletConnectButton } from '../vega-wallet-connect-button';
|
2022-09-12 13:05:39 +00:00
|
|
|
import { ThemeSwitcher } from '@vegaprotocol/ui-toolkit';
|
|
|
|
import { Vega } from '../icons/vega';
|
2022-10-26 16:11:04 +00:00
|
|
|
import type { HTMLAttributeAnchorTarget } from 'react';
|
2022-10-03 08:29:07 +00:00
|
|
|
import { useEffect, useState } from 'react';
|
2022-10-28 15:13:14 +00:00
|
|
|
import testnetBg from '../../assets/green-cloud.png';
|
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 {
|
|
|
|
theme: 'light' | 'dark';
|
|
|
|
toggleTheme: () => void;
|
2022-10-28 15:13:14 +00:00
|
|
|
navbarTheme?: NavbarTheme;
|
2022-08-31 04:35:46 +00:00
|
|
|
}
|
|
|
|
|
2022-10-28 15:13:14 +00:00
|
|
|
export const Navbar = ({
|
|
|
|
theme,
|
|
|
|
toggleTheme,
|
|
|
|
navbarTheme = 'inherit',
|
|
|
|
}: NavbarProps) => {
|
2022-10-26 16:11:04 +00:00
|
|
|
const { VEGA_TOKEN_URL } = useEnvironment();
|
2022-10-14 15:42:53 +00:00
|
|
|
const { marketId } = useGlobalStore((store) => ({
|
2022-09-05 14:25:33 +00:00
|
|
|
marketId: store.marketId,
|
|
|
|
}));
|
2022-10-03 08:29:07 +00:00
|
|
|
const [tradingPath, setTradingPath] = useState('/markets');
|
2022-10-26 16:11:04 +00:00
|
|
|
|
2022-10-03 08:29:07 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (marketId) {
|
|
|
|
setTradingPath(`/markets/${marketId}`);
|
|
|
|
}
|
|
|
|
}, [marketId]);
|
2022-10-26 16:11:04 +00:00
|
|
|
|
2022-10-28 15:13:14 +00:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-03-14 13:18:11 +00:00
|
|
|
return (
|
2022-10-28 15:13:14 +00:00
|
|
|
<div className={themeWrapperClasses}>
|
|
|
|
<div
|
|
|
|
className={navbarClasses}
|
|
|
|
style={{
|
|
|
|
backgroundImage: isYellow ? `url("${testnetBg.src}")` : '',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div className="flex gap-4 items-center">
|
|
|
|
<Link href="/" passHref={true}>
|
|
|
|
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
|
|
|
|
<a>
|
|
|
|
<Vega className="w-13" />
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
<NetworkSwitcher />
|
|
|
|
</div>
|
|
|
|
<nav className="flex items-center flex-1 px-2">
|
|
|
|
<NavLink
|
|
|
|
name={t('Trading')}
|
|
|
|
path={tradingPath}
|
|
|
|
navbarTheme={navbarTheme}
|
|
|
|
/>
|
|
|
|
<NavLink
|
|
|
|
name={t('Portfolio')}
|
|
|
|
path="/portfolio"
|
|
|
|
navbarTheme={navbarTheme}
|
|
|
|
/>
|
|
|
|
<NavLink
|
|
|
|
name={t('Governance')}
|
|
|
|
path={`${VEGA_TOKEN_URL}/governance`}
|
|
|
|
alignRight={true}
|
|
|
|
target="_blank"
|
|
|
|
navbarTheme={navbarTheme}
|
|
|
|
/>
|
|
|
|
</nav>
|
|
|
|
<div className="flex items-center gap-2 ml-auto">
|
|
|
|
<VegaWalletConnectButton />
|
|
|
|
<ThemeSwitcher theme={theme} onToggle={toggleTheme} />
|
|
|
|
</div>
|
2022-08-31 04:35:46 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-03-14 13:18:11 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
interface NavLinkProps {
|
|
|
|
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
|
|
|
alignRight?: boolean;
|
|
|
|
target?: HTMLAttributeAnchorTarget;
|
2022-03-14 13:18:11 +00:00
|
|
|
}
|
|
|
|
|
2022-10-26 16:11:04 +00:00
|
|
|
const NavLink = ({
|
|
|
|
name,
|
|
|
|
path,
|
2022-10-28 15:13:14 +00:00
|
|
|
navbarTheme,
|
2022-10-26 16:11:04 +00:00
|
|
|
alignRight,
|
|
|
|
target,
|
|
|
|
testId = name,
|
|
|
|
}: NavLinkProps) => {
|
2022-03-14 13:18:11 +00:00
|
|
|
const router = useRouter();
|
2022-10-26 16:11:04 +00:00
|
|
|
const isActive = router.asPath?.includes(path);
|
|
|
|
const linkClasses = classNames('mx-2 py-3 self-end relative', {
|
2022-10-28 15:13:14 +00:00
|
|
|
'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',
|
2022-10-26 16:11:04 +00:00
|
|
|
'ml-auto': alignRight,
|
2022-10-28 15:13:14 +00:00
|
|
|
'text-black': isActive && navbarTheme === 'yellow',
|
|
|
|
'text-black/60 hover:text-black': !isActive && navbarTheme === 'yellow',
|
|
|
|
});
|
|
|
|
const borderClasses = classNames('absolute h-1 w-full bottom-[-1px] left-0', {
|
|
|
|
'bg-black dark:bg-vega-yellow': navbarTheme !== 'yellow',
|
|
|
|
'bg-black': navbarTheme === 'yellow',
|
2022-08-31 04:35:46 +00:00
|
|
|
});
|
2022-03-14 13:18:11 +00:00
|
|
|
return (
|
2022-06-24 03:16:01 +00:00
|
|
|
<Link data-testid={testId} href={path} passHref={true}>
|
2022-07-07 11:01:03 +00:00
|
|
|
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
|
2022-10-26 16:11:04 +00:00
|
|
|
<a className={linkClasses} target={target}>
|
|
|
|
{name}
|
2022-10-28 15:13:14 +00:00
|
|
|
{isActive && <span className={borderClasses} />}
|
2022-10-26 16:11:04 +00:00
|
|
|
</a>
|
2022-06-24 03:16:01 +00:00
|
|
|
</Link>
|
2022-03-14 13:18:11 +00:00
|
|
|
);
|
|
|
|
};
|