From 24458c8bed62c6cac46c4186e8b5ac6e74711131 Mon Sep 17 00:00:00 2001 From: ggnine-jito <122913584+ggnine-jito@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:09:03 -0800 Subject: [PATCH] update jup api url, update inline price showing for individual mint accounts so it now reliably works and presents a little beter styling-wise (#22) --- components/TreasuryAccount/AccountItem.tsx | 63 ++++++++++++++++------ hooks/queries/jupiterPrice.ts | 2 +- utils/treasuryTools.tsx | 2 + 3 files changed, 50 insertions(+), 17 deletions(-) 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 (