1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

switch to using squid-js for version numbers

This commit is contained in:
Matthias Kretschmann 2019-06-17 20:31:14 +02:00
parent c063ad82cb
commit c4f862baa5
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 81 additions and 146 deletions

View File

@ -1,14 +1,16 @@
import React, { Fragment } from 'react'
import { VersionNumbersState as VersionTableProps } from '.'
import { OceanPlatformTechStatus } from '@oceanprotocol/squid'
import { VersionNumbersState } from '.'
import styles from './VersionTable.module.scss'
import slugify from '@sindresorhus/slugify'
import Spinner from '../../atoms/Spinner'
const VersionTableContracts = ({
contracts,
network
}: {
contracts: any
contracts: {
[contractName: string]: string
}
network: string
}) => (
<table>
@ -41,23 +43,21 @@ const VersionTableContracts = ({
)
const VersionNumber = ({
isLoading,
software,
name,
version,
network
network,
status
}: {
isLoading: boolean
software: string
version: string
network: string
name: string
version?: string
network?: string
status: OceanPlatformTechStatus
}) =>
isLoading ? (
<Spinner small className={styles.spinner} />
) : version ? (
version ? (
<>
<a
href={`https://github.com/oceanprotocol/${slugify(
software
name
)}/releases/tag/v${version}`}
>
<code>v{version}</code>
@ -65,47 +65,47 @@ const VersionNumber = ({
{network && `(${network})`}
</>
) : (
<span>Could not get version</span>
<span>{status || 'Could not get version'}</span>
)
const VersionTable = ({ data }: { data: VersionTableProps }) => (
const VersionTable = ({ data }: { data: VersionNumbersState }) => (
<div className={styles.tableWrap}>
<table className={styles.table}>
<tbody>
{Object.entries(data).map(([key, value]) => (
<Fragment key={key}>
<tr key={key}>
<tr>
<td>
<a
href={
value.software &&
value.name &&
`https://github.com/oceanprotocol/${slugify(
value.software
value.name
)}`
}
>
<strong>{value.software}</strong>
<strong>{value.name}</strong>
</a>
</td>
<td>
<VersionNumber
isLoading={value.isLoading}
software={value.software}
name={value.name}
version={value.version}
network={value.network}
status={value.status}
// network={value.network}
/>
</td>
</tr>
{key === 'keeperContracts' && data.brizo.contracts && (
{/* {value.contracts && (
<tr>
<td colSpan={2}>
<VersionTableContracts
contracts={data.brizo.contracts}
network={data.brizo.network}
contracts={value.contracts}
network={value.network || ''}
/>
</td>
</tr>
)}
)} */}
</Fragment>
))}
</tbody>

View File

@ -1,14 +1,17 @@
import React, { PureComponent } from 'react'
import { Logger } from '@oceanprotocol/squid'
import {
OceanPlatformVersions,
OceanPlatformTechStatus,
Logger
} from '@oceanprotocol/squid'
import axios from 'axios'
import { version } from '../../../../package.json'
import { version as versionSquid } from '@oceanprotocol/squid/package.json'
import styles from './index.module.scss'
import { aquariusUri, brizoUri, faucetUri } from '../../../config'
import { faucetUri } from '../../../config'
import { User } from '../../../context'
import VersionTable from './VersionTable'
import { isJsonString } from './utils'
export const commonsVersion =
process.env.NODE_ENV === 'production' ? version : `${version}-dev`
@ -17,40 +20,15 @@ interface VersionNumbersProps {
minimal?: boolean
}
export interface VersionNumbersState {
export interface VersionNumbersState extends OceanPlatformVersions {
commons: {
software: string
name: string
version: string
}
squidJs: {
software: string
version: string
}
aquarius: {
isLoading: boolean
software: string
version: string
}
brizo: {
isLoading: boolean
software: string
version: string
network: string
'keeper-version': string
'keeper-url': string
contracts: any
}
keeperContracts: {
isLoading: boolean
software: string
version: string
network: string
contracts: any
}
faucet: {
isLoading: boolean
software?: string
version?: string
name: string
version: string
status: OceanPlatformTechStatus
}
}
@ -58,99 +36,60 @@ export default class VersionNumbers extends PureComponent<
VersionNumbersProps,
VersionNumbersState
> {
public state = {
commons: { software: 'Commons', version: commonsVersion },
squidJs: {
software: 'Squid-js',
version: versionSquid
},
aquarius: {
isLoading: true,
software: 'Aquarius',
version: ''
},
brizo: {
isLoading: true,
software: 'Brizo',
version: '',
contracts: {} as any,
network: '',
'keeper-version': '0.0.0',
'keeper-url': ''
},
keeperContracts: {
isLoading: true,
software: 'Keeper Contracts',
version: '',
contracts: {} as any,
network: ''
public static contextType = User
public state: VersionNumbersState = {
commons: {
name: 'Commons',
version: commonsVersion
},
faucet: {
isLoading: true,
software: 'Faucet',
version: ''
name: 'Faucet',
version: '',
status: OceanPlatformTechStatus.Loading
},
squid: {
name: 'Squid-js',
status: OceanPlatformTechStatus.Loading
},
aquarius: {
name: 'Aquarius',
status: OceanPlatformTechStatus.Loading
},
brizo: {
name: 'Brizo',
status: OceanPlatformTechStatus.Loading
}
}
// for canceling axios requests
public signal = axios.CancelToken.source()
public componentWillMount() {
this.setAquarius()
this.setBrizoAndKeeper()
this.setFaucet()
public componentDidMount() {
this.getOceanVersions()
}
public componentWillUnmount() {
this.signal.cancel()
}
private async setAquarius() {
const aquarius = await this.getData(aquariusUri)
aquarius &&
aquarius.version !== undefined &&
this.setState({ aquarius: { isLoading: false, ...aquarius } })
}
private async getOceanVersions() {
const { ocean } = this.context
const { versions } = ocean
const componentVersions = versions && (await versions.get())
const { squid, brizo, aquarius } = componentVersions
console.log(componentVersions)
private async setBrizoAndKeeper() {
const brizo = await this.getData(brizoUri)
// const faucet = await this.getData(faucetUri)
const keeperVersion =
brizo['keeper-version'] && brizo['keeper-version'].replace('v', '')
const keeperNetwork =
brizo['keeper-url'] &&
new URL(brizo['keeper-url']).hostname.split('.')[0]
brizo &&
brizo.version !== undefined &&
this.setState({
brizo: {
isLoading: false,
...brizo
},
keeperContracts: {
...this.state.keeperContracts,
isLoading: false,
version: keeperVersion,
contracts: brizo.contracts,
network: keeperNetwork
}
commons: { ...this.state.commons },
squid,
brizo,
aquarius
// faucet
})
}
private async setFaucet() {
const faucet = await this.getData(faucetUri)
// backwards compatibility
isJsonString(faucet) === false &&
this.setState({
faucet: { ...this.state.faucet, isLoading: false }
})
// the new thing
faucet &&
faucet.version !== undefined &&
this.setState({ faucet: { isLoading: false, ...faucet } })
console.log(this.state)
}
private async getData(uri: string) {
@ -171,15 +110,11 @@ export default class VersionNumbers extends PureComponent<
public render() {
const { minimal } = this.props
const { commons, squidJs, brizo, aquarius, faucet } = this.state
const { commons, squid, brizo, aquarius } = this.state
const mimimalOutput = `${squidJs.software} v${squidJs.version} \n${
brizo.software
} v${brizo.version} \n${aquarius.software} v${
aquarius.version
} \nKeeper Contracts ${brizo['keeper-version']} \n${faucet.software} v${
faucet.version
}`
const mimimalOutput = `${squid.name} v${squid.version}\n${
brizo.name
} v${brizo.version}\n${aquarius.name} v${aquarius.version}`
return minimal ? (
<p className={styles.versionsMinimal}>