import { Fragment, useState } from 'react' import { CheckCircleIcon, ChevronDownIcon, PlusCircleIcon, } from '@heroicons/react/solid' import { Popover, Transition } from '@headlessui/react' import { MangoAccount } from '@blockworks-foundation/mango-v4' import mangoStore from '../store/mangoStore' import { LinkButton } from './shared/Button' import CreateAccountModal from './modals/CreateAccountModal' import { useLocalStorageStringState } from '../hooks/useLocalStorageState' import { LAST_ACCOUNT_KEY } from '../utils/constants' import { useTranslation } from 'next-i18next' const MangoAccountsList = ({ mangoAccount, }: { mangoAccount: MangoAccount }) => { const { t } = useTranslation('common') const mangoAccounts = mangoStore((s) => s.mangoAccounts.accounts) const [showNewAccountModal, setShowNewAccountModal] = useState(false) const [, setLastAccountViewed] = useLocalStorageStringState(LAST_ACCOUNT_KEY) const handleSelectMangoAccount = async (acc: MangoAccount) => { const set = mangoStore.getState().set const client = mangoStore.getState().client const group = mangoStore.getState().group if (!group) return await acc.reloadAccountData(client, group) set((s) => { s.mangoAccount.current = acc }) setLastAccountViewed(acc.publicKey.toString()) } return ( <> {({ open }) => ( <>

{t('accounts')}

{mangoAccount.name}

{mangoAccounts.length ? ( mangoAccounts.map((acc) => (
)) ) : (

Loading...

)}
setShowNewAccountModal(true)} > New Account
)}
{showNewAccountModal ? ( setShowNewAccountModal(false)} /> ) : null} ) } export default MangoAccountsList