import { Popover, Transition } from '@headlessui/react' import { ArrowRightOnRectangleIcon, CurrencyDollarIcon, UserCircleIcon, } from '@heroicons/react/20/solid' import { useWallet } 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' import { TV_USER_ID_KEY } from 'utils/constants' import useLocalStorageState from 'hooks/useLocalStorageState' import Loading from '@components/shared/Loading' const set = mangoStore.getState().set const actions = mangoStore.getState().actions const ConnectedMenu = () => { const { t } = useTranslation('common') const { publicKey, disconnect, wallet } = useWallet() const { width } = useViewport() const [tvUserId, setTvUserId] = useLocalStorageState(TV_USER_ID_KEY, '') const [showEditProfileModal, setShowEditProfileModal] = useState(false) const [showMangoAccountsModal, setShowMangoAccountsModal] = useState(false) // const profileDetails = mangoStore((s) => s.profile.details) const loadProfileDetails = mangoStore((s) => s.profile.loadDetails) const groupLoaded = mangoStore((s) => s.groupLoaded) const mangoAccountLoading = mangoStore((s) => s.mangoAccount.initialLoad) const isMobile = width ? width < breakpoints.md : false const handleDisconnect = useCallback(() => { set((state) => { state.activityFeed.feed = [] state.mangoAccount.current = undefined state.mangoAccounts = [] state.mangoAccount.initialLoad = true state.mangoAccount.openOrders = {} state.mangoAccount.interestTotals = { data: [], loading: false } }) disconnect() notify({ type: 'info', title: t('wallet-disconnected'), }) }, [t, disconnect]) useEffect(() => { if (publicKey && wallet && groupLoaded) { actions.connectMangoClientWithWallet(wallet) actions.fetchMangoAccounts(publicKey) // actions.fetchTourSettings(publicKey?.toString() as string) actions.fetchProfileDetails(publicKey.toString()) actions.fetchWalletTokens(publicKey) if (!tvUserId) { setTvUserId(publicKey.toString()) } } }, [publicKey, wallet, groupLoaded, tvUserId, setTvUserId]) return ( <>
{!mangoAccountLoading ? ( ) : ( )} {!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