import { useEnvironment, useNodeHealth } from '@vegaprotocol/environment'; import { useNavigatorOnline } from '@vegaprotocol/react-helpers'; import { t } from '@vegaprotocol/i18n'; import { Indicator, Intent } from '@vegaprotocol/ui-toolkit'; import classNames from 'classnames'; import type { ButtonHTMLAttributes, ReactNode } from 'react'; import { useGlobalStore } from '../../stores'; export const Footer = () => { const { VEGA_URL } = useEnvironment(); const setNodeSwitcher = useGlobalStore( (store) => (open: boolean) => store.update({ nodeSwitcherDialog: open }) ); const { blockDiff, datanodeBlockHeight } = useNodeHealth(); return ( ); }; interface NodeHealthProps { url: string; blockHeight: number | undefined; blockDiff: number | null; onClick: () => void; } export const NodeHealth = ({ url, blockHeight, blockDiff, onClick, }: NodeHealthProps) => { return ( {blockHeight} ); }; interface NodeUrlProps { url: string; } export const NodeUrl = ({ url }: NodeUrlProps) => { // get base url from api url, api sub domain const urlObj = new URL(url); const nodeUrl = urlObj.origin.replace(/^[^.]+\./g, ''); return {nodeUrl}; }; interface HealthIndicatorProps { blockDiff: number | null; } // How many blocks behind the most advanced block that is // deemed acceptable for "Good" status const BLOCK_THRESHOLD = 3; export const HealthIndicator = ({ blockDiff }: HealthIndicatorProps) => { const online = useNavigatorOnline(); let intent = Intent.Success; let text = 'Operational'; if (!online) { text = t('Offline'); intent = Intent.Danger; } else if (blockDiff === null) { // Block height query failed and null was returned text = t('Non operational'); intent = Intent.Danger; } else if (blockDiff >= BLOCK_THRESHOLD) { text = t(`${blockDiff} Blocks behind`); intent = Intent.Warning; } return ( {text} ); }; type FooterButtonProps = ButtonHTMLAttributes; const FooterButton = (props: FooterButtonProps) => { const buttonClasses = classNames( 'px-2 py-0.5 rounded-md', 'enabled:hover:bg-vega-light-150', 'dark:enabled:hover:bg-vega-dark-150' ); return