mirror of
https://github.com/kremalicious/asi-calculator.git
synced 2024-12-22 17:33:18 +01:00
tweaks
This commit is contained in:
parent
bc75e64f82
commit
a9c5c20bc2
@ -7,7 +7,6 @@ const apiUrl = 'https://api.1inch.dev/swap/v6.0/1/quote'
|
|||||||
const config: RequestInit = {
|
const config: RequestInit = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${process.env.ONEINCH_API_KEY}`,
|
Authorization: `Bearer ${process.env.ONEINCH_API_KEY}`,
|
||||||
accept: 'application/json',
|
|
||||||
'content-type': 'application/json'
|
'content-type': 'application/json'
|
||||||
},
|
},
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -24,18 +23,27 @@ export async function GET(request: NextRequest) {
|
|||||||
return Response.json(null, { status: 400 })
|
return Response.json(null, { status: 400 })
|
||||||
}
|
}
|
||||||
|
|
||||||
let data
|
|
||||||
const url = `${apiUrl}/?src=${src}&dst=${dst}&amount=${amount}&includeTokensInfo=true&includeProtocols=true`
|
const url = `${apiUrl}/?src=${src}&dst=${dst}&amount=${amount}&includeTokensInfo=true&includeProtocols=true`
|
||||||
|
let data
|
||||||
|
let status
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(url, config)
|
const res = await fetch(url, config)
|
||||||
const json = await res.json()
|
const json = await res.json()
|
||||||
|
|
||||||
data = json
|
data = json
|
||||||
|
status = res.status
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error((error as Error).message)
|
console.error((error as Error).message)
|
||||||
data = null
|
data = null
|
||||||
|
status = 500
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response.json(data)
|
return new Response(JSON.stringify(data), {
|
||||||
|
status,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Cache-Control': 'public, s-maxage=10'
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ import './globals.css'
|
|||||||
const firaCode = Fira_Code({ subsets: ['latin'] })
|
const firaCode = Fira_Code({ subsets: ['latin'] })
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: 'Create Next App',
|
title: 'OCEAN + AGIX + FET = ASI',
|
||||||
description: 'Generated by create next app'
|
description: 'Calculate how much ASI you get for your OCEAN, AGIX, or FET'
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function RootLayout({
|
export default function RootLayout({
|
||||||
|
@ -2,17 +2,6 @@
|
|||||||
margin-top: 2rem;
|
margin-top: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.results h3,
|
.results h3 {
|
||||||
.results p {
|
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.results p {
|
|
||||||
padding-left: 100px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.results p span {
|
|
||||||
margin-left: -100px;
|
|
||||||
min-width: 90px;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
6
features/Prices/components/Result.module.css
Normal file
6
features/Prices/components/Result.module.css
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
.result {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount {
|
||||||
|
}
|
@ -1,3 +1,6 @@
|
|||||||
|
import { formatCurrency } from '@coingecko/cryptoformat'
|
||||||
|
import styles from './Result.module.css'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
symbol: string
|
symbol: string
|
||||||
amount: number
|
amount: number
|
||||||
@ -5,12 +8,23 @@ type Props = {
|
|||||||
amountFiat: number
|
amountFiat: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatPrice(price: number, currency: string) {
|
||||||
|
return formatCurrency(price, currency, 'en', false, {
|
||||||
|
decimalPlaces: 3,
|
||||||
|
significantFigures: 5
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function Result({ symbol, amount, amountAsi, amountFiat }: Props) {
|
export function Result({ symbol, amount, amountAsi, amountFiat }: Props) {
|
||||||
return (
|
return (
|
||||||
|
<div className={styles.result}>
|
||||||
<p>
|
<p>
|
||||||
<span>{symbol}</span> {amount} {symbol}, convertible to{' '}
|
{formatPrice(amount, symbol)} →{' '}
|
||||||
<strong>{amountAsi} ASI</strong> currently worth{' '}
|
<strong title={`${amountAsi}`}>{formatPrice(amountAsi, 'ASI')}</strong>
|
||||||
<strong>${amountFiat.toFixed(2)}</strong>.
|
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
= <strong>{formatPrice(amountFiat, 'USD')}</strong>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
9
package-lock.json
generated
9
package-lock.json
generated
@ -8,6 +8,7 @@
|
|||||||
"name": "ocean-fetch-price-difference",
|
"name": "ocean-fetch-price-difference",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@coingecko/cryptoformat": "^0.8.1",
|
||||||
"next": "14.1.4",
|
"next": "14.1.4",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
"react-dom": "^18",
|
"react-dom": "^18",
|
||||||
@ -43,6 +44,14 @@
|
|||||||
"node": ">=6.9.0"
|
"node": ">=6.9.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@coingecko/cryptoformat": {
|
||||||
|
"version": "0.8.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@coingecko/cryptoformat/-/cryptoformat-0.8.1.tgz",
|
||||||
|
"integrity": "sha512-pBxGpae1HIX0is1jFNB9U5RYv2OfRTKu6bcKM9BlhlfR/5TMK1m569Narra8pqlopg3MTHJ9B71zGqUbv56row==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@eslint-community/eslint-utils": {
|
"node_modules/@eslint-community/eslint-utils": {
|
||||||
"version": "4.4.0",
|
"version": "4.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz",
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@coingecko/cryptoformat": "^0.8.1",
|
||||||
"next": "14.1.4",
|
"next": "14.1.4",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
"react-dom": "^18",
|
"react-dom": "^18",
|
||||||
|
Loading…
Reference in New Issue
Block a user