Skip to content

Commit

Permalink
feat: dashboard accurately display on/offline peers
Browse files Browse the repository at this point in the history
Checks consensus numbers for offline peers, surfacing it to the user/Guardian.
  • Loading branch information
EthnTuttle committed Aug 11, 2023
1 parent 406f394 commit 8f1bcaf
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions apps/guardian-ui/src/components/AdminHeader.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -9,6 +9,7 @@ interface PillProp {
status: string;
}

// Have to update pull color based on quorum.
export const Pill: FC<PillProp> = ({ text, status }) => {
return (
<Flex gap='8px' alignItems='center'>
Expand Down Expand Up @@ -40,10 +41,23 @@ interface AdminHeaderProps {
connectionCode: string;
}

export const AdminHeader: FC<AdminHeaderProps> = ({ connectionCode }) => {
export function AdminHeader({ connectionCode }: AdminHeaderProps) {
const [guardians, setGuardians] = useState<string | undefined>();
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 (
<Flex>
<Box>
Expand All @@ -61,7 +75,7 @@ export const AdminHeader: FC<AdminHeaderProps> = ({ connectionCode }) => {
bitcoin standard
</Text>
<Flex gap='12px' mt='13px'>
<Pill text='Guardians' status='Online' />
<Pill text='Guardians' status={`${guardians}`} />
<Pill text='Server' status='Healthy' />
<Pill text='Uptime' status='100%' />
</Flex>
Expand All @@ -80,4 +94,4 @@ export const AdminHeader: FC<AdminHeaderProps> = ({ connectionCode }) => {
</Box>
</Flex>
);
};
}

0 comments on commit 8f1bcaf

Please sign in to comment.