refactor: debug api health to use bee-js and removed node readiness (#41)

This commit is contained in:
Vojtech Simetka
2021-04-02 15:20:51 +02:00
committed by GitHub
parent decdd87bb7
commit c88027cc38
4 changed files with 24 additions and 67 deletions
+3 -35
View File
@@ -1,7 +1,7 @@
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import type { NodeAddresses, ChequebookAddressResponse, ChequebookBalanceResponse, BalanceResponse, import type { NodeAddresses, ChequebookAddressResponse, ChequebookBalanceResponse, BalanceResponse,
LastChequesResponse, AllSettlements, LastCashoutActionResponse } from '@ethersphere/bee-js' LastChequesResponse, AllSettlements, LastCashoutActionResponse, Health } from '@ethersphere/bee-js'
import { beeDebugApi, beeApi } from '../services/bee'; import { beeDebugApi, beeApi } from '../services/bee';
@@ -27,13 +27,8 @@ export const useApiHealth = () => {
return { health, isLoadingHealth, error } ; return { health, isLoadingHealth, error } ;
} }
interface NodeHealth {
status: string,
version: string
}
export const useDebugApiHealth = () => { export const useDebugApiHealth = () => {
const [nodeHealth, setNodeHealth] = useState<NodeHealth | null>(null) const [nodeHealth, setNodeHealth] = useState<Health | null>(null)
const [isLoadingNodeHealth, setLoading] = useState<boolean>(false) const [isLoadingNodeHealth, setLoading] = useState<boolean>(false)
const [error, setError] = useState<Error | null>(null) const [error, setError] = useState<Error | null>(null)
@@ -41,7 +36,7 @@ export const useDebugApiHealth = () => {
setLoading(true) setLoading(true)
beeDebugApi.status.nodeHealth() beeDebugApi.status.nodeHealth()
.then(res => { .then(res => {
setNodeHealth(res.data) setNodeHealth(res)
}) })
.catch(error => { .catch(error => {
setError(error) setError(error)
@@ -54,33 +49,6 @@ export const useDebugApiHealth = () => {
return { nodeHealth, isLoadingNodeHealth, error } ; return { nodeHealth, isLoadingNodeHealth, error } ;
} }
interface NodeReadiness {
status: string,
version: string
}
export const useApiReadiness = () => {
const [nodeReadiness, setNodeReadiness] = useState<NodeReadiness | null>(null)
const [isLoadingNodeReadiness, setLoading] = useState<boolean>(false)
const [error, setError] = useState<Error | null>(null)
useEffect(() => {
setLoading(true)
beeDebugApi.status.nodeReadiness()
.then(res => {
setNodeReadiness(res.data)
})
.catch(error => {
setError(error)
})
.finally(() => {
setLoading(false)
})
}, [])
return { nodeReadiness, isLoadingNodeReadiness, error } ;
}
export const useApiNodeAddresses = () => { export const useApiNodeAddresses = () => {
const [nodeAddresses, setNodeAddresses] = useState<NodeAddresses | null>(null) const [nodeAddresses, setNodeAddresses] = useState<NodeAddresses | null>(null)
const [isLoadingNodeAddresses, setLoading] = useState<boolean>(false) const [isLoadingNodeAddresses, setLoading] = useState<boolean>(false)
+4 -16
View File
@@ -5,6 +5,7 @@ import { Theme, createStyles, makeStyles } from '@material-ui/core/styles';
import { Card, CardContent, Typography, Chip, Button } from '@material-ui/core/'; import { Card, CardContent, Typography, Chip, Button } from '@material-ui/core/';
import { CheckCircle, Error, ArrowRight, ArrowDropUp } from '@material-ui/icons/'; import { CheckCircle, Error, ArrowRight, ArrowDropUp } from '@material-ui/icons/';
import { Skeleton } from '@material-ui/lab'; import { Skeleton } from '@material-ui/lab';
import { Health } from '@ethersphere/bee-js';
const useStyles = makeStyles((theme: Theme) => const useStyles = makeStyles((theme: Theme) =>
createStyles({ createStyles({
@@ -27,17 +28,6 @@ const useStyles = makeStyles((theme: Theme) =>
}), }),
); );
interface NodeHealth {
status?: string,
version?: string
}
interface NodeReadiness {
status?: string,
version?: string
}
interface NodeAddresses { interface NodeAddresses {
overlay: string, overlay: string,
underlay: string[], underlay: string[],
@@ -58,10 +48,8 @@ interface NodeTopology {
interface IProps{ interface IProps{
nodeHealth: NodeHealth, nodeHealth: Health,
loadingNodeHealth: boolean, loadingNodeHealth: boolean,
nodeReadiness: NodeReadiness | null,
loadingNodeReadiness: boolean,
beeRelease: any, beeRelease: any,
loadingBeeRelease: boolean, loadingBeeRelease: boolean,
nodeAddresses: NodeAddresses, nodeAddresses: NodeAddresses,
@@ -108,8 +96,8 @@ function StatusCard(props: IProps) {
<Typography component="div" variant="subtitle2" gutterBottom> <Typography component="div" variant="subtitle2" gutterBottom>
<span>AGENT: </span> <span>AGENT: </span>
<a href='https://github.com/ethersphere/bee' rel='noreferrer' target='_blank'>Bee</a> <a href='https://github.com/ethersphere/bee' rel='noreferrer' target='_blank'>Bee</a>
<span>{props.nodeReadiness?.version ? ` v${props.nodeReadiness.version}` : '-'}</span> <span>{props.nodeHealth?.version ? ` v${props.nodeHealth.version}` : '-'}</span>
{props.beeRelease && props.beeRelease.name === `v${props.nodeReadiness?.version?.split('-')[0]}` ? {props.beeRelease && props.beeRelease.name === `v${props.nodeHealth?.version?.split('-')[0]}` ?
<Chip <Chip
style={{ marginLeft: '7px', color: '#2145a0' }} style={{ marginLeft: '7px', color: '#2145a0' }}
size="small" size="small"
+2 -8
View File
@@ -5,7 +5,7 @@ import { Container, CircularProgress } from '@material-ui/core';
import NodeSetupWorkflow from './NodeSetupWorkflow'; import NodeSetupWorkflow from './NodeSetupWorkflow';
import StatusCard from './StatusCard'; import StatusCard from './StatusCard';
import EthereumAddressCard from '../../components/EthereumAddressCard'; import EthereumAddressCard from '../../components/EthereumAddressCard';
import { useApiHealth, useDebugApiHealth, useApiReadiness, useApiNodeAddresses, useApiChequebookAddress, useApiNodeTopology, useApiChequebookBalance } from '../../hooks/apiHooks'; import { useApiHealth, useDebugApiHealth, useApiNodeAddresses, useApiChequebookAddress, useApiNodeTopology, useApiChequebookBalance } from '../../hooks/apiHooks';
export default function Status() { export default function Status() {
const [beeRelease, setBeeRelease] = useState({ name: ''}); const [beeRelease, setBeeRelease] = useState({ name: ''});
@@ -18,7 +18,6 @@ export default function Status() {
const { health, isLoadingHealth } = useApiHealth() const { health, isLoadingHealth } = useApiHealth()
const { nodeHealth, isLoadingNodeHealth } = useDebugApiHealth() const { nodeHealth, isLoadingNodeHealth } = useDebugApiHealth()
const { nodeReadiness, isLoadingNodeReadiness } = useApiReadiness()
const { nodeAddresses, isLoadingNodeAddresses } = useApiNodeAddresses() const { nodeAddresses, isLoadingNodeAddresses } = useApiNodeAddresses()
const { chequebookAddress, isLoadingChequebookAddress } = useApiChequebookAddress() const { chequebookAddress, isLoadingChequebookAddress } = useApiChequebookAddress()
const { nodeTopology, isLoadingNodeTopology } = useApiNodeTopology() const { nodeTopology, isLoadingNodeTopology } = useApiNodeTopology()
@@ -81,8 +80,6 @@ export default function Status() {
<StatusCard <StatusCard
nodeHealth={nodeHealth} nodeHealth={nodeHealth}
loadingNodeHealth={isLoadingNodeHealth} loadingNodeHealth={isLoadingNodeHealth}
nodeReadiness={nodeReadiness}
loadingNodeReadiness={isLoadingNodeReadiness}
beeRelease={beeRelease} beeRelease={beeRelease}
loadingBeeRelease={isLoadingBeeRelease} loadingBeeRelease={isLoadingBeeRelease}
nodeAddresses={nodeAddresses} nodeAddresses={nodeAddresses}
@@ -98,7 +95,7 @@ export default function Status() {
/> />
</div> </div>
: :
( isLoadingNodeHealth || isLoadingHealth || isLoadingNodeReadiness || isLoadingChequebookAddress || ( isLoadingNodeHealth || isLoadingHealth || isLoadingChequebookAddress ||
isLoadingNodeTopology || isLoadingBeeRelease || isLoadingNodeAddresses || isLoadingBeeRelease || isLoadingChequebookBalance isLoadingNodeTopology || isLoadingBeeRelease || isLoadingNodeAddresses || isLoadingBeeRelease || isLoadingChequebookBalance
) )
? ?
@@ -113,9 +110,6 @@ export default function Status() {
nodeHealth={nodeHealth} nodeHealth={nodeHealth}
isLoadingNodeHealth={isLoadingNodeHealth} isLoadingNodeHealth={isLoadingNodeHealth}
nodeReadiness={nodeReadiness}
isLoadingNodeReadiness={isLoadingNodeReadiness}
nodeAddresses={nodeAddresses} nodeAddresses={nodeAddresses}
isLoadingNodeAddresses={isLoadingNodeAddresses} isLoadingNodeAddresses={isLoadingNodeAddresses}
+12 -5
View File
@@ -1,5 +1,5 @@
import axios, { AxiosInstance } from 'axios'; import axios, { AxiosInstance } from 'axios';
import { Bee, Reference } from "@ethersphere/bee-js"; import { Bee, BeeDebug, Reference } from "@ethersphere/bee-js";
const beeJSClient = () => { const beeJSClient = () => {
let apiHost = process.env.REACT_APP_BEE_HOST || 'http://localhost:1633' let apiHost = process.env.REACT_APP_BEE_HOST || 'http://localhost:1633'
@@ -11,6 +11,16 @@ const beeJSClient = () => {
return new Bee(apiHost) return new Bee(apiHost)
} }
const beeJSDebugClient = () => {
let debugApiHost = process.env.REACT_APP_BEE_DEBUG_HOST || 'http://localhost:1635'
if (sessionStorage.getItem('debug_api_host')) {
debugApiHost = String(sessionStorage.getItem('debug_api_host'))
}
return new BeeDebug(debugApiHost)
}
const beeDebugApiClient = (): AxiosInstance => { const beeDebugApiClient = (): AxiosInstance => {
let debugApiHost = process.env.REACT_APP_BEE_DEBUG_HOST || 'http://localhost:1635' let debugApiHost = process.env.REACT_APP_BEE_DEBUG_HOST || 'http://localhost:1635'
@@ -42,10 +52,7 @@ export const beeApi = {
export const beeDebugApi = { export const beeDebugApi = {
status: { status: {
nodeHealth() { nodeHealth() {
return beeDebugApiClient().get(`/health`) return beeJSDebugClient().getHealth()
},
nodeReadiness() {
return beeDebugApiClient().get(`/readiness`)
}, },
}, },
connectivity: { connectivity: {