diff --git a/components/AccountSelect.tsx b/components/AccountSelect.tsx index 9ee09014..93289855 100644 --- a/components/AccountSelect.tsx +++ b/components/AccountSelect.tsx @@ -1,12 +1,12 @@ -import { useState } from 'react' +import { useMemo, useState } from 'react' import { Listbox } from '@headlessui/react' import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/solid' -import { abbreviateAddress, getSymbolForTokenMintAddress } from '../utils' -import useMarketList from '../hooks/useMarketList' -import { nativeToUi } from '@blockworks-foundation/mango-client/lib/utils' +import { abbreviateAddress } from '../utils' +import { nativeToUi } from '@blockworks-foundation/mango-client/lib/src/utils' +import { getTokenByMint } from '@blockworks-foundation/mango-client' import useMangoStore from '../stores/useMangoStore' -import { SRM_DECIMALS } from '@project-serum/serum/lib/token-instructions' import { RefreshClockwiseIcon } from './icons' +import useMangoGroupConfig from '../hooks/useMangoGroupConfig' type AccountSelectProps = { accounts: any[] @@ -23,10 +23,10 @@ const AccountSelect = ({ onSelectAccount, getBalance, hideAddress = false, - symbols, }: AccountSelectProps) => { - const { getTokenIndex } = useMarketList() - const mintDecimals = useMangoStore((s) => s.selectedMangoGroup.mintDecimals) + const groupConfig = useMangoGroupConfig(); + const tokenSymbols = useMemo(() => groupConfig.tokens.map(t => t.symbol), [groupConfig]); + const actions = useMangoStore((s) => s.actions) const [loading, setLoading] = useState(false) @@ -36,11 +36,9 @@ const AccountSelect = ({ } const getBalanceForAccount = (account) => { - const mintAddress = account?.account.mint.toString() - const symbol = getSymbolForTokenMintAddress(mintAddress) const balance = nativeToUi( account?.account?.amount, - symbol !== 'SRM' ? mintDecimals[getTokenIndex(mintAddress)] : SRM_DECIMALS + getTokenByMint(groupConfig, account?.account.mint).decimals ) return balance.toString() @@ -52,19 +50,15 @@ const AccountSelect = ({ setLoading(false) } - const symbolsForAccounts = accounts.map((a) => - getSymbolForTokenMintAddress(a.account.mint.toString()) - ) - - const missingTokens = symbols - ? Object.keys(symbols).filter((sym) => !symbolsForAccounts.includes(sym)) - : null + const getSymbolOfAccount = (a) => getTokenByMint(groupConfig, a.account.mint)?.symbol; + const symbolsForAccounts = accounts.map(getSymbolOfAccount) + const missingTokens = tokenSymbols.filter((sym) => !symbolsForAccounts.includes(sym)) return (
Asset
- {accounts.length < Object.keys(symbols).length ? ( + {missingTokens.length > 0 ? (