status-frontend/src/pages/index.tsx

179 lines
6.3 KiB
TypeScript
Raw Normal View History

2022-09-29 16:25:10 +02:00
import Head from 'next/head'
2022-10-20 11:14:31 +02:00
import React, { Fragment, ReactElement } from 'react'
import { State } from '../@types'
2022-09-29 16:25:10 +02:00
import styles from '../styles/Home.module.css'
2022-10-18 19:17:32 +02:00
import { getData } from '../utils/getData'
2022-10-18 16:27:41 +02:00
import LogoAsset from '../images/logo.svg'
import CheckAsset from '../images/check.svg'
2022-10-19 21:20:09 +02:00
import GithubAsset from '../images/github.svg'
2022-10-18 21:52:14 +02:00
import addresses from '@oceanprotocol/contracts/addresses/address.json'
2022-10-19 17:40:44 +02:00
import { statusApiUri } from '../../app.config'
2022-10-19 19:17:15 +02:00
import relativeDate from 'tiny-relative-date'
2022-10-20 11:14:31 +02:00
import useSWR from 'swr'
2022-09-30 12:47:53 +02:00
function statusIcon(state: State): ReactElement {
2022-10-20 10:32:03 +02:00
if (state === State.Normal) {
2022-10-18 20:14:49 +02:00
return <CheckAsset className={`${styles.icon} ${styles.check}`} />
2022-10-20 10:32:03 +02:00
} else if (state === State.Outage) {
2022-10-18 20:14:49 +02:00
return <span className={styles.icon}>🚨</span>
2022-10-18 16:27:41 +02:00
} else {
2022-10-18 20:14:49 +02:00
return <span className={styles.icon}>🚧</span>
2022-10-17 14:34:22 +02:00
}
2022-10-18 16:27:41 +02:00
}
2022-10-18 16:27:41 +02:00
function statusStyle(state: State) {
2022-10-20 10:32:03 +02:00
if (state === State.Outage) {
2022-10-20 11:00:36 +02:00
return styles.outage
2022-10-20 10:32:03 +02:00
} else if (state === State.Degraded) {
2022-10-20 11:00:36 +02:00
return styles.degraded
2022-10-18 16:27:41 +02:00
} else {
2022-10-20 11:00:36 +02:00
return styles.normal
}
2022-10-18 16:27:41 +02:00
}
2022-09-30 12:47:53 +02:00
2022-10-18 16:27:41 +02:00
export default function HomePage(): ReactElement {
2022-10-20 11:14:31 +02:00
const { data, error } = useSWR(statusApiUri, getData, {
refreshInterval: 60000
})
const isLoading = !data && !error
2022-09-29 16:25:10 +02:00
return (
2022-10-19 19:10:04 +02:00
<div className={styles.app}>
2022-09-29 16:25:10 +02:00
<Head>
<title>Ocean Protocol Status</title>
2022-10-19 17:40:44 +02:00
<meta
name="description"
content="Status overview of all deployed components hosted by the Ocean Protocol Foundation."
/>
2022-09-29 16:25:10 +02:00
<link rel="icon" href="/favicon.ico" />
</Head>
2022-10-18 16:45:01 +02:00
2022-10-19 19:10:04 +02:00
<header className={styles.header}>
2022-10-18 16:27:41 +02:00
<LogoAsset className={styles.logo} />
2022-10-18 21:52:14 +02:00
<h1 className={styles.title}>Ocean Protocol Status</h1>
<p className={styles.description}>
Status overview of all{' '}
<a href="https://docs.oceanprotocol.com/core-concepts/networks">
deployed components
</a>{' '}
hosted by the Ocean Protocol Foundation.
</p>
2022-10-18 16:45:01 +02:00
</header>
2022-10-18 16:27:41 +02:00
2022-10-19 19:10:04 +02:00
<main className={styles.content}>
2022-10-18 22:51:23 +02:00
{isLoading ? (
<div className={styles.loading}>Loading...</div>
2022-10-19 17:40:44 +02:00
) : error ? (
<div className={styles.loading}>{error}</div>
2022-10-18 22:51:23 +02:00
) : (
Object.entries(data || {}).map(([networkName, value]) => (
<Fragment key={networkName}>
2022-10-19 19:05:19 +02:00
<h2 className={styles.networkName}>
2022-10-19 19:17:15 +02:00
{networkName == 'general' ? null : (
<>
{networkName}
<span
className={styles.date}
title={`Last update: ${new Date(value.lastUpdatedOn)}`}
>
{relativeDate(new Date(value.lastUpdatedOn))}
</span>
</>
)}
2022-10-19 19:05:19 +02:00
</h2>
<div className={styles.grid}>
2022-10-19 17:40:44 +02:00
{value.components.map((component) => (
<div
key={component.name}
className={`${styles.card} ${statusStyle(
component.status
)}`}
>
<h2 className={styles.titleComponent}>
2022-10-19 21:20:09 +02:00
{statusIcon(component.status)}{' '}
<a
2022-10-20 10:00:12 +02:00
href={component.url}
2022-10-19 21:20:09 +02:00
title="Go to tested endpoint"
target="_blank"
rel="noreferrer"
>
{component.name}
</a>
2022-10-19 17:40:44 +02:00
<code className={styles.version} title="deployed version">
{component.version}
</code>
</h2>
2022-10-18 21:52:14 +02:00
2022-10-19 17:40:44 +02:00
{component.statusMessages?.length ? (
<ul className={styles.messages}>
{component.statusMessages.map(
(message: string, i: number) => (
<li key={i} className={styles.statusMessage}>
{message}
</li>
)
)}
</ul>
) : null}
2022-10-19 21:20:09 +02:00
<footer className={styles.links}>
{component.name !== 'data-farming' &&
component.name !== 'cexa' && (
<a
href={`https://github.com/oceanprotocol/${
component.name === 'subgraph' ? 'ocean-' : ''
2022-10-31 16:58:54 +01:00
}${
component.name === 'event-monitor'
? 'aquarius'
: component.name
}`}
2022-10-19 21:20:09 +02:00
target="_blank"
rel="noreferrer"
title="Go to GitHub repository"
>
<GithubAsset className={styles.icon} />
</a>
)}
</footer>
2022-10-19 17:40:44 +02:00
</div>
))}
</div>
2022-10-18 21:52:14 +02:00
2022-10-19 17:40:44 +02:00
{networkName !== 'general' && (
<details className={styles.contracts}>
<summary>
<h3 className={styles.titleComponent}>
Deployed Contracts
</h3>
</summary>
<ul>
{Object.entries((addresses as any)[networkName]).map(
2022-10-19 21:56:12 +02:00
([key, value]: [
key: string,
value: string | { [key: number]: string }
]) =>
2022-10-19 17:40:44 +02:00
key !== 'chainId' &&
key !== 'startBlock' && (
<li key={key}>
2022-10-19 21:56:12 +02:00
<code className={styles.key}>{key}</code>
<code>
{typeof value === 'string'
? value
: JSON.stringify(value, null, 2)}
</code>
2022-10-19 17:40:44 +02:00
</li>
)
)}
</ul>
</details>
)}
</Fragment>
))
2022-10-18 22:51:23 +02:00
)}
2022-09-29 16:25:10 +02:00
</main>
2022-09-30 12:16:56 +02:00
<footer className={styles.footer}></footer>
2022-09-29 16:25:10 +02:00
</div>
)
}