asi-calculator/hooks/use-prices.tsx

23 lines
555 B
TypeScript
Raw Normal View History

2024-03-30 19:11:24 +01:00
'use client'
import { tokens } from '@/constants'
import { fetcher } from '@/utils'
import useSWR from 'swr'
2024-03-31 05:32:11 +02:00
export function usePrices(): {
prices: { ocean: number; fet: number; agix: number; asi: number }
isValidating: boolean
} {
const { data, isValidating } = useSWR(
2024-03-30 19:11:24 +01:00
`/api/prices/?tokens=${tokens.toString()}`,
fetcher
)
2024-03-31 05:32:11 +02:00
const ocean = data?.[tokens[0]]?.usd || 0
const fet = data?.[tokens[1]]?.usd || 0
const agix = data?.[tokens[2]]?.usd || 0
2024-03-30 19:11:24 +01:00
const asi = fet
2024-03-31 05:32:11 +02:00
return { prices: { ocean, fet, agix, asi }, isValidating }
2024-03-30 19:11:24 +01:00
}