diff --git a/components/TreasuryAccount/AccountItem.tsx b/components/TreasuryAccount/AccountItem.tsx index 4fdd1e30c1..643db0b188 100644 --- a/components/TreasuryAccount/AccountItem.tsx +++ b/components/TreasuryAccount/AccountItem.tsx @@ -3,6 +3,8 @@ import { getTreasuryAccountItemInfoV2 } from '@utils/treasuryTools' import { AssetAccount } from '@utils/uiTypes/assets' import TokenIcon from '@components/treasuryV2/icons/TokenIcon' import { useTokenMetadata } from '@hooks/queries/tokenMetadata' +import { useJupiterPriceByMintQuery } from '../../hooks/queries/jupiterPrice' +import BigNumber from 'bignumber.js' const AccountItem = ({ governedAccountTokenAccount, @@ -10,55 +12,84 @@ const AccountItem = ({ governedAccountTokenAccount: AssetAccount }) => { const { + decimalAdjustedAmount, amountFormatted, logo, name, symbol, - displayPrice, } = getTreasuryAccountItemInfoV2(governedAccountTokenAccount) + const { data: priceData } = useJupiterPriceByMintQuery( + governedAccountTokenAccount.extensions.mint?.publicKey + ) + const { data } = useTokenMetadata( governedAccountTokenAccount.extensions.mint?.publicKey, !logo ) const symbolFromMeta = useMemo(() => { - return data?.symbol - }, [data?.symbol]) + // data.symbol is kinda weird + //Handle null characters, whitespace, and ensure fallback to symbol + const cleanSymbol = data?.symbol + ?.replace(/\0/g, '') // Remove null characters + ?.replace(/\s+/g, ' ') // Normalize whitespace to single spaces + ?.trim() // Remove leading/trailing whitespace + + return cleanSymbol || symbol || '' + }, [data?.symbol, symbol]) + + const displayPrice = useMemo(() => { + if (!decimalAdjustedAmount || !priceData?.result?.price) return '' + + try { + const totalPrice = decimalAdjustedAmount * priceData.result.price + return new BigNumber(totalPrice).toFormat(0) + } catch (error) { + console.error('Error calculating display price:', error) + return '' + } + }, [priceData, decimalAdjustedAmount]) return (