adding prices of pools

This commit is contained in:
2025-11-11 17:45:00 -04:00
parent 732dfd7780
commit fea441b4e7
2 changed files with 47 additions and 6 deletions

View File

@@ -340,9 +340,14 @@ export function StakeForm({ defaultMode = 'stake' }: StakeFormProps) {
setSelectedToken(null); setSelectedToken(null);
}} }}
> >
<div className="flex flex-col"> <div className="flex justify-between items-center w-full">
<span className="font-medium">{pool.symbol}</span> <div className="flex flex-col">
<span className="text-xs text-muted-foreground">{pool.name}</span> <span className="font-medium">{pool.symbol}</span>
<span className="text-xs text-muted-foreground">{pool.name}</span>
</div>
{pool.price && (
<span className="text-sm font-medium text-muted-foreground">{pool.price}</span>
)}
</div> </div>
</button> </button>
)) ))
@@ -390,9 +395,14 @@ export function StakeForm({ defaultMode = 'stake' }: StakeFormProps) {
setSelectedToken(null); setSelectedToken(null);
}} }}
> >
<div className="flex flex-col"> <div className="flex justify-between items-center w-full">
<span className="font-medium">{pool.symbol}</span> <div className="flex flex-col">
<span className="text-xs text-muted-foreground">{pool.name}</span> <span className="font-medium">{pool.symbol}</span>
<span className="text-xs text-muted-foreground">{pool.name}</span>
</div>
{pool.price && (
<span className="text-sm font-medium text-muted-foreground">{pool.price}</span>
)}
</div> </div>
</button> </button>
)) ))

View File

@@ -333,6 +333,7 @@ export interface PoolDetails {
name: string; name: string;
symbol: string; symbol: string;
tokens: readonly `0x${string}`[]; tokens: readonly `0x${string}`[];
price?: string; // Formatted price string
} }
export function useGetAllPools(offset: number = 0, limit: number = 100) { export function useGetAllPools(offset: number = 0, limit: number = 100) {
@@ -413,11 +414,41 @@ export function useGetAllPools(offset: number = 0, limit: number = 100) {
// Only add pool if it's working // Only add pool if it's working
if (isWorking) { if (isWorking) {
// Fetch pool price (use first token as quote, index 0)
let priceStr: string | undefined;
try {
const priceRaw = await publicClient.readContract({
address: partyInfoAddress as `0x${string}`,
abi: IPartyInfoABI,
functionName: 'poolPrice',
args: [poolAddress, BigInt(0)],
});
const price = BigInt(priceRaw as bigint | number);
if (price === 0n) {
priceStr = undefined;
} else {
// Convert Q64 format to decimal (price = priceValue / 2^64)
const Q64 = 2n ** 64n;
const isNegative = price < 0n;
const absPrice = isNegative ? -price : price;
const priceFloat = Number(absPrice) / Number(Q64);
const finalPrice = isNegative ? -priceFloat : priceFloat;
priceStr = `$${finalPrice.toFixed(4)}`;
}
} catch (err) {
console.error(`Error fetching pool price for ${poolAddress}:`, err);
priceStr = undefined;
}
details.push({ details.push({
address: poolAddress, address: poolAddress,
name: name as string, name: name as string,
symbol: symbol as string, symbol: symbol as string,
tokens: tokens as readonly `0x${string}`[], tokens: tokens as readonly `0x${string}`[],
price: priceStr,
}); });
} }
} catch (err) { } catch (err) {