import Head from 'next/head'
import React, { Fragment, ReactElement } from 'react'
import { State } from '../@types'
import styles from '../styles/Home.module.css'
import { getData } from '../utils/getData'
import LogoAsset from '../images/logo.svg'
import CheckAsset from '../images/check.svg'
import GithubAsset from '../images/github.svg'
import addresses from '@oceanprotocol/contracts/addresses/address.json'
import { statusApiUri } from '../../app.config'
import relativeDate from 'tiny-relative-date'
import useSWR from 'swr'
function statusIcon(state: State): ReactElement {
if (state === State.Normal) {
return
} else if (state === State.Outage) {
return 🚨
} else {
return 🚧
}
}
function statusStyle(state: State) {
if (state === State.Outage) {
return styles.outage
} else if (state === State.Degraded) {
return styles.degraded
} else {
return styles.normal
}
}
export default function HomePage(): ReactElement {
const { data, error } = useSWR(statusApiUri, getData, {
refreshInterval: 60000
})
const isLoading = !data && !error
return (
Ocean Protocol Status
{isLoading ? (
Loading...
) : error ? (
{error}
) : (
Object.entries(data || {}).map(([networkName, value]) => (
{networkName == 'general' ? null : (
<>
{networkName}
{relativeDate(new Date(value.lastUpdatedOn))}
>
)}
{value.components.map((component) => (
{statusIcon(component.status)}{' '}
{component.name}
{component.version}
{component.statusMessages?.length ? (
{component.statusMessages.map(
(message: string, i: number) => (
-
{message}
)
)}
) : null}
))}
{networkName !== 'general' && (
Deployed Contracts
{Object.entries((addresses as any)[networkName]).map(
([key, value]: [
key: string,
value: string | { [key: number]: string }
]) =>
key !== 'chainId' &&
key !== 'startBlock' && (
-
{key}
{typeof value === 'string'
? value
: JSON.stringify(value, null, 2)}
)
)}
)}
))
)}
)
}