1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-12-22 09:13:35 +01:00

switch to coingecko for prices

This commit is contained in:
Matthias Kretschmann 2020-03-07 18:22:12 +01:00
parent 95db74a2f1
commit a9ca7c2444
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -3,15 +3,15 @@ import fetch from 'node-fetch'
import styles from './Conversion.module.scss'
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)
if (!response.ok) console.error(response.statusText)
const data = await response.json()
/* eslint-disable @typescript-eslint/camelcase */
const { price_usd, price_eur } = data[0]
const dollar = (amount * price_usd).toFixed(2)
const euro = (amount * price_eur).toFixed(2)
/* eslint-enable @typescript-eslint/camelcase */
const { usd, eur } = data.ethereum
const dollar = (amount * usd).toFixed(2)
const euro = (amount * eur).toFixed(2)
return { dollar, euro }
}