import Link from 'next/link' import { EllipsisHorizontalIcon, BuildingLibraryIcon, ArrowTopRightOnSquareIcon, ChevronDownIcon, CurrencyDollarIcon, ChartBarIcon, Cog8ToothIcon, ArrowsRightLeftIcon, ArrowTrendingUpIcon, MagnifyingGlassIcon, BanknotesIcon, NewspaperIcon, PlusCircleIcon, ArchiveBoxArrowDownIcon, ExclamationTriangleIcon, DocumentTextIcon, // ClipboardDocumentIcon, } from '@heroicons/react/20/solid' import { useRouter } from 'next/router' import { useTranslation } from 'next-i18next' import { Fragment, ReactNode, useEffect, useMemo } from 'react' import { Disclosure, Popover, Transition } from '@headlessui/react' import MangoAccountSummary from './account/MangoAccountSummary' import Tooltip from './shared/Tooltip' import { HealthType } from '@blockworks-foundation/mango-v4' import { useWallet } from '@solana/wallet-adapter-react' import mangoStore from '@store/mangoStore' import HealthHeart from './account/HealthHeart' import useMangoAccount from 'hooks/useMangoAccount' import { useTheme } from 'next-themes' import LeaderboardIcon from './icons/LeaderboardIcon' import { sideBarAnimationDuration } from './Layout' import { CUSTOM_SKINS, breakpoints } from 'utils/theme' import { NFT } from 'types' import { useViewport } from 'hooks/useViewport' import useLocalStorageState from 'hooks/useLocalStorageState' import { SIDEBAR_COLLAPSE_KEY } from 'utils/constants' const SideNav = ({ collapsed }: { collapsed: boolean }) => { const { t } = useTranslation(['common', 'search']) const { connected, publicKey } = useWallet() const { theme } = useTheme() const group = mangoStore.getState().group const themeData = mangoStore((s) => s.themeData) const nfts = mangoStore((s) => s.wallet.nfts.data) const { mangoAccount } = useMangoAccount() const router = useRouter() const { pathname } = router const { width } = useViewport() const [, setIsCollapsed] = useLocalStorageState(SIDEBAR_COLLAPSE_KEY, false) useEffect(() => { if (width !== 0 && width < breakpoints['2xl']) { setIsCollapsed(true) } }, [width, setIsCollapsed]) const playAnimation = () => { const set = mangoStore.getState().set set((s) => { s.successAnimation.theme = true }) } // fetch nfts when pk changes useEffect(() => { if (publicKey) { const actions = mangoStore.getState().actions const connection = mangoStore.getState().connection actions.fetchNfts(connection, publicKey) } }, [publicKey]) // find all mango skin nfts const mangoNfts = useMemo(() => { if (!nfts.length) return [] const mangoNfts: NFT[] = [] for (const nft of nfts) { const collectionAddress = nft?.collectionAddress for (const themeKey in CUSTOM_SKINS) { if (CUSTOM_SKINS[themeKey] === collectionAddress) { mangoNfts.push(nft) } } } return mangoNfts }, [nfts]) // find sidebar image url from skin nft for theme const sidebarImageUrl = useMemo(() => { if (!theme) return themeData.sideImagePath const collectionAddress = CUSTOM_SKINS[theme.toLowerCase()] if (collectionAddress && mangoNfts.length) { const sidebarImageUrl = mangoNfts.find((nft) => nft.collectionAddress === collectionAddress) ?.image || themeData.sideImagePath return sidebarImageUrl } return themeData.sideImagePath }, [mangoNfts, theme, themeData]) return (
{sidebarImageUrl && !collapsed ? ( playAnimation()} src={sidebarImageUrl} alt="next" /> ) : null}
logo {themeData.platformName}
} title={t('account')} pagePath="/" /> } title={t('swap')} pagePath="/swap" /> } title={t('trade')} pagePath="/trade" /> } title={t('borrow')} pagePath="/borrow" /> } title={t('stats')} pagePath="/stats" /> } title={t('leaderboard')} pagePath="/leaderboard" /> } title={t('settings')} pagePath="/settings" /> } title={t('more')} > } title={t('search:search-accounts')} pagePath="/search" hideIconBg showTooltip={false} /> } title={t('common:list-market-token')} pagePath="/governance/list" hideIconBg showTooltip={false} /> } title={t('common:vote')} pagePath="/governance/vote" hideIconBg showTooltip={false} /> } title={t('documentation')} pagePath="https://docs.mango.markets" hideIconBg isExternal showTooltip={false} /> } title={t('governance')} pagePath="https://dao.mango.markets" hideIconBg isExternal showTooltip={false} /> {/* } title={t('feedback-survey')} pagePath="https://forms.gle/JgV4w7SJ2kPH89mq7" hideIconBg isExternal showTooltip={false} /> */} } title={t('terms-of-use')} pagePath="https://docs.mango.markets/legal" hideIconBg isExternal showTooltip={false} /> } title={t('risks')} pagePath="https://docs.mango.markets/mango-markets/risks" hideIconBg isExternal showTooltip={false} />
} panelTitle={mangoAccount?.name ? mangoAccount.name : t('account')} title={

{t('account')}

{mangoAccount ? mangoAccount.name : connected ? 'No Account' : 'Connect'}

} alignBottom hideIconBg >
) } export default SideNav const MenuItem = ({ active, collapsed, icon, title, pagePath, hideIconBg, isExternal, showTooltip = true, }: { active?: boolean collapsed: boolean icon?: ReactNode title: string pagePath: string hideIconBg?: boolean isExternal?: boolean showTooltip?: boolean }) => { const { theme } = useTheme() return (
{icon ? (
{icon}
) : null} {title}
{isExternal ? ( ) : null}
) } export const ExpandableMenuItem = ({ alignBottom, children, collapsed, hideIconBg, icon, panelTitle, title, }: { alignBottom?: boolean children: ReactNode collapsed: boolean hideIconBg?: boolean icon: ReactNode panelTitle?: string title: string | ReactNode }) => { const { theme } = useTheme() const themeData = mangoStore((s) => s.themeData) return collapsed ? (
{icon}
{panelTitle ? (

{panelTitle}

) : null}
{children}
) : ( {({ open }) => ( <>
{icon}
{title}
{children}
)}
) }