From 8f1bcaf91e4715a8d2bb6e63302b5c3b69f60a81 Mon Sep 17 00:00:00 2001 From: Ethan Tuttle Date: Thu, 10 Aug 2023 23:16:31 -0400 Subject: [PATCH] feat: dashboard accurately display on/offline peers Checks consensus numbers for offline peers, surfacing it to the user/Guardian. --- .../src/components/AdminHeader.tsx | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/apps/guardian-ui/src/components/AdminHeader.tsx b/apps/guardian-ui/src/components/AdminHeader.tsx index 86696f3ec..aa11810fa 100644 --- a/apps/guardian-ui/src/components/AdminHeader.tsx +++ b/apps/guardian-ui/src/components/AdminHeader.tsx @@ -1,6 +1,6 @@ -import React, { FC } from 'react'; +import React, { FC, useEffect, useState } from 'react'; import { CopyInput } from '@fedimint/ui'; -import { useSetupContext } from '../hooks'; +import { useAppContext, useSetupContext } from '../hooks'; import { Flex, Box, Text, Icon } from '@chakra-ui/react'; import { ReactComponent as CopyIcon } from '../assets/svgs/copy.svg'; @@ -9,6 +9,7 @@ interface PillProp { status: string; } +// Have to update pull color based on quorum. export const Pill: FC = ({ text, status }) => { return ( @@ -40,10 +41,23 @@ interface AdminHeaderProps { connectionCode: string; } -export const AdminHeader: FC = ({ connectionCode }) => { +export function AdminHeader({ connectionCode }: AdminHeaderProps) { + const [guardians, setGuardians] = useState(); const { state: { configGenParams }, } = useSetupContext(); + const { api } = useAppContext(); + // will have to do polling + useEffect(() => { + async function getStatus() { + const { consensus } = await api.status(); + const online = consensus ? consensus.peers_online + 1 : 1; + const offline = consensus ? consensus.peers_offline : 1; + const totalPeers = online + offline; + setGuardians(`${online} / ${totalPeers}`); + } + getStatus(); + }, [api]); return ( @@ -61,7 +75,7 @@ export const AdminHeader: FC = ({ connectionCode }) => { bitcoin standard - + @@ -80,4 +94,4 @@ export const AdminHeader: FC = ({ connectionCode }) => { ); -}; +}