Fix errors if me null

This commit is contained in:
ekzyis 2022-09-18 03:07:14 +02:00
parent 7d49b686aa
commit 22e07a4318
2 changed files with 6 additions and 6 deletions

View File

@ -43,7 +43,7 @@ export function getGetServerSideProps (query, variables = null, notFoundFunc, re
query: ME_SSR query: ME_SSR
}) })
const price = await getPrice(me.fiatCurrency) const price = await getPrice(me?.fiatCurrency)
// we want to use client-side cache // we want to use client-side cache
if (nodata && query) { if (nodata && query) {

View File

@ -15,7 +15,7 @@ export const CURRENCY_SYMBOLS = {
'EUR': '€' 'EUR': '€'
} }
const endpoint = (fiat) => `https://api.coinbase.com/v2/prices/BTC-${fiat}/spot` const endpoint = (fiat) => `https://api.coinbase.com/v2/prices/BTC-${fiat ?? 'USD'}/spot`
export async function getPrice (fiat) { export async function getPrice (fiat) {
const data = await fetcher(endpoint(fiat)) const data = await fetcher(endpoint(fiat))
@ -23,9 +23,9 @@ export async function getPrice (fiat) {
} }
export function PriceProvider ({ price, children }) { export function PriceProvider ({ price, children }) {
const { fiatCurrency } = useMe() const me = useMe()
const { data } = useSWR( const { data } = useSWR(
endpoint(fiatCurrency), endpoint(me?.fiatCurrency),
fetcher, fetcher,
{ {
refreshInterval: 30000 refreshInterval: 30000
@ -53,8 +53,8 @@ export default function Price () {
setAsSats(localStorage.getItem('asSats')) setAsSats(localStorage.getItem('asSats'))
}, []) }, [])
const price = usePrice() const price = usePrice()
const { fiatCurrency } = useMe() const me = useMe()
const fiatSymbol = CURRENCY_SYMBOLS[fiatCurrency]; const fiatSymbol = CURRENCY_SYMBOLS[me?.fiatCurrency || 'USD'];
if (!price) return null if (!price) return null