status-frontend/src/pages/index.tsx

147 lines
4.9 KiB
TypeScript
Raw Normal View History

2022-09-29 16:25:10 +02:00
import Head from 'next/head'
2022-10-18 16:45:01 +02:00
import React, { Fragment, ReactElement, useEffect, useState } from 'react'
2022-10-18 19:17:32 +02:00
import { State, Status } 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-18 21:52:14 +02:00
import addresses from '@oceanprotocol/contracts/addresses/address.json'
2022-09-30 12:47:53 +02:00
function statusIcon(state: State): ReactElement {
2022-10-18 16:27:41 +02:00
if (state === State.Up) {
2022-10-18 20:14:49 +02:00
return <CheckAsset className={`${styles.icon} ${styles.check}`} />
2022-10-18 16:27:41 +02:00
} else if (state === State.Down) {
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) {
if (state === State.Down) {
return styles.down
} else if (state === State.Warning) {
return styles.warning
} else {
return styles.up
}
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-18 19:17:32 +02:00
const [data, setData] = useState<{ [key: string]: Status }>()
2022-09-30 12:47:53 +02:00
useEffect(() => {
async function getStatuses() {
2022-10-18 19:17:32 +02:00
const data = await getData()
setData(data)
2022-09-30 12:47:53 +02:00
}
getStatuses()
}, [])
2022-09-29 16:25:10 +02:00
return (
<div className={styles.container}>
<Head>
<title>Ocean Protocol Status</title>
2022-09-29 16:25:10 +02:00
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
2022-10-18 16:45:01 +02:00
<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-18 16:45:01 +02:00
<main>
2022-10-18 21:52:14 +02:00
{Object.entries(data || {}).map(([key, value]) => {
const networkKey = key
return (
<Fragment key={networkKey}>
<h2 className={styles.networkName}>{networkKey}</h2>
<div className={styles.grid}>
{Object.entries(value)
.filter(
// TODO: Remove this filter if we fix this on API level
// Needs a new `components` key under Status response
([key]) =>
key !== 'currentBlock' &&
key !== 'lastUpdatedOn' &&
key !== 'network' &&
key !== '_id' &&
key !== '__v'
)
.map(([key, value]) => (
<div
key={key}
className={`${styles.card} ${statusStyle(
// TODO: all component states should be of type Status on API level
2022-10-18 19:17:32 +02:00
key === 'market' || key === 'dataFarming'
? value
: value.status
2022-10-18 21:52:14 +02:00
)}`}
>
<h2 className={styles.titleComponent}>
{statusIcon(
key === 'market' || key === 'dataFarming'
? value
: value.status
)}{' '}
{key}
<code
className={styles.version}
title="deployed version"
>
{value.version}
</code>
</h2>
{value.statusMessages && value.statusMessages !== '' && (
<ul className={styles.messages}>
{value.statusMessages
.split(',')
.map((message: string, i: number) => (
<li key={i} className={styles.statusMessage}>
{message}
</li>
))}
</ul>
)}
</div>
))}
</div>
2022-10-18 19:58:05 +02:00
2022-10-18 21:52:14 +02:00
<details className={styles.contracts}>
<summary>
<h3 className={styles.titleComponent}>Deployed Contracts</h3>
</summary>
<ul>
{Object.entries((addresses as any)[networkKey]).map(
([key, value]) =>
key !== 'chainId' &&
key !== 'startBlock' && (
<li key={key}>
<code className={styles.key}>{key}</code>:{' '}
<code>{JSON.stringify(value)}</code>
</li>
)
)}
</ul>
</details>
</Fragment>
)
})}
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>
)
}