import { useCallback, useEffect, useState } from 'react' import { ArrowRightIcon, CheckCircleIcon, ChevronRightIcon, Cog8ToothIcon, DocumentDuplicateIcon, ExclamationTriangleIcon, EyeIcon, } from '@heroicons/react/20/solid' import { useWallet } from '@solana/wallet-adapter-react' import { useTranslation } from 'next-i18next' import WalletIcon from './icons/WalletIcon' import ConnectedMenu from './wallet/ConnectedMenu' import ConnectWalletButton from './wallet/ConnectWalletButton' import CreateAccountModal from './modals/CreateAccountModal' // import SolanaTps from './SolanaTps' import useMangoAccount from 'hooks/useMangoAccount' import useOnlineStatus from 'hooks/useOnlineStatus' import { abbreviateAddress } from 'utils/formatting' import DepositWithdrawModal from './modals/DepositWithdrawModal' import AccountsButton from './AccountsButton' import useUnownedAccount from 'hooks/useUnownedAccount' import NotificationsButton from './notifications/NotificationsButton' import Tooltip from './shared/Tooltip' import { copyToClipboard } from 'utils' import mangoStore from '@store/mangoStore' import UserSetupModal from './modals/UserSetupModal' import { IS_ONBOARDED_KEY } from 'utils/constants' import useLocalStorageState from 'hooks/useLocalStorageState' import SettingsModal from './modals/SettingsModal' import DepositWithdrawIcon from './icons/DepositWithdrawIcon' import { useCurrentSeason, useWalletPoints } from 'hooks/useRewards' import SheenLoader from './shared/SheenLoader' import Link from 'next/link' import { useIsWhiteListed } from 'hooks/useIsWhiteListed' import FormatNumericValue from './shared/FormatNumericValue' import { useRouter } from 'next/router' import TopBarStore from '@store/topBarStore' export const TOPBAR_ICON_BUTTON_CLASSES = 'relative flex h-16 w-10 sm:w-16 items-center justify-center sm:border-l sm:border-th-bkg-3 focus-visible:bg-th-bkg-3 md:hover:bg-th-bkg-2' const set = mangoStore.getState().set const TopBar = () => { const { t } = useTranslation('common') const { mangoAccount, mangoAccountAddress } = useMangoAccount() const { connected, wallet } = useWallet() const { data: seasonData } = useCurrentSeason() const { data: walletPoints, isLoading: loadingWalletRewardsData, refetch: refetchWalletPoints, } = useWalletPoints(mangoAccountAddress, seasonData?.season_id, wallet) const { data: isWhiteListed } = useIsWhiteListed() const router = useRouter() const themeData = mangoStore((s) => s.themeData) const [action, setAction] = useState<'deposit' | 'withdraw'>('deposit') const [copied, setCopied] = useState('') const [showDepositWithdrawModal, setShowDepositWithdrawModal] = useState(false) const [showCreateAccountModal, setShowCreateAccountModal] = useState(false) const { showSettingsModal, setShowSettingsModal } = TopBarStore() const isOnline = useOnlineStatus() const { isUnownedAccount } = useUnownedAccount() const showUserSetup = mangoStore((s) => s.showUserSetup) const [, setIsOnboarded] = useLocalStorageState(IS_ONBOARDED_KEY) const handleCloseSetup = useCallback(() => { set((s) => { s.showUserSetup = false }) setIsOnboarded(true) }, [setIsOnboarded]) const handleShowSetup = useCallback(() => { set((s) => { s.showUserSetup = true }) }, []) const handleDepositWithdrawModal = (action: 'deposit' | 'withdraw') => { if (!connected || mangoAccount) { setAction(action) setShowDepositWithdrawModal(true) } else { setShowCreateAccountModal(true) } } const handleCopy = (text: string) => { copyToClipboard(text) setCopied(text) } useEffect(() => { setTimeout(() => setCopied(''), 2000) }, [copied]) useEffect(() => { if (router.pathname === '/rewards') { refetchWalletPoints() } }, [router]) return (
logo
{!connected ? ( mangoAccount ? ( {t('unowned-helper', { accountPk: '', })} :

{t('account')}

{t('wallet')}

} > {mangoAccount.name ? mangoAccount.name : abbreviateAddress(mangoAccount.publicKey)}
) : ( {t('connect-helper')} ) ) : isWhiteListed ? (
Points {!loadingWalletRewardsData ? (

{walletPoints ? ( ) : wallet?.adapter.publicKey ? ( 0 ) : ( '–' )}

) : (
)}
) : null} {!isOnline ? (

Your connection appears to be offline

) : null}
{isUnownedAccount || !connected ? null : (
)}
{connected ? (
{mangoAccountAddress && }
) : (
)}
{showDepositWithdrawModal ? ( setShowDepositWithdrawModal(false)} /> ) : null} {showUserSetup ? ( ) : null} {showCreateAccountModal ? ( setShowCreateAccountModal(false)} /> ) : null} {showSettingsModal ? ( setShowSettingsModal(false)} /> ) : null}
) } export default TopBar