-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
313 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Banner, Link } from "@stellar/design-system"; | ||
|
||
import { getRelevantMaintenanceMsg } from "@/helpers/getRelevantMaintenanceMsg"; | ||
import { sanitizeHtml } from "@/helpers/sanitizeHtml"; | ||
import { useMaintenanceData } from "@/query/useMaintenanceData"; | ||
import { useStore } from "@/store/useStore"; | ||
|
||
export const MaintenanceBanner = () => { | ||
const { network } = useStore(); | ||
const { data, error } = useMaintenanceData(); | ||
|
||
const relevantMaintenance = getRelevantMaintenanceMsg(network.id, data); | ||
|
||
const renderBanner = (message: React.ReactNode) => ( | ||
<Banner variant="primary">{message}</Banner> | ||
); | ||
|
||
if (error) { | ||
return renderBanner(error.message); | ||
} | ||
|
||
if (!relevantMaintenance) { | ||
return network.id === "testnet" | ||
? renderBanner( | ||
<> | ||
Failed to fetch testnet reset date. Check status{" "} | ||
<Link href="https://9sl3dhr1twv1.statuspage.io/">here</Link>. | ||
</>, | ||
) | ||
: null; | ||
} | ||
|
||
if (relevantMaintenance.length === 0) { | ||
return network.id === "testnet" | ||
? renderBanner("The next testnet reset has not yet been scheduled.") | ||
: null; | ||
} | ||
|
||
const nextMaintenance = relevantMaintenance[0]; | ||
const date = new Date(nextMaintenance.scheduled_for); | ||
|
||
return renderBanner( | ||
<> | ||
<Link href={`https://status.stellar.org/incidents/${nextMaintenance.id}`}> | ||
{nextMaintenance.name} | ||
</Link>{" "} | ||
on {date.toDateString()} at {date.toTimeString()} | ||
{nextMaintenance.incident_updates.map((update) => ( | ||
<div key={update.id}>{sanitizeHtml(update.body)}</div> | ||
))} | ||
</>, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { NetworkType, StatusPageScheduled } from "@/types/types"; | ||
|
||
export const getRelevantMaintenanceMsg = ( | ||
currentNetwork: NetworkType, | ||
allMaintenance?: StatusPageScheduled[], | ||
) => { | ||
if (!allMaintenance) { | ||
return false; | ||
} | ||
|
||
// If we’re on the test network, we care about all scheduled maintenance. If | ||
// we’re on the public network, we only care about public network maintenance. | ||
return allMaintenance.filter((maintenance) => | ||
maintenance.components.some((component) => | ||
currentNetwork === "testnet" | ||
? true | ||
: component.name === "Stellar Public Network", | ||
), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import parse from "html-react-parser"; | ||
import DOMPurify from "dompurify"; | ||
|
||
export const sanitizeHtml = (html: string | Node) => { | ||
return parse(DOMPurify.sanitize(html, { USE_PROFILES: { html: true } })); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use client"; | ||
|
||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
refetchOnWindowFocus: false, | ||
retry: false, | ||
}, | ||
}, | ||
}); | ||
|
||
export const QueryProvider = ({ children }: { children: React.ReactNode }) => { | ||
return ( | ||
<QueryClientProvider client={queryClient}> | ||
{children} | ||
<ReactQueryDevtools initialIsOpen={false} /> | ||
</QueryClientProvider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { StatusPageScheduled } from "@/types/types"; | ||
|
||
export const useMaintenanceData = () => { | ||
const query = useQuery<StatusPageScheduled[]>({ | ||
queryKey: ["maintenanceData"], | ||
queryFn: async () => { | ||
try { | ||
const scheduleResponse = await fetch( | ||
"https://9sl3dhr1twv1.statuspage.io/api/v2/summary.json", | ||
); | ||
const scheduleResponseJson = await scheduleResponse.json(); | ||
|
||
return scheduleResponseJson.scheduled_maintenances; | ||
} catch (e) { | ||
throw Error("Failed to fetch testnet reset date."); | ||
} | ||
}, | ||
}); | ||
|
||
return query; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.