import { ReactElement, useEffect, useState } from 'react' import { makeStyles, Theme, createStyles } from '@material-ui/core/styles' import { Typography, Paper, Button, Step, StepLabel, StepContent, Stepper, StepButton } from '@material-ui/core/' import { CheckCircle, Error, Sync, ExpandLessSharp, ExpandMoreSharp, Autorenew } from '@material-ui/icons/' import DebugConnectionCheck from './SetupSteps/DebugConnectionCheck' import NodeConnectionCheck from './SetupSteps/NodeConnectionCheck' import VersionCheck from './SetupSteps/VersionCheck' import EthereumConnectionCheck from './SetupSteps/EthereumConnectionCheck' import ChequebookDeployFund from './SetupSteps/ChequebookDeployFund' import PeerConnection from './SetupSteps/PeerConnection' import { StatusChequebookHook } from '../../hooks/status' const useStyles = makeStyles((theme: Theme) => createStyles({ root: { padding: theme.spacing(2), width: '100%', }, button: { marginTop: theme.spacing(1), marginRight: theme.spacing(1), }, actionsContainer: { margin: theme.spacing(2), }, }), ) interface Step { label: string condition: boolean isLoading: boolean component: ReactElement } interface Props { nodeVersion: StatusNodeVersionHook ethereumConnection: StatusEthereumConnectionHook debugApiConnection: StatusHookCommon apiConnection: StatusHookCommon topology: StatusTopologyHook chequebook: StatusChequebookHook } export default function NodeSetupWorkflow({ nodeVersion, ethereumConnection, debugApiConnection, apiConnection, topology, chequebook, }: Props): ReactElement { const classes = useStyles() const [activeStep, setActiveStep] = useState(-1) const steps: Step[] = [ { label: 'Connected to Node DebugAPI', condition: debugApiConnection.isOk, isLoading: debugApiConnection.isLoading, component: , }, { label: 'Running latest Bee version', condition: nodeVersion.isOk, isLoading: nodeVersion.isLoading, component: , }, { label: 'Connected to Ethereum Blockchain', condition: ethereumConnection.isOk, isLoading: ethereumConnection.isLoading, component: , }, { label: 'Deployed and Funded Chequebook', condition: chequebook.isOk, isLoading: chequebook.isLoading, component: , }, { label: 'Connected to Node API', condition: apiConnection.isOk, isLoading: apiConnection.isLoading, component: , }, { label: 'Connected to Peers', condition: topology.isOk, isLoading: topology.isLoading, component: , }, ] useEffect(() => { // If the user already changed the active step we don't want to overwrite it if (activeStep > 0 && activeStep < steps.length) return // Select first step that is not OK for (let i = 0; i < steps.length; ++i) { if (!steps[i].condition) { setActiveStep(i) return } } }, [steps]) const handleNext = () => { setActiveStep(prevActiveStep => prevActiveStep + 1) } const handleBack = () => { setActiveStep(prevActiveStep => prevActiveStep - 1) } return ( Node Setup window.location.reload()}> Refresh Checks {steps.map(({ label, condition, component, isLoading }, index) => ( setActiveStep(index === activeStep ? steps.length : index)} StepIconComponent={() => { if (isLoading) return if (condition) return return }} > setActiveStep(index === activeStep ? steps.length : index)} style={{ justifyContent: 'space-between' }} > {label} {index === activeStep ? : } {component} Back {index < steps.length - 1 ? 'Next' : 'Finish'} ))} ) }