feat: optional status checks (e.g. connected peers > 0 or funded chequebook) (#331)

* feat: make some check optional (e.g. connected peers > 0 or funded chequebook)

* fix: alter setup step text to better describe what needs to be done

* refactor: rename isOk from boolean value to checkState enum

* fix: add checking for any error
This commit is contained in:
Vojtech Simetka
2022-04-13 18:09:30 +05:00
committed by GitHub
parent cd332c4dfd
commit 5d0fbf705d
16 changed files with 190 additions and 124 deletions
@@ -1,41 +1,59 @@
import { useContext } from 'react'
import DepositModal from '../../../containers/DepositModal'
import type { ReactElement } from 'react'
import type { ReactElement, ReactNode } from 'react'
import ExpandableList from '../../../components/ExpandableList'
import ExpandableListItemKey from '../../../components/ExpandableListItemKey'
import ExpandableListItemActions from '../../../components/ExpandableListItemActions'
import ExpandableListItemNote from '../../../components/ExpandableListItemNote'
import StatusIcon from '../../../components/StatusIcon'
import { Context } from '../../../providers/Bee'
import { CheckState, Context } from '../../../providers/Bee'
const ChequebookDeployFund = (): ReactElement | null => {
const { status, isLoading, chequebookAddress } = useContext(Context)
const { isOk, isEnabled } = status.chequebook
const { checkState, isEnabled } = status.chequebook
if (!isEnabled) return null
let text: ReactNode
switch (checkState) {
case CheckState.OK:
text = 'Your chequebook is deployed and funded'
break
case CheckState.WARNING:
text = (
<>
Your chequebook is not funded. Please deposit some xBZZ to your chequebook address. You may need to aquire BZZ
(e.g. <a href="https://bzz.exchange/">bzz.exchange</a>) and bridge it to the xDai network through the{' '}
<a href="https://omni.xdaichain.com/bridge">omni bridge</a>. To pay the transaction fees, you will also need
xDAI token. You can purchase DAI on the network and bridge it to xDai network through the{' '}
<a href="https://bridge.xdaichain.com/">xDai Bridge</a>. See the{' '}
<a href="https://www.xdaichain.com/#xdai-stable-chain">official xDai website</a> for more information.
</>
)
break
default:
text = (
<>
Your chequebook is either not deployed nor funded. To run the node you will need xDAI and xBZZ on the xDai
network. You may need to aquire BZZ (e.g. <a href="https://bzz.exchange/">bzz.exchange</a>) and bridge it to
the xDai network through the <a href="https://omni.xdaichain.com/bridge">omni bridge</a>. To pay the
transaction fees, you will also need xDAI token. You can purchase DAI on the network and bridge it to xDai
network through the <a href="https://bridge.xdaichain.com/">xDai Bridge</a>. See the{' '}
<a href="https://www.xdaichain.com/#xdai-stable-chain">official xDai website</a> for more information.
</>
)
}
return (
<ExpandableList
label={
<>
<StatusIcon isOk={isOk} isLoading={isLoading} /> Chequebook Deployment & Funding
<StatusIcon checkState={checkState} isLoading={isLoading} /> Chequebook Deployment & Funding
</>
}
>
<ExpandableListItemNote>
{isOk ? (
'Your chequebook is deployed and funded'
) : (
<>
Your chequebook is either not deployed or funded. To run the node you will need xDAI and xBZZ on the xDai
network. You may need to aquire BZZ (e.g. <a href="https://bzz.exchange/">bzz.exchange</a>) and bridge it to
the xDai network through the <a href="https://omni.xdaichain.com/bridge">omni bridge</a>. To pay the
transaction fees, you will also need xDAI token. You can purchase DAI on the network and bridge it to xDai
network through the <a href="https://bridge.xdaichain.com/">xDai Bridge</a>. See the{' '}
<a href="https://www.xdaichain.com/#xdai-stable-chain">official xDai website</a> for more information.
</>
)}
</ExpandableListItemNote>
<ExpandableListItemNote>{text}</ExpandableListItemNote>
{chequebookAddress && (
<>
<ExpandableListItemKey label="Chequebook Address" value={chequebookAddress.chequebookAddress} />
@@ -6,13 +6,13 @@ import ExpandableListItem from '../../../components/ExpandableListItem'
import ExpandableListItemInput from '../../../components/ExpandableListItemInput'
import ExpandableListItemNote from '../../../components/ExpandableListItemNote'
import StatusIcon from '../../../components/StatusIcon'
import { Context } from '../../../providers/Bee'
import { CheckState, Context } from '../../../providers/Bee'
import { Context as SettingsContext } from '../../../providers/Settings'
export default function NodeConnectionCheck(): ReactElement | null {
const { status, isLoading } = useContext(Context)
const { setDebugApiUrl, apiDebugUrl } = useContext(SettingsContext)
const { isOk, isEnabled } = status.debugApiConnection
const { checkState, isEnabled } = status.debugApiConnection
if (!isEnabled) return null
@@ -20,18 +20,18 @@ export default function NodeConnectionCheck(): ReactElement | null {
<ExpandableList
label={
<>
<StatusIcon isOk={isOk} isLoading={isLoading} /> Connection to Bee Debug API
<StatusIcon checkState={checkState} isLoading={isLoading} /> Connection to Bee Debug API
</>
}
>
<ExpandableListItemNote>
{isOk
{checkState === CheckState.OK
? 'The connection to the Bee nodes debug API has been successful'
: 'We cannot connect to your nodes debug API. Please check the following to troubleshoot your issue.'}
</ExpandableListItemNote>
<ExpandableListItemInput label="Bee Debug API" value={apiDebugUrl} onConfirm={setDebugApiUrl} />
{!isOk && (
{checkState === CheckState.ERROR && (
<ExpandableList level={1} label="Troubleshoot">
<ExpandableListItem
label={
@@ -3,11 +3,11 @@ import ExpandableList from '../../../components/ExpandableList'
import ExpandableListItemKey from '../../../components/ExpandableListItemKey'
import ExpandableListItemNote from '../../../components/ExpandableListItemNote'
import StatusIcon from '../../../components/StatusIcon'
import { Context } from '../../../providers/Bee'
import { CheckState, Context } from '../../../providers/Bee'
export default function EthereumConnectionCheck(): ReactElement | null {
const { status, isLoading, nodeAddresses } = useContext(Context)
const { isOk, isEnabled } = status.blockchainConnection
const { checkState, isEnabled } = status.blockchainConnection
if (!isEnabled) return null
@@ -15,12 +15,12 @@ export default function EthereumConnectionCheck(): ReactElement | null {
<ExpandableList
label={
<>
<StatusIcon isOk={isOk} isLoading={isLoading} /> Connection to Blockchain
<StatusIcon checkState={checkState} isLoading={isLoading} /> Connection to Blockchain
</>
}
>
<ExpandableListItemNote>
{isOk ? (
{checkState === CheckState.OK ? (
'Your node is connected to the xDai blockchain'
) : (
<>
@@ -7,12 +7,12 @@ import ExpandableListItem from '../../../components/ExpandableListItem'
import ExpandableListItemNote from '../../../components/ExpandableListItemNote'
import ExpandableListItemInput from '../../../components/ExpandableListItemInput'
import StatusIcon from '../../../components/StatusIcon'
import { Context } from '../../../providers/Bee'
import { CheckState, Context } from '../../../providers/Bee'
export default function NodeConnectionCheck(): ReactElement | null {
const { setApiUrl, apiUrl } = useContext(SettingsContext)
const { status, isLoading } = useContext(Context)
const { isEnabled, isOk } = status.apiConnection
const { isEnabled, checkState } = status.apiConnection
if (!isEnabled) return null
@@ -20,17 +20,17 @@ export default function NodeConnectionCheck(): ReactElement | null {
<ExpandableList
label={
<>
<StatusIcon isOk={isOk} isLoading={isLoading} /> Connection to Bee API
<StatusIcon checkState={checkState} isLoading={isLoading} /> Connection to Bee API
</>
}
>
<ExpandableListItemNote>
{isOk
{checkState === CheckState.OK
? 'The connection to the Bee nodes API has been successful'
: 'Could not connect to your Bee nodes API. Please check the troubleshoot below on how you may resolve it.'}
</ExpandableListItemNote>
<ExpandableListItemInput label="Bee API" value={apiUrl} onConfirm={setApiUrl} />
{!isOk && (
{checkState === CheckState.ERROR && (
<ExpandableList level={1} label="Troubleshoot">
<ExpandableListItem
label={
+17 -9
View File
@@ -1,29 +1,37 @@
import { ReactElement, useContext } from 'react'
import { ReactElement, ReactNode, useContext } from 'react'
import ExpandableList from '../../../components/ExpandableList'
import ExpandableListItemNote from '../../../components/ExpandableListItemNote'
import TopologyStats from '../../../components/TopologyStats'
import StatusIcon from '../../../components/StatusIcon'
import { Context } from '../../../providers/Bee'
import { CheckState, Context } from '../../../providers/Bee'
export default function PeerConnection(): ReactElement | null {
const { status, isLoading, topology } = useContext(Context)
const { isEnabled, isOk } = status.topology
const { isEnabled, checkState } = status.topology
if (!isEnabled) return null
let text: ReactNode
switch (checkState) {
case CheckState.OK:
text = 'You are connected to other Bee nodes'
break
// Both error state and warning state
default:
text =
'Your node is not connected to any peers. Please wait a bit if you just started the node, otherwise review your configuration file.'
}
return (
<ExpandableList
label={
<>
<StatusIcon isOk={isOk} isLoading={isLoading} /> Connection to Peers
<StatusIcon checkState={checkState} isLoading={isLoading} /> Connection to Peers
</>
}
>
<ExpandableListItemNote>
{isOk
? 'You are connected to other Bee nodes'
: 'Your node is not connected to any peers. Please wait a bit if you just started the node, otherwise review your configuration file.'}
</ExpandableListItemNote>
<ExpandableListItemNote>{text}</ExpandableListItemNote>
<TopologyStats topology={topology} />
</ExpandableList>
+4 -4
View File
@@ -4,11 +4,11 @@ import ExpandableList from '../../../components/ExpandableList'
import ExpandableListItem from '../../../components/ExpandableListItem'
import ExpandableListItemNote from '../../../components/ExpandableListItemNote'
import StatusIcon from '../../../components/StatusIcon'
import { Context } from '../../../providers/Bee'
import { CheckState, Context } from '../../../providers/Bee'
export default function VersionCheck(): ReactElement | null {
const { status, isLoading, latestUserVersion, latestPublishedVersion, latestBeeVersionUrl } = useContext(Context)
const { isEnabled, isOk } = status.version
const { isEnabled, checkState } = status.version
if (!isEnabled) return null
@@ -16,12 +16,12 @@ export default function VersionCheck(): ReactElement | null {
<ExpandableList
label={
<>
<StatusIcon isOk={isOk} isLoading={isLoading} /> Bee Version
<StatusIcon checkState={checkState} isLoading={isLoading} /> Bee Version
</>
}
>
<ExpandableListItemNote>
{isOk ? (
{checkState === CheckState.OK ? (
'You are running the latest version of Bee.'
) : (
<>