import { useEffect, useState } from 'react'
import { Button } from 'react-bootstrap'
import useSWR from 'swr'
const fetcher = url => fetch(url).then(res => res.json())
export default function Price () {
const [asSats, setAsSats] = useState(undefined)
useEffect(() => {
setAsSats(localStorage.getItem('asSats'))
}, [])
const { data } = useSWR(
'https://api.coinbase.com/v2/prices/BTC-USD/spot',
fetcher,
{
refreshInterval: 30000
})
if (!data || !data.data) return null
const fixed = (n, f) => Number.parseFloat(n).toFixed(f)
const handleClick = () => {
if (asSats) {
localStorage.removeItem('asSats')
setAsSats(undefined)
} else {
localStorage.setItem('asSats', 'yep')
setAsSats('yep')
}
}
if (asSats) {
return (
)
}
return (
)
}