import type { ButtonHTMLAttributes, LiHTMLAttributes, ReactNode } from 'react'; import { useState } from 'react'; import { useEnvironment, DocsLinks, Networks, DApp, useLinks, FLAGS, } from '@vegaprotocol/environment'; import { t } from '@vegaprotocol/i18n'; import { useGlobalStore } from '../../stores'; import { VegaWalletConnectButton } from '../vega-wallet-connect-button'; import { VegaIconNames, VegaIcon, VLogo } from '@vegaprotocol/ui-toolkit'; import * as N from '@radix-ui/react-navigation-menu'; import * as D from '@radix-ui/react-dialog'; import { NavLink } from 'react-router-dom'; import { Links } from '../../lib/links'; import classNames from 'classnames'; import { VegaWalletMenu } from '../vega-wallet'; import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet'; import { WalletIcon } from '../icons/wallet'; import { ProtocolUpgradeCountdown } from '@vegaprotocol/proposals'; type MenuState = 'wallet' | 'nav' | null; type Theme = 'system' | 'yellow'; export const Navbar = ({ children, theme = 'system', }: { children?: ReactNode; theme?: Theme; }) => { // menu state for small screens const [menu, setMenu] = useState(null); const { pubKey } = useVegaWallet(); const openVegaWalletDialog = useVegaWalletDialogStore( (store) => store.openVegaWalletDialog ); const isConnected = pubKey !== null; const navTextClasses = 'text-vega-clight-200 dark:text-vega-cdark-200'; const rootClasses = classNames( navTextClasses, 'flex gap-3 h-10 pr-1', 'border-b border-default', 'bg-vega-clight-800 dark:bg-vega-cdark-800' ); return ( {/* Left section */}
{children}
{/* Used to show header in nav on mobile */}
setMenu(null)} />
{/* Right section */}
{ if (isConnected) { setMenu((x) => (x === 'wallet' ? null : 'wallet')); } else { openVegaWalletDialog(); } }} data-testid="navbar-mobile-wallet" > {t('Wallet')} { setMenu((x) => (x === 'nav' ? null : 'nav')); }} data-testid="navbar-mobile-burger" > {t('Menu')}
{menu !== null && ( setMenu((x) => (open ? x : null))} >
setMenu(null)}> {t('Close menu')}
{menu === 'nav' && setMenu(null)} />} {menu === 'wallet' && }
)}
); }; /** * List of links or dropdown triggers to show in the main section * of the navigation */ const NavbarMenu = ({ onClick }: { onClick: () => void }) => { const { VEGA_ENV, VEGA_NETWORKS, GITHUB_FEEDBACK_URL } = useEnvironment(); const marketId = useGlobalStore((store) => store.marketId); return (
{envNameMapping[VEGA_ENV]}
    {[Networks.MAINNET, Networks.TESTNET].map((n) => { const url = VEGA_NETWORKS[n]; if (!url) return; return ( {envNameMapping[n]} ); })}
{t('Markets')} {t('Trading')} {t('Portfolio')} {FLAGS.REFERRALS && ( {t('Referrals')} )} {t('Governance')} {t('Resources')}
    {DocsLinks?.NEW_TO_VEGA && ( {t('Docs')} )} {GITHUB_FEEDBACK_URL && ( {t('Give Feedback')} )} {t('Disclaimer')}
); }; /** * Wrapper for radix-ux Trigger for consistent styles */ const NavbarTrigger = ({ children, ...props }: N.NavigationMenuTriggerProps) => { return ( {children} ); }; /** * Wrapper for react-router-dom NavLink for consistent styles */ const NavbarLink = ({ children, to, onClick, }: { children: ReactNode; to: string; onClick?: () => void; }) => { return ( {({ isActive }) => { const borderClasses = { 'border-b-2': true, 'border-transparent': !isActive, 'border-vega-yellow lg:group-[.navbar-content]:border-transparent': isActive, }; return ( <> {children} ); }} ); }; const NavbarItem = (props: N.NavigationMenuItemProps) => { return ; }; const NavbarSubItem = (props: LiHTMLAttributes) => { return
  • ; }; const NavbarList = (props: N.NavigationMenuListProps) => { return ; }; /** * Content that gets rendered when a sub section of the navbar is shown */ const NavbarContent = (props: N.NavigationMenuContentProps) => { return ( ); }; /** * NavbarLink with OPEN_EXTERNAL icon */ const NavbarLinkExternal = ({ children, to, onClick, }: { children: ReactNode; to: string; onClick?: () => void; }) => { return ( {children} ); }; const BurgerIcon = () => ( ); const NavbarListDivider = () => { return (
    ); }; /** * Button component to avoid repeating styles for buttons shown on small screens */ const NavbarMobileButton = (props: ButtonHTMLAttributes) => { return (