Skip to content

Commit

Permalink
fix(maps-testnet): showing custom error message
Browse files Browse the repository at this point in the history
  • Loading branch information
BLuEScioN committed Jun 26, 2024
1 parent b2cafe3 commit 35b6707
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/app/_components/PageWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function PageWrapper({
}: {
tokenPrice: TokenPrice;
children: ReactNode;
statusBarContent: IncidentContent;
statusBarContent: IncidentContent | null;
}) {
const statusBarBg = useColorModeValue('black', 'white');
return (
Expand Down
11 changes: 7 additions & 4 deletions src/app/_components/StatusBar/CMSStatusBars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {

Check warning on line 10 in src/app/_components/StatusBar/CMSStatusBars.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/StatusBar/CMSStatusBars.tsx#L10

Added line #L10 was not covered by tests
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(

Check warning on line 14 in src/app/_components/StatusBar/CMSStatusBars.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/StatusBar/CMSStatusBars.tsx#L13-L14

Added lines #L13 - L14 were not covered by tests
alert =>
(alert.fields.showOnTestnet && isTestnet) || (alert.fields.showOnMainnet && !isTestnet)
);
const colorMode = useColorMode().colorMode;
return (
<Flex
Expand Down
10 changes: 6 additions & 4 deletions src/app/getStatusBarContent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { CMS_URL } from '../common/constants/env';
import { IncidentContent } from '../common/types/incidents';

export async function getStatusBarContent(): Promise<IncidentContent> {
return fetch(CMS_URL, {
next: { revalidate: 60 }, // Revalidate every 1 minute
}).then(res => res.json());
export async function getStatusBarContent(): Promise<IncidentContent | null> {

Check warning on line 4 in src/app/getStatusBarContent.ts

View check run for this annotation

Codecov / codecov/patch

src/app/getStatusBarContent.ts#L4

Added line #L4 was not covered by tests
return CMS_URL
? fetch(CMS_URL, {

Check warning on line 6 in src/app/getStatusBarContent.ts

View check run for this annotation

Codecov / codecov/patch

src/app/getStatusBarContent.ts#L6

Added line #L6 was not covered by tests
next: { revalidate: 60 }, // Revalidate every 1 minute
}).then(res => res.json())
: Promise.resolve(null);

Check warning on line 9 in src/app/getStatusBarContent.ts

View check run for this annotation

Codecov / codecov/patch

src/app/getStatusBarContent.ts#L8-L9

Added lines #L8 - L9 were not covered by tests
}
6 changes: 1 addition & 5 deletions src/app/signers/SignersMapComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,7 @@ export function SignersMapComponentBase() {

export function SignersMapComponent() {
return (
<ExplorerErrorBoundary
Wrapper={Card}
wrapperProps={{ height: '100%', width: '100%' }}
tryAgainButton
>
<ExplorerErrorBoundary Wrapper={Card} wrapperProps={{ height: '100%', width: '100%' }}>
<Suspense fallback={<SignersMapSkeleton />}>
<SignersMapComponentBase />
</Suspense>
Expand Down
8 changes: 5 additions & 3 deletions src/app/signers/useSignerLocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export function useSignersLocation() {
return useSuspenseQuery<SignerLocation[]>({
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.');

Check warning on line 23 in src/app/signers/useSignerLocations.ts

View check run for this annotation

Codecov / codecov/patch

src/app/signers/useSignerLocations.ts#L20-L23

Added lines #L20 - L23 were not covered by tests
}),
staleTime: TEN_MINUTES,
});
}

0 comments on commit 35b6707

Please sign in to comment.