import React, { useCallback, useMemo, useEffect } from 'react' import { useWallet, Wallet } from '@solana/wallet-adapter-react' import { WalletReadyState } from '@solana/wallet-adapter-base' import { useTranslation } from 'next-i18next' // import AccountsModal from './AccountsModal' import uniqBy from 'lodash/uniqBy' import { notify } from '../../utils/notifications' import WalletSelect from './WalletSelect' export const handleWalletConnect = (wallet: Wallet) => { if (!wallet) { return } wallet?.adapter?.connect().catch((e) => { if (e.name.includes('WalletLoadError')) { notify({ title: `${wallet.adapter.name} Error`, type: 'error', description: `Please install ${wallet.adapter.name} and then reload this page.`, }) } }) } export const ConnectWalletButton: React.FC = () => { const { wallet, wallets, select } = useWallet() const { t } = useTranslation('common') // const [showAccountsModal, setShowAccountsModal] = useState(false) const installedWallets = useMemo(() => { const installed: Wallet[] = [] for (const wallet of wallets) { if (wallet.readyState === WalletReadyState.Installed) { installed.push(wallet) } } return installed?.length ? installed : wallets }, [wallets]) const displayedWallets = useMemo(() => { return uniqBy([...installedWallets, ...wallets], (w) => { return w.adapter.name }) }, [wallets, installedWallets]) const handleConnect = useCallback(() => { if (wallet) { handleWalletConnect(wallet) } }, [wallet]) // const handleCloseAccounts = useCallback(() => { // setShowAccountsModal(false) // }, []) useEffect(() => { if (!wallet && displayedWallets?.length) { select(displayedWallets[0].adapter.name) } }, [wallet, displayedWallets, select]) return (
// {showAccountsModal && ( // // )} ) }