mirror of
https://github.com/kremalicious/asi-calculator.git
synced 2024-12-22 17:33:18 +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'
|
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 = {
|
const config: RequestInit = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${process.env.ONEINCH_API_KEY}`,
|
|
||||||
'content-type': 'application/json'
|
'content-type': 'application/json'
|
||||||
},
|
},
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
next: { revalidate: 60 }
|
next: { revalidate: 30 }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
const searchParams = request?.nextUrl?.searchParams
|
const searchParams = request?.nextUrl?.searchParams
|
||||||
const src = searchParams?.get('src')
|
const tokenIn = searchParams?.get('tokenIn')
|
||||||
const dst = searchParams?.get('dst')
|
const tokenOut = searchParams?.get('tokenOut')
|
||||||
const amount = searchParams?.get('amount')
|
const amountIn = searchParams?.get('amountIn')
|
||||||
|
|
||||||
if (!src || !dst || !amount) {
|
if (!tokenIn || !tokenOut || !amountIn) {
|
||||||
return Response.json(null, { status: 400 })
|
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 data
|
||||||
let status
|
let status
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ export default function Home() {
|
|||||||
<Prices />
|
<Prices />
|
||||||
</main>
|
</main>
|
||||||
<footer className={styles.footer}>
|
<footer className={styles.footer}>
|
||||||
Send ❤️ & meme coins to krema.eth
|
Send ❤️ and memecoins to krema.eth
|
||||||
</footer>
|
</footer>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
@ -16,7 +16,8 @@ export function Content({ prices }: Props) {
|
|||||||
fixed ASI exchange rate
|
fixed ASI exchange rate
|
||||||
</a>
|
</a>
|
||||||
, the fluctuating fiat values fetched from <a href="">Coingecko</a>, and
|
, 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>
|
</p>
|
||||||
|
|
||||||
<ul className={styles.calculationBase}>
|
<ul className={styles.calculationBase}>
|
||||||
|
@ -26,16 +26,12 @@ export function Prices() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const { data: dataSwapOceanToAgix } = useSWR(
|
const { data: dataSwapOceanToAgix } = useSWR(
|
||||||
`/api/quote/?src=${tokens[0]}&dst=${tokens[2]}&amount=${
|
`/api/quote/?tokenIn=${tokens[0]}&tokenOut=${tokens[2]}&amountIn=${debouncedAmountSwap}`,
|
||||||
debouncedAmountSwap * 1e18
|
|
||||||
}`,
|
|
||||||
fetcher
|
fetcher
|
||||||
)
|
)
|
||||||
|
|
||||||
const { data: dataSwapOceanToFet } = useSWR(
|
const { data: dataSwapOceanToFet } = useSWR(
|
||||||
`/api/quote/?src=${tokens[0]}&dst=${tokens[1]}&amount=${
|
`/api/quote/?tokenIn=${tokens[0]}&tokenOut=${tokens[1]}&amountIn=${debouncedAmountSwap}`,
|
||||||
debouncedAmountSwap * 1e18
|
|
||||||
}`,
|
|
||||||
fetcher
|
fetcher
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -66,17 +62,17 @@ export function Prices() {
|
|||||||
tokenSymbol="AGIX"
|
tokenSymbol="AGIX"
|
||||||
tokenAddress="0x5b7533812759b45c2b44c19e320ba2cd2681b542"
|
tokenAddress="0x5b7533812759b45c2b44c19e320ba2cd2681b542"
|
||||||
amount={
|
amount={
|
||||||
dataSwapOceanToAgix?.dstAmount /
|
dataSwapOceanToAgix?.amountOut /
|
||||||
Number(`1e${dataSwapOceanToAgix?.dstToken?.decimals}`) || 0
|
Number(`1e${dataSwapOceanToAgix?.decimals}`) || 0
|
||||||
}
|
}
|
||||||
amountAsi={
|
amountAsi={
|
||||||
(dataSwapOceanToAgix?.dstAmount /
|
(dataSwapOceanToAgix?.amountOut /
|
||||||
Number(`1e${dataSwapOceanToAgix?.dstToken?.decimals}`) || 0) *
|
Number(`1e${dataSwapOceanToAgix?.decimals}`) || 0) *
|
||||||
ratioAgixToAsi
|
ratioAgixToAsi
|
||||||
}
|
}
|
||||||
amountFiat={
|
amountFiat={
|
||||||
(dataSwapOceanToAgix?.dstAmount /
|
(dataSwapOceanToAgix?.amountOut /
|
||||||
Number(`1e${dataSwapOceanToAgix?.dstToken?.decimals}`) || 0) *
|
Number(`1e${dataSwapOceanToAgix?.decimals}`) || 0) *
|
||||||
ratioAgixToAsi *
|
ratioAgixToAsi *
|
||||||
priceAsi
|
priceAsi
|
||||||
}
|
}
|
||||||
@ -86,18 +82,17 @@ export function Prices() {
|
|||||||
tokenSymbol="FET"
|
tokenSymbol="FET"
|
||||||
tokenAddress="0xaea46a60368a7bd060eec7df8cba43b7ef41ad85"
|
tokenAddress="0xaea46a60368a7bd060eec7df8cba43b7ef41ad85"
|
||||||
amount={
|
amount={
|
||||||
dataSwapOceanToFet?.dstAmount /
|
dataSwapOceanToFet?.amountOut /
|
||||||
Number(`1e${dataSwapOceanToFet?.dstToken?.decimals}`) || 0
|
Number(`1e${dataSwapOceanToFet?.decimals}`) || 0
|
||||||
}
|
}
|
||||||
amountAsi={
|
amountAsi={
|
||||||
(dataSwapOceanToFet?.dstAmount /
|
(dataSwapOceanToFet?.amountOut /
|
||||||
Number(`1e${dataSwapOceanToFet?.dstToken?.decimals}`) || 0) *
|
Number(`1e${dataSwapOceanToFet?.decimals}`) || 0) *
|
||||||
ratioFetToAsi
|
ratioFetToAsi
|
||||||
}
|
}
|
||||||
amountFiat={
|
amountFiat={
|
||||||
(dataSwapOceanToFet?.dstAmount /
|
(dataSwapOceanToFet?.amountOut /
|
||||||
Number(`1e${dataSwapOceanToFet?.dstToken?.decimals}`) || 0) *
|
Number(`1e${dataSwapOceanToFet?.decimals}`) || 0) * priceAsi
|
||||||
priceAsi
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user