import { Menu, Transition } from '@headlessui/react' import { ArrowRightOnRectangleIcon, CurrencyDollarIcon, UserCircleIcon, } from '@heroicons/react/20/solid' import { useWallet, Wallet } from '@solana/wallet-adapter-react' import { useTranslation } from 'next-i18next' import { Fragment, useCallback, useEffect, useState } from 'react' import mangoStore from '@store/mangoStore' import { notify } from '../../utils/notifications' import ProfileImage from '../profile/ProfileImage' import { abbreviateAddress } from '../../utils/formatting' import { useViewport } from 'hooks/useViewport' import { breakpoints } from '../../utils/theme' import EditProfileModal from '@components/modals/EditProfileModal' import MangoAccountsListModal from '@components/modals/MangoAccountsListModal' const ConnectedMenu = () => { const { t } = useTranslation('common') const { publicKey, disconnect, wallet } = useWallet() const { width } = useViewport() const [showEditProfileModal, setShowEditProfileModal] = useState(false) const [showMangoAccountsModal, setShowMangoAccountsModal] = useState(false) const set = mangoStore((s) => s.set) const actions = mangoStore.getState().actions // const profileDetails = mangoStore((s) => s.profile.details) const loadProfileDetails = mangoStore((s) => s.profile.loadDetails) const isMobile = width ? width < breakpoints.md : false const onConnectFetchAccountData = async (wallet: Wallet) => { if (!wallet.adapter.publicKey) return await actions.fetchMangoAccounts(wallet.adapter.publicKey) actions.fetchTourSettings(wallet.adapter.publicKey?.toString() as string) actions.fetchWalletTokens(wallet.adapter.publicKey) actions.fetchTradeHistory() } const handleDisconnect = useCallback(() => { set((state) => { state.activityFeed.feed = [] state.mangoAccount.current = undefined state.mangoAccounts = [] state.mangoAccount.openOrders = {} state.mangoAccount.interestTotals = { data: [], loading: false } state.mangoAccount.performance = { data: [], loading: false, initialLoad: false, } }) disconnect() wallet?.adapter.disconnect() notify({ type: 'info', title: t('wallet-disconnected'), }) }, [set, t, disconnect]) useEffect(() => { const handleGetWalletMangoData = async (wallet: Wallet) => { const actions = mangoStore.getState().actions await actions.connectMangoClientWithWallet(wallet) await onConnectFetchAccountData(wallet) } if (publicKey && wallet) { actions.fetchProfileDetails(publicKey.toString()) handleGetWalletMangoData(wallet) } }, [publicKey, actions, wallet]) return ( <> {({ open }) => (
{!loadProfileDetails && !isMobile ? (

{wallet?.adapter.name}

{publicKey ? abbreviateAddress(publicKey) : ''}

{/*

{profileDetails?.profile_name ? profileDetails.profile_name : 'Profile Unavailabe'}

*/}
) : null}
{isMobile ? ( ) : null} {/* */}
)}
{showEditProfileModal ? ( setShowEditProfileModal(false)} /> ) : null} {showMangoAccountsModal ? ( setShowMangoAccountsModal(false)} /> ) : null} ) } export default ConnectedMenu