import { Listbox } from '@headlessui/react' import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/solid' import { abbreviateAddress } from '../utils' import { nativeToUi } from '@blockworks-foundation/mango-client/lib/utils' import { SRM_DECIMALS } from '@project-serum/serum/lib/token-instructions' const MangoSrmAccountSelector = ({ accounts, selectedAccount, onSelectAccount, }) => { const handleChange = (value) => { const newAccount = accounts.find((a) => a.publicKey.toString() === value) onSelectAccount(newAccount) } const getBalanceForAccount = (account) => { const balance = nativeToUi(account.amount, SRM_DECIMALS) return balance.toFixed(SRM_DECIMALS) } return (
{({ open }) => ( <>
{abbreviateAddress(selectedAccount?.publicKey)}
({getBalanceForAccount(selectedAccount)})
{open ? ( ) : ( )}
{open ? (
Your Mango SRM Accounts
{accounts.map((account) => { return ( {({ selected }) => (
{abbreviateAddress(account?.publicKey)}
{getBalanceForAccount(account)} (SRM)
)}
) })}
) : null} )}
) } export default MangoSrmAccountSelector