asi-calculator/hooks/use-prices.tsx

20 lines
475 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-30 20:50:51 +01:00
export function usePrices(): { [key: string]: number } {
2024-03-30 19:11:24 +01:00
const { data: dataPrices } = useSWR(
`/api/prices/?tokens=${tokens.toString()}`,
fetcher
)
const ocean = dataPrices?.[tokens[0]]?.usd || 0
const fet = dataPrices?.[tokens[1]]?.usd || 0
const agix = dataPrices?.[tokens[2]]?.usd || 0
const asi = fet
return { ocean, fet, agix, asi }
}