import React, { Fragment, useMemo } from 'react' import { useWallet } from '@solana/wallet-adapter-react' import { useTranslation } from 'next-i18next' import useLocalStorageState from 'hooks/useLocalStorageState' import { LAST_WALLET_NAME } from 'utils/constants' import { ChevronDownIcon } from '@heroicons/react/20/solid' import { Popover, Transition } from '@headlessui/react' import mangoStore from '@store/mangoStore' import { WalletName, WalletReadyState } from '@solana/wallet-adapter-base' export default function ConnectWalletButton() { const { t } = useTranslation('common') const { wallet, wallets, select, connected, connect } = useWallet() const mangoAccountLoading = mangoStore((s) => s.mangoAccount.initialLoad) const [lastWalletName] = useLocalStorageState( LAST_WALLET_NAME, '', ) const detectedWallets = useMemo(() => { return wallets.filter( (w) => w.readyState === WalletReadyState.Installed || w.readyState === WalletReadyState.Loadable, ) }, [wallets]) const walletIcon = useMemo(() => { const wallet = wallets.find((w) => w.adapter.name === lastWalletName) return wallet?.adapter.icon || wallets[0]?.adapter.icon }, [wallets, lastWalletName]) return (
{({ open }) => ( <> {detectedWallets.map((wallet, index) => ( ))} )}
) }