import SideNav from './SideNav' import { breakpoints } from '../components/TradePageGrid' import { useViewport } from 'hooks/useViewport' import BottomBar from './mobile/BottomBar' import { ConnectWalletButton } from './ConnectWalletButton' import GlobalNotification from './GlobalNotification' import { abbreviateAddress } from 'utils' import { useCallback, useEffect, useState } from 'react' import AccountsModal from './AccountsModal' import { useRouter } from 'next/router' import FavoritesShortcutBar from './FavoritesShortcutBar' import { ArrowRightIcon, ChevronRightIcon, CogIcon, ExclamationCircleIcon, UsersIcon, } from '@heroicons/react/solid' import Button, { IconButton } from './Button' import SettingsModal from './SettingsModal' import { useTranslation } from 'next-i18next' import { useWallet } from '@solana/wallet-adapter-react' import DepositModal from './DepositModal' import WithdrawModal from './WithdrawModal' import Tooltip from './Tooltip' import useMangoStore from 'stores/useMangoStore' const Layout = ({ children }) => { const [isCollapsed, setIsCollapsed] = useState(false) const { width } = useViewport() const isMobile = width ? width < breakpoints.sm : false const router = useRouter() const { pathname } = router useEffect(() => { const collapsed = width ? width <= breakpoints.xl : false setIsCollapsed(collapsed) }, []) const handleToggleSidebar = () => { setIsCollapsed(!isCollapsed) setTimeout(() => { window.dispatchEvent(new Event('resize')) }, 100) } return (
{isMobile ? (
) : (
)}
{pathname === '/' ? : null}
{children}
) } const TopBar = () => { const { t } = useTranslation(['common', 'delegate']) const { connected, publicKey } = useWallet() const mangoAccount = useMangoStore((s) => s.selectedMangoAccount.current) const initialLoad = useMangoStore((s) => s.selectedMangoAccount.initialLoad) const loading = useMangoStore((s) => s.selectedMangoAccount.loading) const router = useRouter() const [showAccountsModal, setShowAccountsModal] = useState(false) const [showSettingsModal, setShowSettingsModal] = useState(false) const [showDepositModal, setShowDepositModal] = useState(false) const [showWithdrawModal, setShowWithdrawModal] = useState(false) const { pubkey } = router.query const { width } = useViewport() const isMobile = width ? width < breakpoints.sm : false const handleCloseAccounts = useCallback(() => { setShowAccountsModal(false) }, []) const canWithdraw = mangoAccount?.owner && publicKey ? mangoAccount?.owner?.equals(publicKey) : false return ( <>
{mangoAccount && mangoAccount.beingLiquidated ? (
{t('being-liquidated')}
) : (
{pubkey ? '🔎' : connected ? initialLoad ? '' : mangoAccount ? '🟢' : '👋' : !isMobile ? '🔗' : ''} {connected || pubkey ? ( !initialLoad && !loading ? ( mangoAccount ? (
setShowAccountsModal(true)} > {`${ mangoAccount.name ? mangoAccount.name : abbreviateAddress(mangoAccount.publicKey) }`} {publicKey && !mangoAccount.owner.equals(publicKey) ? ( ) : ( '' )}
) : ( {t('create-account-helper')} ) ) : (
) ) : !isMobile ? ( {t('connect-helper')} ) : null}
)}
{!isMobile && connected && !initialLoad ? (
{mangoAccount ? ( ) : ( )} {canWithdraw ? ( ) : null}
) : null} setShowSettingsModal(true)} >
{showAccountsModal ? ( ) : null} {showSettingsModal ? ( setShowSettingsModal(false)} isOpen={showSettingsModal} /> ) : null} {showDepositModal ? ( setShowDepositModal(false)} /> ) : null} {showWithdrawModal ? ( setShowWithdrawModal(false)} /> ) : null} ) } export default Layout