From 90f9f91ddbefb47b40c7e567125972b800d81972 Mon Sep 17 00:00:00 2001
From: Cafe137 <77121044+Cafe137@users.noreply.github.com>
Date: Thu, 19 Jan 2023 12:05:24 +0100
Subject: [PATCH] feat: add node connecting status (#603)
---
src/components/Card.tsx | 5 ++++-
src/components/SideBarStatus.tsx | 7 ++++---
src/components/StatusIcon.tsx | 5 ++++-
src/pages/info/NodeInfoCard.tsx | 12 ++++++++++++
src/providers/Bee.tsx | 30 ++++++++++++++++++++++++------
5 files changed, 48 insertions(+), 11 deletions(-)
diff --git a/src/components/Card.tsx b/src/components/Card.tsx
index 3ef502d..00687d4 100644
--- a/src/components/Card.tsx
+++ b/src/components/Card.tsx
@@ -2,6 +2,7 @@ import { createStyles, makeStyles, Theme, Typography } from '@material-ui/core'
import { ReactElement } from 'react'
import Check from 'remixicon-react/CheckLineIcon'
import AlertCircle from 'remixicon-react/ErrorWarningFillIcon'
+import Connecting from 'remixicon-react/LinksLineIcon'
import RefreshLine from 'remixicon-react/RefreshLineIcon'
import { SwarmButton, SwarmButtonProps } from './SwarmButton'
@@ -10,7 +11,7 @@ interface Props {
title: string
subtitle: string
buttonProps: SwarmButtonProps
- status: 'ok' | 'error' | 'loading'
+ status: 'ok' | 'error' | 'loading' | 'connecting'
}
const useStyles = (backgroundColor: string) =>
@@ -65,6 +66,8 @@ export default function Card({ buttonProps, icon, title, subtitle, status }: Pro
statusIcon =
} else if (status === 'loading') {
statusIcon =
+ } else if (status === 'connecting') {
+ statusIcon =
}
return (
diff --git a/src/components/SideBarStatus.tsx b/src/components/SideBarStatus.tsx
index bd8e98e..951bc65 100644
--- a/src/components/SideBarStatus.tsx
+++ b/src/components/SideBarStatus.tsx
@@ -1,9 +1,9 @@
import { ReactElement, useContext } from 'react'
-import { useLocation, matchPath } from 'react-router-dom'
+import { matchPath, useLocation } from 'react-router-dom'
import ArrowRight from 'remixicon-react/ArrowRightLineIcon'
-import { createStyles, Theme, makeStyles } from '@material-ui/core/styles'
-import { ListItemText, ListItemIcon, ListItem, Typography } from '@material-ui/core'
+import { ListItem, ListItemIcon, ListItemText, Typography } from '@material-ui/core'
+import { createStyles, makeStyles, Theme } from '@material-ui/core/styles'
import { Context } from '../providers/Bee'
import StatusIcon from './StatusIcon'
@@ -44,6 +44,7 @@ const useStyles = makeStyles((theme: Theme) =>
},
smallerText: {
fontSize: '0.9rem',
+ whiteSpace: 'nowrap',
},
}),
)
diff --git a/src/components/StatusIcon.tsx b/src/components/StatusIcon.tsx
index 3f5d6ed..810e6ac 100644
--- a/src/components/StatusIcon.tsx
+++ b/src/components/StatusIcon.tsx
@@ -1,5 +1,5 @@
-import type { ReactElement } from 'react'
import { CircularProgress } from '@material-ui/core'
+import type { ReactElement } from 'react'
import { CheckState } from '../providers/Bee'
interface Props {
@@ -28,6 +28,9 @@ export default function StatusIcon({ checkState, size, className, isLoading }: P
case CheckState.STARTING:
backgroundColor = 'orange'
break
+ case CheckState.CONNECTING:
+ backgroundColor = '#0074D9'
+ break
default:
// Default is error
backgroundColor = '#ff3a52'
diff --git a/src/pages/info/NodeInfoCard.tsx b/src/pages/info/NodeInfoCard.tsx
index a202fec..8db570a 100644
--- a/src/pages/info/NodeInfoCard.tsx
+++ b/src/pages/info/NodeInfoCard.tsx
@@ -12,6 +12,18 @@ export default function NodeInfoCard(): ReactElement {
const { status } = useContext(BeeContext)
const navigate = useNavigate()
+ if (status.all === CheckState.CONNECTING) {
+ return (
+ navigate(ROUTES.STATUS) }}
+ icon={}
+ title="Connecting..."
+ subtitle="Attempting to establish connection to your Bee node."
+ status="connecting"
+ />
+ )
+ }
+
if (status.all === CheckState.STARTING) {
return (
isEnabled && checkState === CheckState.ERROR,
+ )
+ const hasWarnings = Object.values(status).some(
+ ({ isEnabled, checkState }) => isEnabled && checkState === CheckState.WARNING,
+ )
+ const isInGracePeriod = Date.now() - startedAt < LAUNCH_GRACE_PERIOD
+
if (debugApiHealth?.status === 'ok' && !debugApiReadiness) {
return CheckState.STARTING
- } else if (Object.values(status).some(({ isEnabled, checkState }) => isEnabled && checkState === CheckState.ERROR)) {
+ } else if (hasErrors && isInGracePeriod) {
+ return CheckState.CONNECTING
+ } else if (hasErrors) {
return CheckState.ERROR
- } else if (
- Object.values(status).some(({ isEnabled, checkState }) => isEnabled && checkState === CheckState.WARNING)
- ) {
+ } else if (hasWarnings) {
return CheckState.WARNING
} else {
return CheckState.OK
@@ -214,6 +230,7 @@ export function Provider({ children, isDesktop }: Props): ReactElement {
const [settlements, setSettlements] = useState(null)
const [chainState, setChainState] = useState(null)
const [chainId, setChainId] = useState(null)
+ const [startedAt] = useState(Date.now())
const { latestBeeRelease } = useLatestBeeRelease()
@@ -408,6 +425,7 @@ export function Provider({ children, isDesktop }: Props): ReactElement {
chequebookBalance,
error,
Boolean(isDesktop),
+ startedAt,
)
useEffect(() => {