mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
version number fixes
* add loading state * add error state * handle connection errors * backwards compatibility for all components * small spinner variant
This commit is contained in:
parent
89b04e93fd
commit
1b336e2e80
@ -29,6 +29,20 @@
|
|||||||
padding-top: $spacer / 4;
|
padding-top: $spacer / 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.small {
|
||||||
|
composes: spinner;
|
||||||
|
margin: 0;
|
||||||
|
display: inline-block;
|
||||||
|
|
||||||
|
&:before {
|
||||||
|
width: $font-size-small;
|
||||||
|
height: $font-size-small;
|
||||||
|
margin-top: -($font-size-small);
|
||||||
|
margin-left: -($font-size-small / 2);
|
||||||
|
border-width: .1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes spinner {
|
@keyframes spinner {
|
||||||
to {
|
to {
|
||||||
transform: rotate(360deg);
|
transform: rotate(360deg);
|
||||||
|
@ -1,15 +1,27 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import styles from './Spinner.module.scss'
|
import styles from './Spinner.module.scss'
|
||||||
|
|
||||||
const Spinner = ({ message }: { message?: string }) => (
|
const Spinner = ({
|
||||||
<div className={styles.spinner}>
|
message,
|
||||||
{message && (
|
small,
|
||||||
<div
|
className
|
||||||
className={styles.spinnerMessage}
|
}: {
|
||||||
dangerouslySetInnerHTML={{ __html: message }}
|
message?: string
|
||||||
/>
|
small?: boolean
|
||||||
)}
|
className?: string
|
||||||
</div>
|
}) => {
|
||||||
)
|
const classes = className || (small ? styles.small : styles.spinner)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={classes}>
|
||||||
|
{message && (
|
||||||
|
<div
|
||||||
|
className={styles.spinnerMessage}
|
||||||
|
dangerouslySetInnerHTML={{ __html: message }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default Spinner
|
export default Spinner
|
||||||
|
@ -52,3 +52,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
composes: spinner, small from '../Spinner.module.scss';
|
||||||
|
margin-right: $spacer;
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@ import React, { Fragment } from 'react'
|
|||||||
import { VersionNumbersState as VersionTableProps } from '.'
|
import { VersionNumbersState as VersionTableProps } from '.'
|
||||||
import styles from './VersionTable.module.scss'
|
import styles from './VersionTable.module.scss'
|
||||||
import slugify from '@sindresorhus/slugify'
|
import slugify from '@sindresorhus/slugify'
|
||||||
|
import Spinner from '../Spinner'
|
||||||
|
|
||||||
const VersionTableContracts = ({
|
const VersionTableContracts = ({
|
||||||
contracts,
|
contracts,
|
||||||
@ -12,23 +13,24 @@ const VersionTableContracts = ({
|
|||||||
}) => (
|
}) => (
|
||||||
<table>
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
{Object.keys(contracts).map(key => (
|
{contracts &&
|
||||||
<tr key={key}>
|
Object.keys(contracts).map(key => (
|
||||||
<td>
|
<tr key={key}>
|
||||||
<span className={styles.label}>{key}</span>
|
<td>
|
||||||
</td>
|
<span className={styles.label}>{key}</span>
|
||||||
<td>
|
</td>
|
||||||
<a
|
<td>
|
||||||
href={`https://submarine${network === 'duero' &&
|
<a
|
||||||
'.duero'}.dev-ocean.com/address/${
|
href={`https://submarine${network === 'duero' &&
|
||||||
contracts[key]
|
'.duero'}.dev-ocean.com/address/${
|
||||||
}`}
|
contracts[key]
|
||||||
>
|
}`}
|
||||||
<code>{contracts[key]}</code>
|
>
|
||||||
</a>
|
<code>{contracts[key]}</code>
|
||||||
</td>
|
</a>
|
||||||
</tr>
|
</td>
|
||||||
))}
|
</tr>
|
||||||
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
)
|
)
|
||||||
@ -42,18 +44,30 @@ const VersionTable = ({ data }: { data: VersionTableProps }) => (
|
|||||||
<tr key={key}>
|
<tr key={key}>
|
||||||
<td>
|
<td>
|
||||||
<a
|
<a
|
||||||
href={`https://github.com/oceanprotocol/${slugify(
|
href={
|
||||||
value.software
|
value.software &&
|
||||||
)}`}
|
`https://github.com/oceanprotocol/${slugify(
|
||||||
|
value.software
|
||||||
|
)}`
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<strong>{value.software}</strong>
|
<strong>{value.software}</strong>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<code>v{value.version}</code>
|
{value.isLoading ? (
|
||||||
|
<Spinner small className={styles.spinner} />
|
||||||
|
) : value.version ? (
|
||||||
|
<>
|
||||||
|
<code>v{value.version}</code>
|
||||||
|
{value.network && `(${value.network})`}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
'Could not get version'
|
||||||
|
)}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{key === 'keeperContracts' && (
|
{key === 'keeperContracts' && data.brizo.contracts && (
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan={2}>
|
<td colSpan={2}>
|
||||||
<VersionTableContracts
|
<VersionTableContracts
|
||||||
|
@ -36,10 +36,12 @@ export interface VersionNumbersState {
|
|||||||
version: string
|
version: string
|
||||||
}
|
}
|
||||||
aquarius: {
|
aquarius: {
|
||||||
|
isLoading: boolean
|
||||||
software: string
|
software: string
|
||||||
version: string
|
version: string
|
||||||
}
|
}
|
||||||
brizo: {
|
brizo: {
|
||||||
|
isLoading: boolean
|
||||||
software: string
|
software: string
|
||||||
version: string
|
version: string
|
||||||
network: string
|
network: string
|
||||||
@ -48,13 +50,16 @@ export interface VersionNumbersState {
|
|||||||
contracts: any
|
contracts: any
|
||||||
}
|
}
|
||||||
keeperContracts: {
|
keeperContracts: {
|
||||||
|
isLoading: boolean
|
||||||
software: string
|
software: string
|
||||||
version: string
|
version: string
|
||||||
|
network: string
|
||||||
contracts: any
|
contracts: any
|
||||||
}
|
}
|
||||||
faucet: {
|
faucet: {
|
||||||
software: string
|
isLoading: boolean
|
||||||
version: string
|
software?: string
|
||||||
|
version?: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,73 +73,121 @@ export default class VersionNumbers extends PureComponent<
|
|||||||
software: 'Squid-js',
|
software: 'Squid-js',
|
||||||
version: versionSquid
|
version: versionSquid
|
||||||
},
|
},
|
||||||
aquarius: { software: 'Aquarius', version: '0.0.0' },
|
aquarius: {
|
||||||
|
isLoading: true,
|
||||||
|
software: 'Aquarius',
|
||||||
|
version: ''
|
||||||
|
},
|
||||||
brizo: {
|
brizo: {
|
||||||
|
isLoading: true,
|
||||||
software: 'Brizo',
|
software: 'Brizo',
|
||||||
version: '0.0.0',
|
version: '',
|
||||||
contracts: {} as any,
|
contracts: {} as any,
|
||||||
network: '',
|
network: '',
|
||||||
'keeper-version': '0.0.0',
|
'keeper-version': '0.0.0',
|
||||||
'keeper-url': ''
|
'keeper-url': ''
|
||||||
},
|
},
|
||||||
keeperContracts: {
|
keeperContracts: {
|
||||||
|
isLoading: true,
|
||||||
software: 'Keeper Contracts',
|
software: 'Keeper Contracts',
|
||||||
version: '0.0.0',
|
version: '',
|
||||||
contracts: {} as any,
|
contracts: {} as any,
|
||||||
network: ''
|
network: ''
|
||||||
},
|
},
|
||||||
faucet: { software: 'Faucet', version: '0.0.0' }
|
faucet: {
|
||||||
|
isLoading: true,
|
||||||
|
software: 'Faucet',
|
||||||
|
version: ''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for canceling axios requests
|
// for canceling axios requests
|
||||||
public signal = axios.CancelToken.source()
|
public signal = axios.CancelToken.source()
|
||||||
|
|
||||||
public componentWillMount() {
|
public componentWillMount() {
|
||||||
this.setComponentVersions()
|
this.setAquarius()
|
||||||
|
this.setBrizoAndKeeper()
|
||||||
|
this.setFaucet()
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
this.signal.cancel()
|
this.signal.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setComponentVersions() {
|
private async setAquarius() {
|
||||||
try {
|
const aquarius = await this.getData(
|
||||||
const aquarius = await this.getData(
|
aquariusScheme,
|
||||||
aquariusScheme,
|
aquariusHost,
|
||||||
aquariusHost,
|
aquariusPort
|
||||||
aquariusPort
|
)
|
||||||
)
|
aquarius.version !== undefined &&
|
||||||
aquarius.version !== undefined && this.setState({ aquarius })
|
this.setState({ aquarius: { isLoading: false, ...aquarius } })
|
||||||
|
}
|
||||||
|
|
||||||
const brizo = await this.getData(brizoScheme, brizoHost, brizoPort)
|
private async setBrizoAndKeeper() {
|
||||||
brizo.version !== undefined &&
|
const brizo = await this.getData(brizoScheme, brizoHost, brizoPort)
|
||||||
this.setState({
|
|
||||||
brizo,
|
|
||||||
keeperContracts: {
|
|
||||||
...this.state.keeperContracts,
|
|
||||||
version: brizo['keeper-version'].replace('v', ''),
|
|
||||||
contracts: brizo.contracts
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const faucet = await this.getData(
|
const keeperVersion =
|
||||||
faucetScheme,
|
brizo['keeper-version'] && brizo['keeper-version'].replace('v', '')
|
||||||
faucetHost,
|
const keeperNetwork =
|
||||||
faucetPort
|
brizo['keeper-url'] &&
|
||||||
)
|
new URL(brizo['keeper-url']).hostname.split('.')[0]
|
||||||
|
|
||||||
faucet.version !== undefined && this.setState({ faucet })
|
brizo.version !== undefined &&
|
||||||
} catch (error) {
|
this.setState({
|
||||||
!axios.isCancel(error) && Logger.error(error.message)
|
brizo: {
|
||||||
|
isLoading: false,
|
||||||
|
...brizo
|
||||||
|
},
|
||||||
|
keeperContracts: {
|
||||||
|
...this.state.keeperContracts,
|
||||||
|
isLoading: false,
|
||||||
|
version: keeperVersion,
|
||||||
|
contracts: brizo.contracts,
|
||||||
|
network: keeperNetwork
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private async setFaucet() {
|
||||||
|
const faucet = await this.getData(faucetScheme, faucetHost, faucetPort)
|
||||||
|
|
||||||
|
// backwards compatibility
|
||||||
|
function IsJsonString(str: string) {
|
||||||
|
try {
|
||||||
|
JSON.parse(str)
|
||||||
|
} catch (e) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IsJsonString(faucet) === false &&
|
||||||
|
this.setState({
|
||||||
|
faucet: { ...this.state.faucet, isLoading: false }
|
||||||
|
})
|
||||||
|
|
||||||
|
// the new thing
|
||||||
|
faucet.version !== undefined &&
|
||||||
|
this.setState({ faucet: { isLoading: false, ...faucet } })
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getData(scheme: string, host: string, port: number | string) {
|
private async getData(scheme: string, host: string, port: number | string) {
|
||||||
const { data } = await axios.get(`${scheme}://${host}:${port}`, {
|
try {
|
||||||
headers: { Accept: 'application/json' },
|
const response = await axios.get(`${scheme}://${host}:${port}`, {
|
||||||
cancelToken: this.signal.token
|
headers: { Accept: 'application/json' },
|
||||||
})
|
cancelToken: this.signal.token
|
||||||
return data
|
})
|
||||||
|
|
||||||
|
if (response.status !== 200) {
|
||||||
|
Logger.error(response.statusText)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.data
|
||||||
|
} catch (error) {
|
||||||
|
!axios.isCancel(error) && Logger.error(error.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
@ -152,7 +205,7 @@ export default class VersionNumbers extends PureComponent<
|
|||||||
return minimal ? (
|
return minimal ? (
|
||||||
<p className={styles.versionsMinimal}>
|
<p className={styles.versionsMinimal}>
|
||||||
<a title={mimimalOutput} href={'/about'}>
|
<a title={mimimalOutput} href={'/about'}>
|
||||||
v{commons.version} ({brizo.network})
|
v{commons.version} {brizo.network && `(${brizo.network})`}
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "brizo",
|
"name": "brizo",
|
||||||
"version": "~0.3.6"
|
"version": "~0.3.9"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "aquarius",
|
"name": "aquarius",
|
||||||
@ -23,7 +23,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "faucet",
|
"name": "faucet",
|
||||||
"version": "~0.2.0"
|
"version": "~0.2.4"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user