Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/providers/Bee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface Status {
interface ContextInterface {
beeVersion: string | null
status: Status
setStatus: (status: Status) => void
error: Error | null
apiHealth: boolean
nodeAddresses: NodeAddresses | null
Expand Down Expand Up @@ -75,6 +76,7 @@ const initialValues: ContextInterface = {
topology: { isEnabled: false, checkState: CheckState.ERROR },
chequebook: { isEnabled: false, checkState: CheckState.ERROR },
},
setStatus: () => {}, // eslint-disable-line
error: null,
apiHealth: false,
nodeAddresses: null,
Expand Down Expand Up @@ -184,6 +186,9 @@ export function Provider({ children }: Props): ReactElement {
const [walletBalance, setWalletBalance] = useState<WalletBalance | null>(null)
const [startedAt] = useState(Date.now())

// Make status stateful
const [status, setStatus] = useState<Status>(initialValues.status)

const { latestBeeRelease } = useLatestBeeRelease()

const [error, setError] = useState<Error | null>(initialValues.error)
Expand Down Expand Up @@ -333,7 +338,11 @@ export function Provider({ children }: Props): ReactElement {
}
const stop = () => setFrequency(null)

const status = getStatus(nodeInfo, apiHealth, topology, chequebookAddress, chequebookBalance, error, startedAt)
// Update status when dependent values change
useEffect(() => {
const newStatus = getStatus(nodeInfo, apiHealth, topology, chequebookAddress, chequebookBalance, error, startedAt)
setStatus(newStatus)
}, [nodeInfo, apiHealth, topology, chequebookAddress, chequebookBalance, error, startedAt])

useEffect(() => {
let newFrequency = REFRESH_WHEN_OK
Expand All @@ -358,6 +367,7 @@ export function Provider({ children }: Props): ReactElement {
value={{
beeVersion,
status,
setStatus,
error,
apiHealth,
nodeAddresses,
Expand Down
Loading