import { useCallback, useEffect, useState } from 'react' import { ArrowLeftIcon, ArrowRightIcon, CheckCircleIcon, 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 Button from './shared/Button' import ConnectedMenu from './wallet/ConnectedMenu' import ConnectWalletButton from './wallet/ConnectWalletButton' import CreateAccountModal from './modals/CreateAccountModal' import { useRouter } from 'next/router' // 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 { useViewport } from 'hooks/useViewport' 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' export const TOPBAR_ICON_BUTTON_CLASSES = 'relative flex h-16 w-16 items-center justify-center border-l border-r border-th-bkg-3 focus-visible:bg-th-bkg-3 md:border-r-0 md:hover:bg-th-bkg-2' const set = mangoStore.getState().set const TopBar = () => { const { t } = useTranslation('common') const { mangoAccount, mangoAccountAddress } = useMangoAccount() const { connected } = useWallet() 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] = useState(false) const isOnline = useOnlineStatus() const router = useRouter() const { query } = router const { isMobile } = useViewport() 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]) return (
{t('account')}
{t('wallet')}
> } > {mangoAccount.name ? mangoAccount.name : abbreviateAddress(mangoAccount.publicKey)}Your connection appears to be offline