Răsfoiți Sursa

feat(DataTable): use baseMint.price and add fee display

lushdog@outlook.com 1 lună în urmă
părinte
comite
a2ee0163b4
1 a modificat fișierele cu 26 adăugiri și 16 ștergeri
  1. 26 16
      src/app/components/DataTable.tsx

+ 26 - 16
src/app/components/DataTable.tsx

@@ -43,6 +43,16 @@ interface PoolOption {
 interface PoolInfo {
 interface PoolInfo {
 	poolAddress: string
 	poolAddress: string
 	displayReversed?: boolean
 	displayReversed?: boolean
+	feeUsd1d?: number
+	feeUsd1h?: number
+	baseMint?: {
+		price?: number
+		mintInfo: {
+			address?: string
+			symbol?: string
+			decimals?: number
+		}
+	}
 	mintA?: {
 	mintA?: {
 		address: string
 		address: string
 		symbol?: string
 		symbol?: string
@@ -120,6 +130,8 @@ function DataTableContent() {
 	// const [priceUpper, setPriceUpper] = useState<number>(0)
 	// const [priceUpper, setPriceUpper] = useState<number>(0)
 	const [balanceUsd, setBalanceUsd] = useState<number>(0)
 	const [balanceUsd, setBalanceUsd] = useState<number>(0)
 	const [currentPrice, setCurrentPrice] = useState<number>(0)
 	const [currentPrice, setCurrentPrice] = useState<number>(0)
+	const [feeUsd1d, setFeeUsd1d] = useState<number>(0)
+	const [feeUsd1h, setFeeUsd1h] = useState<number>(0)
 
 
 	const fetchBalance = async (
 	const fetchBalance = async (
 		tokenAddress: string,
 		tokenAddress: string,
@@ -159,22 +171,13 @@ function DataTableContent() {
 		const poolInfo = result?.result?.data?.records?.find(
 		const poolInfo = result?.result?.data?.records?.find(
 			(option) => option.poolAddress === selectedPoolAddress
 			(option) => option.poolAddress === selectedPoolAddress
 		)
 		)
-		const symbolA = poolInfo?.mintA?.mintInfo?.symbol || ''
-		const symbolB = poolInfo?.mintB?.mintInfo?.symbol || ''
-		let label = ''
-		let address = ''
-		let price = 0
-		if (symbolA === 'USDC' || symbolA === 'USDT' || symbolA === 'SOL') {
-			address = poolInfo?.mintB?.mintInfo?.address || ''
-			label = symbolB
-			price = poolInfo?.mintB?.price || 0
-		} else {
-			address = poolInfo?.mintA?.mintInfo?.address || ''
-			label = symbolA
-			price = poolInfo?.mintA?.price || 0
-		}
+		const price = poolInfo?.baseMint?.price || 0
+		const label = poolInfo?.baseMint?.mintInfo?.symbol || ''
+		const address = poolInfo?.baseMint?.mintInfo?.address || ''
 		setCurrentPrice(price)
 		setCurrentPrice(price)
-		setTokenName(label || '')
+		setTokenName(label)
+		setFeeUsd1d(poolInfo?.feeUsd1d || 0)
+		setFeeUsd1h(poolInfo?.feeUsd1h || 0)
 		return fetchBalance(address, userAddressRef.current, price)
 		return fetchBalance(address, userAddressRef.current, price)
 	}
 	}
 
 
@@ -894,7 +897,14 @@ function DataTableContent() {
 				/>
 				/>
 				<span className="ml-2 mr-2 text-lg font-bold text-green-500">
 				<span className="ml-2 mr-2 text-lg font-bold text-green-500">
 					余额:{balance} {tokenName} (${balanceUsd}) | 当前价格:$
 					余额:{balance} {tokenName} (${balanceUsd}) | 当前价格:$
-					{Number(currentPrice).toFixed(4)}
+					{Number(currentPrice).toFixed(4)} | 24h Fee:
+					<span className="text-orange-500 font-bold text-xl">
+						${Number(feeUsd1d).toFixed(2)}
+					</span>{' '}
+					| 1h Fee:
+					<span className="text-orange-500 font-bold text-xl">
+						${Number(feeUsd1h).toFixed(2)}
+					</span>
 				</span>
 				</span>
 				<Button type="primary" className="ml-2 mr-2" onClick={handleRefresh}>
 				<Button type="primary" className="ml-2 mr-2" onClick={handleRefresh}>
 					刷新
 					刷新