mirror of
https://github.com/kremalicious/asi-calculator.git
synced 2024-12-22 09:23:16 +01:00
new quote fetching
This commit is contained in:
parent
0927218eea
commit
263a089b97
@ -2,28 +2,27 @@ import { type NextRequest } from 'next/server'
|
||||
|
||||
export const runtime = 'edge'
|
||||
|
||||
const apiUrl = 'https://api.1inch.dev/swap/v6.0/1/quote'
|
||||
const apiUrl = process.env.WEB3_API_URL
|
||||
|
||||
const config: RequestInit = {
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.ONEINCH_API_KEY}`,
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
method: 'GET',
|
||||
next: { revalidate: 60 }
|
||||
next: { revalidate: 30 }
|
||||
}
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const searchParams = request?.nextUrl?.searchParams
|
||||
const src = searchParams?.get('src')
|
||||
const dst = searchParams?.get('dst')
|
||||
const amount = searchParams?.get('amount')
|
||||
const tokenIn = searchParams?.get('tokenIn')
|
||||
const tokenOut = searchParams?.get('tokenOut')
|
||||
const amountIn = searchParams?.get('amountIn')
|
||||
|
||||
if (!src || !dst || !amount) {
|
||||
if (!tokenIn || !tokenOut || !amountIn) {
|
||||
return Response.json(null, { status: 400 })
|
||||
}
|
||||
|
||||
const url = `${apiUrl}/?src=${src}&dst=${dst}&amount=${amount}&includeTokensInfo=true&includeProtocols=true`
|
||||
const url = `${apiUrl}/quote?tokenIn=${tokenIn}&tokenOut=${tokenOut}&amountIn=${amountIn}`
|
||||
let data
|
||||
let status
|
||||
|
||||
|
@ -13,7 +13,7 @@ export default function Home() {
|
||||
<Prices />
|
||||
</main>
|
||||
<footer className={styles.footer}>
|
||||
Send ❤️ & meme coins to krema.eth
|
||||
Send ❤️ and memecoins to krema.eth
|
||||
</footer>
|
||||
</>
|
||||
)
|
||||
|
@ -16,7 +16,8 @@ export function Content({ prices }: Props) {
|
||||
fixed ASI exchange rate
|
||||
</a>
|
||||
, the fluctuating fiat values fetched from <a href="">Coingecko</a>, and
|
||||
token swap quotes from <a href="https://1inch.io">1inch</a>.
|
||||
token swap quotes from <a href="https://uniswap.org">Uniswap</a> v3
|
||||
routes.
|
||||
</p>
|
||||
|
||||
<ul className={styles.calculationBase}>
|
||||
|
@ -26,16 +26,12 @@ export function Prices() {
|
||||
)
|
||||
|
||||
const { data: dataSwapOceanToAgix } = useSWR(
|
||||
`/api/quote/?src=${tokens[0]}&dst=${tokens[2]}&amount=${
|
||||
debouncedAmountSwap * 1e18
|
||||
}`,
|
||||
`/api/quote/?tokenIn=${tokens[0]}&tokenOut=${tokens[2]}&amountIn=${debouncedAmountSwap}`,
|
||||
fetcher
|
||||
)
|
||||
|
||||
const { data: dataSwapOceanToFet } = useSWR(
|
||||
`/api/quote/?src=${tokens[0]}&dst=${tokens[1]}&amount=${
|
||||
debouncedAmountSwap * 1e18
|
||||
}`,
|
||||
`/api/quote/?tokenIn=${tokens[0]}&tokenOut=${tokens[1]}&amountIn=${debouncedAmountSwap}`,
|
||||
fetcher
|
||||
)
|
||||
|
||||
@ -66,17 +62,17 @@ export function Prices() {
|
||||
tokenSymbol="AGIX"
|
||||
tokenAddress="0x5b7533812759b45c2b44c19e320ba2cd2681b542"
|
||||
amount={
|
||||
dataSwapOceanToAgix?.dstAmount /
|
||||
Number(`1e${dataSwapOceanToAgix?.dstToken?.decimals}`) || 0
|
||||
dataSwapOceanToAgix?.amountOut /
|
||||
Number(`1e${dataSwapOceanToAgix?.decimals}`) || 0
|
||||
}
|
||||
amountAsi={
|
||||
(dataSwapOceanToAgix?.dstAmount /
|
||||
Number(`1e${dataSwapOceanToAgix?.dstToken?.decimals}`) || 0) *
|
||||
(dataSwapOceanToAgix?.amountOut /
|
||||
Number(`1e${dataSwapOceanToAgix?.decimals}`) || 0) *
|
||||
ratioAgixToAsi
|
||||
}
|
||||
amountFiat={
|
||||
(dataSwapOceanToAgix?.dstAmount /
|
||||
Number(`1e${dataSwapOceanToAgix?.dstToken?.decimals}`) || 0) *
|
||||
(dataSwapOceanToAgix?.amountOut /
|
||||
Number(`1e${dataSwapOceanToAgix?.decimals}`) || 0) *
|
||||
ratioAgixToAsi *
|
||||
priceAsi
|
||||
}
|
||||
@ -86,18 +82,17 @@ export function Prices() {
|
||||
tokenSymbol="FET"
|
||||
tokenAddress="0xaea46a60368a7bd060eec7df8cba43b7ef41ad85"
|
||||
amount={
|
||||
dataSwapOceanToFet?.dstAmount /
|
||||
Number(`1e${dataSwapOceanToFet?.dstToken?.decimals}`) || 0
|
||||
dataSwapOceanToFet?.amountOut /
|
||||
Number(`1e${dataSwapOceanToFet?.decimals}`) || 0
|
||||
}
|
||||
amountAsi={
|
||||
(dataSwapOceanToFet?.dstAmount /
|
||||
Number(`1e${dataSwapOceanToFet?.dstToken?.decimals}`) || 0) *
|
||||
(dataSwapOceanToFet?.amountOut /
|
||||
Number(`1e${dataSwapOceanToFet?.decimals}`) || 0) *
|
||||
ratioFetToAsi
|
||||
}
|
||||
amountFiat={
|
||||
(dataSwapOceanToFet?.dstAmount /
|
||||
Number(`1e${dataSwapOceanToFet?.dstToken?.decimals}`) || 0) *
|
||||
priceAsi
|
||||
(dataSwapOceanToFet?.amountOut /
|
||||
Number(`1e${dataSwapOceanToFet?.decimals}`) || 0) * priceAsi
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user