import React, { Fragment, useMemo } from 'react' import { useWallet } from '@solana/wallet-adapter-react' import { useTranslation } from 'next-i18next' import WalletIcon from '@components/icons/WalletIcon' import useLocalStorageState from 'hooks/useLocalStorageState' import { IS_ONBOARDED_KEY } from 'utils/constants' import { ChevronDownIcon } from '@heroicons/react/20/solid' import { Popover, Transition } from '@headlessui/react' // import Loading from '@components/shared/Loading' import mangoStore from '@store/mangoStore' import { WalletName, WalletReadyState } from '@solana/wallet-adapter-base' export default function ConnectWalletButton({ handleShowSetup, }: { handleShowSetup: () => void }) { const { t } = useTranslation('common') const { wallet, wallets, select, connected, connect } = useWallet() const [isOnboarded] = useLocalStorageState(IS_ONBOARDED_KEY) const mangoAccountLoading = mangoStore((s) => s.mangoAccount.initialLoad) const [lastWalletName] = useLocalStorageState( 'lastWalletName', '', ) 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, lastWalletName]) return ( <> {isOnboarded && walletIcon ? (
{({ open }) => ( <> {detectedWallets.map((wallet, index) => ( ))} )}
) : ( )} ) }