import type { Coin } from '@cosmjs/proto-signing' import { Popover, Transition } from '@headlessui/react' import clsx from 'clsx' import { Fragment, useEffect, useState } from 'react' import { FaCopy, FaPowerOff, FaRedo } from 'react-icons/fa' import { copy } from 'utils/clipboard' import { convertDenomToReadable } from 'utils/convertDenomToReadable' import { getShortAddress } from 'utils/getShortAddress' import { useWallet } from 'utils/wallet' import { WalletButton } from './WalletButton' import { WalletPanelButton } from './WalletPanelButton' export const WalletLoader = () => { const { address = '', username, connect, disconnect, isWalletConnecting, isWalletConnected, getStargateClient, } = useWallet() // Once wallet connects, load balances. const [balances, setBalances] = useState() useEffect(() => { if (!isWalletConnected) { setBalances(undefined) return } const loadBalances = async () => { const client = await getStargateClient() setBalances(await client.getAllBalances(address)) } loadBalances().catch(console.error) }, [isWalletConnected, getStargateClient, address]) return ( {({ close }) => ( <>
{isWalletConnected ? ( {username || address} ) : ( void connect().catch(console.error)} > Connect Wallet )}
{getShortAddress(address)}
Your Balances
{balances?.map((val) => ( {convertDenomToReadable(val.amount)} {val.denom.slice(1, val.denom.length)} ))}
void copy(address)}> Copy wallet address void connect()}> Reconnect [disconnect(), close()]}> Disconnect
)}
) }