diff --git a/src/utils/markets.tsx b/src/utils/markets.tsx index 11b56ed7f..f9e5cc06a 100644 --- a/src/utils/markets.tsx +++ b/src/utils/markets.tsx @@ -8,7 +8,7 @@ import {useWallet} from './wallet'; import tuple from 'immutable-tuple'; import {notify} from './notifications'; import BN from 'bn.js'; -import {getTokenAccountInfo, parseTokenAccountData, useMintInfos,} from './tokens'; +import { getMultipleTokenAccountInfo, parseTokenAccountData, useMintInfos } from './tokens'; import { Balances, CustomMarketInfo, @@ -440,7 +440,7 @@ export function useTokenAccounts(): [ if (!connected || !wallet) { return null; } - return await getTokenAccountInfo(connection, wallet.publicKey); + return await getMultipleTokenAccountInfo(connection, wallet.publicKey); } return useAsyncData( getTokenAccounts, diff --git a/src/utils/tokens.tsx b/src/utils/tokens.tsx index 2c0ecc7c6..d3cdff624 100644 --- a/src/utils/tokens.tsx +++ b/src/utils/tokens.tsx @@ -121,6 +121,33 @@ export async function getOwnedTokenAccounts( }); } +export async function getMultipleTokenAccountInfo( + connection: Connection, + ownerAddress: PublicKey, +) { + let [splAccounts, account] = await Promise.all([ + getOwnedTokenAccounts(connection, ownerAddress), + connection.getAccountInfo(ownerAddress), + ]); + let accounts = splAccounts.map(value => { + return value.publicKey; + }); + let response = await getMultipleSolanaAccounts(connection, accounts); + const parsedAccounts: TokenAccount[] = Object.entries(response.value).map(([pubKey, accountInfo]) => { + return { + pubkey: new PublicKey(pubKey), + account: accountInfo, + effectiveMint: parseTokenAccountData(accountInfo!.data).mint, + }; + } + ); + return parsedAccounts.concat({ + pubkey: ownerAddress, + account, + effectiveMint: WRAPPED_SOL_MINT, + }); +} + export async function getTokenAccountInfo( connection: Connection, ownerAddress: PublicKey,