import Link from 'next/link' import { EllipsisHorizontalIcon, BuildingLibraryIcon, ArrowTopRightOnSquareIcon, ChevronDownIcon, CurrencyDollarIcon, ChartBarIcon, ArrowsRightLeftIcon, ArrowTrendingUpIcon, MagnifyingGlassIcon, BanknotesIcon, NewspaperIcon, PlusCircleIcon, ArchiveBoxArrowDownIcon, ExclamationTriangleIcon, DocumentTextIcon, } from '@heroicons/react/20/solid' import { useRouter } from 'next/router' import { useTranslation } from 'next-i18next' import React, { Fragment, ReactNode, useEffect, useMemo, useState } 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' import { createTransferInstruction } from '@solana/spl-token' import { PublicKey, TransactionInstruction } from '@solana/web3.js' import CoinIcon from './icons/CoinIcon' import PerpIcon from './icons/PerpIcon' //import { useIsWhiteListed } from 'hooks/useIsWhiteListed' const set = mangoStore.getState().set 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 { data: isWhiteListed } = useIsWhiteListed() const setPrependedGlobalAdditionalInstructions = mangoStore( (s) => s.actions.setPrependedGlobalAdditionalInstructions, ) const router = useRouter() const { pathname, query } = router const { width } = useViewport() const [, setIsCollapsed] = useLocalStorageState(SIDEBAR_COLLAPSE_KEY, false) useEffect(() => { if (width !== 0 && width < breakpoints['xl']) { 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) { set((state) => { state.wallet.nfts.initialLoad = true }) 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]) //mark transactions with used nfts useEffect(() => { let newInstruction: TransactionInstruction[] = [] if (mangoNfts.length && theme) { const collectionAddress = CUSTOM_SKINS[theme.toLowerCase()] const usedNft = mangoNfts.find( (nft) => nft.collectionAddress === collectionAddress, ) if (usedNft && publicKey && collectionAddress) { newInstruction = [ createTransferInstruction( new PublicKey(usedNft.tokenAccount), new PublicKey(usedNft.tokenAccount), publicKey, 1, ), ] } } setPrependedGlobalAdditionalInstructions(newInstruction) }, [mangoNfts, theme, themeData]) // 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 attributes = mangoNfts.find( (nft) => nft.collectionAddress === collectionAddress, )?.json?.attributes const sidebarImageUrl = attributes ? attributes[0].value || 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')} > } title={t('perp')} pagePath="/trade?name=SOL-PERP" hideIconBg showTooltip={false} /> } title={t('spot')} pagePath="/trade?name=SOL/USDC" hideIconBg showTooltip={false} /> } title={t('borrow')} pagePath="/borrow" /> } title={t('stats')} pagePath="/stats" /> } title={t('leaderboard')} pagePath="/leaderboard" /> {/* {isWhiteListed ? ( } title={t('nft-market')} pagePath="/nft" /> ) : null} */} } 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')} showTooltip={false} title={

{t('account')}

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

} alignBottom hideIconBg >
) } export default SideNav const MenuItem = ({ active, collapsed, icon, onClick, title, pagePath, hideIconBg, isExternal, showTooltip = true, }: { active?: boolean collapsed: boolean icon?: ReactNode onClick?: () => void title: string pagePath: string hideIconBg?: boolean isExternal?: boolean showTooltip?: boolean }) => { const { theme } = useTheme() return (
{icon ? (
{icon}
) : null} {title}
{isExternal ? ( ) : null}
) } export const ExpandableMenuItem = ({ active, alignBottom, children, collapsed, hideIconBg, icon, panelTitle, showTooltip = true, title, }: { active?: boolean alignBottom?: boolean children: ReactNode collapsed: boolean hideIconBg?: boolean icon: ReactNode panelTitle?: string showTooltip?: boolean title: string | ReactNode }) => { const { theme } = useTheme() const themeData = mangoStore((s) => s.themeData) const [isOpen, setIsOpen] = useState(false) return collapsed ? ( {({ open, close }) => ( <> setIsOpen(!isOpen)} >
{icon}
{panelTitle ? (

{panelTitle}

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