import type { Coin } from '@cosmjs/proto-signing' import { Popover, Transition } from '@headlessui/react' import clsx from 'clsx' import { tokensList } from 'config/token' 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 { truncateMiddle } from 'utils/text' 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)}{' '} {tokensList.find((t) => t.denom === val.denom)?.displayName ? tokensList.find((t) => t.denom === val.denom)?.displayName : truncateMiddle(val.denom ? val.denom : '', 28)} ))}
void copy(address)}> Copy wallet address void connect()}> Reconnect [disconnect(), close()]}> Disconnect
)}
) }