import { useCallback, useState } from 'react' import useMangoStore from '../stores/useMangoStore' import { Menu } from '@headlessui/react' import { CogIcon, CurrencyDollarIcon, DuplicateIcon, LogoutIcon, } from '@heroicons/react/outline' import { WALLET_PROVIDERS, DEFAULT_PROVIDER, PROVIDER_LOCAL_STORAGE_KEY, } from '../hooks/useWallet' import useLocalStorageState from '../hooks/useLocalStorageState' import { abbreviateAddress, copyToClipboard } from '../utils' import WalletSelect from './WalletSelect' import { WalletIcon, ProfileIcon } from './icons' import AccountsModal from './AccountsModal' import { useEffect } from 'react' import SettingsModal from './SettingsModal' import { useTranslation } from 'next-i18next' const ConnectWalletButton = () => { const { t } = useTranslation('common') const wallet = useMangoStore((s) => s.wallet.current) const connected = useMangoStore((s) => s.wallet.connected) const set = useMangoStore((s) => s.set) const [showAccountsModal, setShowAccountsModal] = useState(false) const [showSettingsModal, setShowSettingsModal] = useState(false) const [selectedWallet, setSelectedWallet] = useState(DEFAULT_PROVIDER.url) const [savedProviderUrl] = useLocalStorageState( PROVIDER_LOCAL_STORAGE_KEY, DEFAULT_PROVIDER.url ) // update in useEffect to prevent SRR error from next.js useEffect(() => { setSelectedWallet(savedProviderUrl) }, [savedProviderUrl]) const handleWalletConect = () => { wallet.connect() set((state) => { state.selectedMangoAccount.initialLoad = true }) } const handleCloseAccounts = useCallback(() => { setShowAccountsModal(false) }, []) return ( <> {connected && wallet?.publicKey ? (
) : (