2024-03-29 19:54:14 +01:00
|
|
|
'use client'
|
|
|
|
|
|
|
|
import useSWR from 'swr'
|
2024-03-29 22:54:07 +01:00
|
|
|
import { useDebounce } from 'use-debounce'
|
2024-03-29 19:54:14 +01:00
|
|
|
import styles from './Prices.module.css'
|
|
|
|
import { Result } from './Result'
|
|
|
|
import {
|
|
|
|
tokens,
|
|
|
|
ratioOceanToAsi,
|
|
|
|
ratioAgixToAsi,
|
|
|
|
exampleBuyInUsd,
|
|
|
|
ratioFetToAsi
|
|
|
|
} from '@/constants'
|
2024-03-29 22:54:07 +01:00
|
|
|
import { useState } from 'react'
|
|
|
|
import { FormAmount } from './FormAmount'
|
2024-03-30 01:32:46 +01:00
|
|
|
import { fetcher, formatNumber } from '@/utils'
|
|
|
|
import { Content } from '@/components/Content'
|
2024-03-29 19:54:14 +01:00
|
|
|
|
|
|
|
export function Prices() {
|
2024-03-29 22:54:07 +01:00
|
|
|
const [amountSwap, setAmountSwap] = useState(100)
|
|
|
|
const [debouncedAmountSwap] = useDebounce(amountSwap, 500)
|
|
|
|
|
2024-03-29 19:54:14 +01:00
|
|
|
const { data: dataPrices } = useSWR(
|
2024-03-30 01:32:46 +01:00
|
|
|
`/api/prices/?tokens=${tokens.toString()}`,
|
2024-03-29 19:54:14 +01:00
|
|
|
fetcher
|
|
|
|
)
|
2024-03-30 02:03:43 +01:00
|
|
|
|
2024-03-29 19:54:14 +01:00
|
|
|
const { data: dataSwapOceanToAgix } = useSWR(
|
|
|
|
`/api/quote/?src=${tokens[0]}&dst=${tokens[2]}&amount=${
|
2024-03-29 22:54:07 +01:00
|
|
|
debouncedAmountSwap * 1e18
|
2024-03-29 19:54:14 +01:00
|
|
|
}`,
|
|
|
|
fetcher
|
|
|
|
)
|
2024-03-30 02:03:43 +01:00
|
|
|
console.log(dataSwapOceanToAgix)
|
2024-03-29 19:54:14 +01:00
|
|
|
|
|
|
|
const { data: dataSwapOceanToFet } = useSWR(
|
|
|
|
`/api/quote/?src=${tokens[0]}&dst=${tokens[1]}&amount=${
|
2024-03-29 22:54:07 +01:00
|
|
|
debouncedAmountSwap * 1e18
|
2024-03-29 19:54:14 +01:00
|
|
|
}`,
|
|
|
|
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 (
|
|
|
|
<>
|
2024-03-29 22:54:07 +01:00
|
|
|
<div className={styles.grid}>
|
|
|
|
<div className={styles.results}>
|
|
|
|
<h3>
|
2024-03-30 01:32:46 +01:00
|
|
|
Swapping{' '}
|
|
|
|
<FormAmount amount={amountSwap} setAmount={setAmountSwap} /> OCEAN (
|
|
|
|
{formatNumber(debouncedAmountSwap * priceOcean, 'USD')}) gets you:
|
2024-03-29 22:54:07 +01:00
|
|
|
</h3>
|
2024-03-29 19:54:14 +01:00
|
|
|
|
2024-03-29 22:54:07 +01:00
|
|
|
<Result
|
2024-03-30 02:03:43 +01:00
|
|
|
tokenSymbol="OCEAN"
|
|
|
|
tokenAddress="0x967da4048cd07ab37855c090aaf366e4ce1b9f48"
|
2024-03-29 22:54:07 +01:00
|
|
|
amount={debouncedAmountSwap}
|
|
|
|
amountAsi={debouncedAmountSwap * ratioOceanToAsi}
|
|
|
|
amountFiat={debouncedAmountSwap * ratioOceanToAsi * priceAsi}
|
|
|
|
/>
|
2024-03-29 19:54:14 +01:00
|
|
|
|
2024-03-29 22:54:07 +01:00
|
|
|
<Result
|
2024-03-30 02:03:43 +01:00
|
|
|
tokenSymbol="AGIX"
|
|
|
|
tokenAddress="0x5b7533812759b45c2b44c19e320ba2cd2681b542"
|
2024-03-29 22:54:07 +01:00
|
|
|
amount={
|
|
|
|
dataSwapOceanToAgix?.dstAmount /
|
|
|
|
Number(`1e${dataSwapOceanToAgix?.dstToken?.decimals}`) || 0
|
|
|
|
}
|
|
|
|
amountAsi={
|
|
|
|
(dataSwapOceanToAgix?.dstAmount /
|
|
|
|
Number(`1e${dataSwapOceanToAgix?.dstToken?.decimals}`) || 0) *
|
|
|
|
ratioAgixToAsi
|
|
|
|
}
|
|
|
|
amountFiat={
|
|
|
|
(dataSwapOceanToAgix?.dstAmount /
|
|
|
|
Number(`1e${dataSwapOceanToAgix?.dstToken?.decimals}`) || 0) *
|
|
|
|
ratioAgixToAsi *
|
|
|
|
priceAsi
|
|
|
|
}
|
|
|
|
/>
|
2024-03-29 19:54:14 +01:00
|
|
|
|
2024-03-29 22:54:07 +01:00
|
|
|
<Result
|
2024-03-30 02:03:43 +01:00
|
|
|
tokenSymbol="FET"
|
|
|
|
tokenAddress="0xaea46a60368a7bd060eec7df8cba43b7ef41ad85"
|
2024-03-29 22:54:07 +01:00
|
|
|
amount={
|
|
|
|
dataSwapOceanToFet?.dstAmount /
|
|
|
|
Number(`1e${dataSwapOceanToFet?.dstToken?.decimals}`) || 0
|
|
|
|
}
|
|
|
|
amountAsi={
|
|
|
|
(dataSwapOceanToFet?.dstAmount /
|
|
|
|
Number(`1e${dataSwapOceanToFet?.dstToken?.decimals}`) || 0) *
|
|
|
|
ratioFetToAsi
|
|
|
|
}
|
|
|
|
amountFiat={
|
|
|
|
(dataSwapOceanToFet?.dstAmount /
|
|
|
|
Number(`1e${dataSwapOceanToFet?.dstToken?.decimals}`) || 0) *
|
|
|
|
priceAsi
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-03-30 02:20:15 +01:00
|
|
|
|
|
|
|
<div className={styles.results}>
|
|
|
|
<h3>Buying with ${exampleBuyInUsd} right now gets you:</h3>
|
|
|
|
<Result
|
|
|
|
tokenSymbol="OCEAN"
|
|
|
|
tokenAddress="0x967da4048cd07ab37855c090aaf366e4ce1b9f48"
|
|
|
|
amount={priceOcean ? exampleBuyInUsd / priceOcean : 0}
|
|
|
|
amountAsi={
|
|
|
|
priceOcean ? (exampleBuyInUsd / priceOcean) * ratioOceanToAsi : 0
|
|
|
|
}
|
|
|
|
amountFiat={
|
|
|
|
priceOcean
|
|
|
|
? (exampleBuyInUsd / priceOcean) * ratioOceanToAsi * priceAsi
|
|
|
|
: 0
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Result
|
|
|
|
tokenSymbol="AGIX"
|
|
|
|
tokenAddress="0x5b7533812759b45c2b44c19e320ba2cd2681b542"
|
|
|
|
amount={priceAgix ? exampleBuyInUsd / priceAgix : 0}
|
|
|
|
amountAsi={
|
|
|
|
priceAgix ? (exampleBuyInUsd / priceAgix) * ratioAgixToAsi : 0
|
|
|
|
}
|
|
|
|
amountFiat={
|
|
|
|
priceAgix
|
|
|
|
? (exampleBuyInUsd / priceAgix) * ratioAgixToAsi * priceAsi
|
|
|
|
: 0
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Result
|
|
|
|
tokenSymbol="FET"
|
|
|
|
tokenAddress="0xaea46a60368a7bd060eec7df8cba43b7ef41ad85"
|
|
|
|
amount={priceFet ? exampleBuyInUsd / priceFet : 0}
|
|
|
|
amountAsi={
|
|
|
|
priceFet ? (exampleBuyInUsd / priceFet) * ratioFetToAsi : 0
|
|
|
|
}
|
|
|
|
amountFiat={
|
|
|
|
priceFet
|
|
|
|
? (exampleBuyInUsd / priceFet) * ratioFetToAsi * priceAsi
|
|
|
|
: 0
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-03-29 19:54:14 +01:00
|
|
|
</div>
|
2024-03-30 01:32:46 +01:00
|
|
|
<Content prices={{ ocean: priceOcean, agix: priceAgix, asi: priceAsi }} />
|
2024-03-29 19:54:14 +01:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|