From 22e07a4318b2637db0e948a433b58b68633120f5 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sun, 18 Sep 2022 03:07:14 +0200 Subject: [PATCH] Fix errors if me null --- api/ssrApollo.js | 2 +- components/price.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/ssrApollo.js b/api/ssrApollo.js index 3e655938..3c3097c6 100644 --- a/api/ssrApollo.js +++ b/api/ssrApollo.js @@ -43,7 +43,7 @@ export function getGetServerSideProps (query, variables = null, notFoundFunc, re query: ME_SSR }) - const price = await getPrice(me.fiatCurrency) + const price = await getPrice(me?.fiatCurrency) // we want to use client-side cache if (nodata && query) { diff --git a/components/price.js b/components/price.js index 257c12eb..e9573203 100644 --- a/components/price.js +++ b/components/price.js @@ -15,7 +15,7 @@ export const CURRENCY_SYMBOLS = { '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) { const data = await fetcher(endpoint(fiat)) @@ -23,9 +23,9 @@ export async function getPrice (fiat) { } export function PriceProvider ({ price, children }) { - const { fiatCurrency } = useMe() + const me = useMe() const { data } = useSWR( - endpoint(fiatCurrency), + endpoint(me?.fiatCurrency), fetcher, { refreshInterval: 30000 @@ -53,8 +53,8 @@ export default function Price () { setAsSats(localStorage.getItem('asSats')) }, []) const price = usePrice() - const { fiatCurrency } = useMe() - const fiatSymbol = CURRENCY_SYMBOLS[fiatCurrency]; + const me = useMe() + const fiatSymbol = CURRENCY_SYMBOLS[me?.fiatCurrency || 'USD']; if (!price) return null