From 35b6707ae489a7811af8a423628a0133e4b016b6 Mon Sep 17 00:00:00 2001 From: Nicholas Barnett Date: Wed, 26 Jun 2024 16:40:27 -0500 Subject: [PATCH] fix(maps-testnet): showing custom error message --- src/app/_components/PageWrapper.tsx | 2 +- src/app/_components/StatusBar/CMSStatusBars.tsx | 11 +++++++---- src/app/getStatusBarContent.ts | 10 ++++++---- src/app/signers/SignersMapComponent.tsx | 6 +----- src/app/signers/useSignerLocations.ts | 8 +++++--- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/app/_components/PageWrapper.tsx b/src/app/_components/PageWrapper.tsx index 73b2c4765..e9a2de2b5 100644 --- a/src/app/_components/PageWrapper.tsx +++ b/src/app/_components/PageWrapper.tsx @@ -56,7 +56,7 @@ export function PageWrapper({ }: { tokenPrice: TokenPrice; children: ReactNode; - statusBarContent: IncidentContent; + statusBarContent: IncidentContent | null; }) { const statusBarBg = useColorModeValue('black', 'white'); return ( diff --git a/src/app/_components/StatusBar/CMSStatusBars.tsx b/src/app/_components/StatusBar/CMSStatusBars.tsx index bfcf9469a..58325beb0 100644 --- a/src/app/_components/StatusBar/CMSStatusBars.tsx +++ b/src/app/_components/StatusBar/CMSStatusBars.tsx @@ -7,11 +7,14 @@ import { Flex } from '../../../ui/Flex'; import { useColorMode } from '../../../ui/hooks/useColorMode'; import { StatusBarBase } from './StatusBarBase'; -export function CMSStatusBars({ statusBarContent }: { statusBarContent: IncidentContent }) { +export function CMSStatusBars({ statusBarContent }: { statusBarContent: IncidentContent | null }) { const isTestnet = useGlobalContext().activeNetwork.mode === 'testnet'; - const incidentsToShow = statusBarContent?.items?.filter( - alert => (alert.fields.showOnTestnet && isTestnet) || (alert.fields.showOnMainnet && !isTestnet) - ); + const incidentsToShow = !statusBarContent + ? [] + : statusBarContent?.items?.filter( + alert => + (alert.fields.showOnTestnet && isTestnet) || (alert.fields.showOnMainnet && !isTestnet) + ); const colorMode = useColorMode().colorMode; return ( { - return fetch(CMS_URL, { - next: { revalidate: 60 }, // Revalidate every 1 minute - }).then(res => res.json()); +export async function getStatusBarContent(): Promise { + return CMS_URL + ? fetch(CMS_URL, { + next: { revalidate: 60 }, // Revalidate every 1 minute + }).then(res => res.json()) + : Promise.resolve(null); } diff --git a/src/app/signers/SignersMapComponent.tsx b/src/app/signers/SignersMapComponent.tsx index 431277657..ea702851a 100644 --- a/src/app/signers/SignersMapComponent.tsx +++ b/src/app/signers/SignersMapComponent.tsx @@ -144,11 +144,7 @@ export function SignersMapComponentBase() { export function SignersMapComponent() { return ( - + }> diff --git a/src/app/signers/useSignerLocations.ts b/src/app/signers/useSignerLocations.ts index f5a6276f2..206aef0ef 100644 --- a/src/app/signers/useSignerLocations.ts +++ b/src/app/signers/useSignerLocations.ts @@ -17,9 +17,11 @@ export function useSignersLocation() { return useSuspenseQuery({ queryKey: [SIGNER_LOCATION_QUERY_KEY], queryFn: () => - fetch(`https://assets.hiro.so/stacks/${activeNetwork.mode}/crawler/signer-nodes.json`).then( - res => res.json() - ), + fetch(`https://assets.hiro.so/stacks/${activeNetwork.mode}/crawler/signer-nodes.json`) + .then(res => res.json()) + .catch(err => { + throw new Error('No signer location data available.'); + }), staleTime: TEN_MINUTES, }); }