'use client' import useSWR from 'swr' import styles from './Prices.module.css' import { Result } from './Result' import { tokens, ratioOceanToAsi, ratioAgixToAsi, exampleBuyInUsd, ratioFetToAsi } from '@/constants' const fetcher = async (url: string) => { const res = await fetch(url) if (!res.ok) throw new Error('Failed to fetch') return await res.json() } export function Prices() { const { data: dataPrices } = useSWR( `https://web3.kremalicious.com/api/prices/?tokens=${tokens.toString()}`, fetcher ) const { data: dataSwapOceanToAgix } = useSWR( `/api/quote/?src=${tokens[0]}&dst=${tokens[2]}&amount=${ exampleBuyInUsd * 1e18 }`, fetcher ) const { data: dataSwapOceanToFet } = useSWR( `/api/quote/?src=${tokens[0]}&dst=${tokens[1]}&amount=${ exampleBuyInUsd * 1e18 }`, fetcher ) const priceOcean = dataPrices?.[tokens[0]]?.usd || 0 const priceFet = dataPrices?.[tokens[1]]?.usd || 0 const priceAgix = dataPrices?.[tokens[2]]?.usd || 0 const priceAsi = priceFet return ( <>
1 OCEAN = {ratioOceanToAsi} ASI (fixed) = ${priceOcean}
1 AGIX = {ratioAgixToAsi} ASI (fixed) = ${priceAgix}
1 Fet = 1 ASI (fixed) = ${priceAsi}