diff --git a/src/hooks/apiHooks.tsx b/src/hooks/apiHooks.tsx index b77d508..309004d 100644 --- a/src/hooks/apiHooks.tsx +++ b/src/hooks/apiHooks.tsx @@ -1,7 +1,7 @@ import { useState, useEffect } from "react"; 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'; @@ -27,13 +27,8 @@ export const useApiHealth = () => { return { health, isLoadingHealth, error } ; } -interface NodeHealth { - status: string, - version: string -} - export const useDebugApiHealth = () => { - const [nodeHealth, setNodeHealth] = useState(null) + const [nodeHealth, setNodeHealth] = useState(null) const [isLoadingNodeHealth, setLoading] = useState(false) const [error, setError] = useState(null) @@ -41,7 +36,7 @@ export const useDebugApiHealth = () => { setLoading(true) beeDebugApi.status.nodeHealth() .then(res => { - setNodeHealth(res.data) + setNodeHealth(res) }) .catch(error => { setError(error) @@ -54,33 +49,6 @@ export const useDebugApiHealth = () => { return { nodeHealth, isLoadingNodeHealth, error } ; } -interface NodeReadiness { - status: string, - version: string -} - -export const useApiReadiness = () => { - const [nodeReadiness, setNodeReadiness] = useState(null) - const [isLoadingNodeReadiness, setLoading] = useState(false) - const [error, setError] = useState(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 = () => { const [nodeAddresses, setNodeAddresses] = useState(null) const [isLoadingNodeAddresses, setLoading] = useState(false) diff --git a/src/pages/status/StatusCard.tsx b/src/pages/status/StatusCard.tsx index 1490a6e..fa3e2dd 100644 --- a/src/pages/status/StatusCard.tsx +++ b/src/pages/status/StatusCard.tsx @@ -5,6 +5,7 @@ import { Theme, createStyles, makeStyles } from '@material-ui/core/styles'; import { Card, CardContent, Typography, Chip, Button } from '@material-ui/core/'; import { CheckCircle, Error, ArrowRight, ArrowDropUp } from '@material-ui/icons/'; import { Skeleton } from '@material-ui/lab'; +import { Health } from '@ethersphere/bee-js'; const useStyles = makeStyles((theme: Theme) => createStyles({ @@ -25,18 +26,7 @@ const useStyles = makeStyles((theme: Theme) => backgroundColor: '#e1effe', } }), -); - - -interface NodeHealth { - status?: string, - version?: string -} - -interface NodeReadiness { - status?: string, - version?: string -} +); interface NodeAddresses { overlay: string, @@ -58,10 +48,8 @@ interface NodeTopology { interface IProps{ - nodeHealth: NodeHealth, + nodeHealth: Health, loadingNodeHealth: boolean, - nodeReadiness: NodeReadiness | null, - loadingNodeReadiness: boolean, beeRelease: any, loadingBeeRelease: boolean, nodeAddresses: NodeAddresses, @@ -108,8 +96,8 @@ function StatusCard(props: IProps) { AGENT: Bee - {props.nodeReadiness?.version ? ` v${props.nodeReadiness.version}` : '-'} - {props.beeRelease && props.beeRelease.name === `v${props.nodeReadiness?.version?.split('-')[0]}` ? + {props.nodeHealth?.version ? ` v${props.nodeHealth.version}` : '-'} + {props.beeRelease && props.beeRelease.name === `v${props.nodeHealth?.version?.split('-')[0]}` ? : - ( isLoadingNodeHealth || isLoadingHealth || isLoadingNodeReadiness || isLoadingChequebookAddress || + ( isLoadingNodeHealth || isLoadingHealth || isLoadingChequebookAddress || isLoadingNodeTopology || isLoadingBeeRelease || isLoadingNodeAddresses || isLoadingBeeRelease || isLoadingChequebookBalance ) ? @@ -111,10 +108,7 @@ export default function Status() { isLoadingBeeRelease={isLoadingBeeRelease} nodeHealth={nodeHealth} - isLoadingNodeHealth={isLoadingNodeHealth} - - nodeReadiness={nodeReadiness} - isLoadingNodeReadiness={isLoadingNodeReadiness} + isLoadingNodeHealth={isLoadingNodeHealth} nodeAddresses={nodeAddresses} isLoadingNodeAddresses={isLoadingNodeAddresses} diff --git a/src/services/bee.tsx b/src/services/bee.tsx index 4bc7156..83bbdc6 100644 --- a/src/services/bee.tsx +++ b/src/services/bee.tsx @@ -1,5 +1,5 @@ import axios, { AxiosInstance } from 'axios'; -import { Bee, Reference } from "@ethersphere/bee-js"; +import { Bee, BeeDebug, Reference } from "@ethersphere/bee-js"; const beeJSClient = () => { let apiHost = process.env.REACT_APP_BEE_HOST || 'http://localhost:1633' @@ -11,6 +11,16 @@ const beeJSClient = () => { 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 => { let debugApiHost = process.env.REACT_APP_BEE_DEBUG_HOST || 'http://localhost:1635' @@ -42,10 +52,7 @@ export const beeApi = { export const beeDebugApi = { status: { nodeHealth() { - return beeDebugApiClient().get(`/health`) - }, - nodeReadiness() { - return beeDebugApiClient().get(`/readiness`) + return beeJSDebugClient().getHealth() }, }, connectivity: {