mirror of
https://github.com/kremalicious/blog.git
synced 2024-12-22 17:23:50 +01:00
switch to coingecko for prices
This commit is contained in:
parent
95db74a2f1
commit
a9ca7c2444
@ -3,15 +3,15 @@ import fetch from 'node-fetch'
|
|||||||
import styles from './Conversion.module.scss'
|
import styles from './Conversion.module.scss'
|
||||||
|
|
||||||
export async function getFiat(amount: number) {
|
export async function getFiat(amount: number) {
|
||||||
const url = 'https://api.coinmarketcap.com/v1/ticker/ethereum/?convert=EUR'
|
const url =
|
||||||
|
'https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=eur%2Cusd'
|
||||||
const response = await fetch(url)
|
const response = await fetch(url)
|
||||||
|
|
||||||
if (!response.ok) console.error(response.statusText)
|
if (!response.ok) console.error(response.statusText)
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
/* eslint-disable @typescript-eslint/camelcase */
|
const { usd, eur } = data.ethereum
|
||||||
const { price_usd, price_eur } = data[0]
|
const dollar = (amount * usd).toFixed(2)
|
||||||
const dollar = (amount * price_usd).toFixed(2)
|
const euro = (amount * eur).toFixed(2)
|
||||||
const euro = (amount * price_eur).toFixed(2)
|
|
||||||
/* eslint-enable @typescript-eslint/camelcase */
|
|
||||||
|
|
||||||
return { dollar, euro }
|
return { dollar, euro }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user