import { useMemo } from "react"; import { Box, Paper, Grid, Typography, LinearProgress, useTheme } from "@mui/material" import Metric from "../../components/Metric/Metric"; import Countdown from "../../components/Countdown/Countdown"; import InfoTooltip from "../../components/Tooltip/InfoTooltip"; import { formatNumber } from "../../helpers"; export const BridgeHeader = ({ totalValidators, disabledValidators, bridgeStability, transactionEta, timeToNextEpoch, isSmallScreen }) => { const theme = useTheme(); const disabledPercentage = useMemo(() => { if (totalValidators === undefined || disabledValidators === undefined) { return 0; } return ((totalValidators - disabledValidators) / totalValidators) * 100; }, [totalValidators, disabledValidators]); const validatorsColor = useMemo(() => { if (disabledPercentage < 50) { return theme.colors.validatorsColor.red; } return theme.colors.validatorsColor.green; }, [disabledPercentage, theme]); const stabilityColor = useMemo(() => { if (bridgeStability > 80) { return theme.colors.bridgeProgress.success; } else if (bridgeStability > 50) { return theme.colors.bridgeProgress.warning; } else { return theme.colors.bridgeProgress.error; } }, [bridgeStability, theme]); const progressBarPostfix = useMemo(() => { if (bridgeStability > 90) { return "✅ Safe"; } else if (bridgeStability > 80) { return "✅ Moderate Risk"; } else if (bridgeStability > 70) { return "⚠️ High Risk"; } else if (bridgeStability > 50) { return "⚠️ Critical Risk"; } else { return "❌ Do NOT Bridge"; } }, [bridgeStability]); const formatTime = (totalSeconds) => { const hours = Math.floor(totalSeconds / 3600); const minutes = Math.floor((totalSeconds % 3600) / 60); const secs = Math.floor(totalSeconds % 60); if (hours > 0) { return `${hours} hours ${minutes} mins`; } else if (minutes > 0) { return `${minutes} mins`; } else { return `${secs} secs`; } } return ( {totalValidators} ({formatNumber(disabledPercentage, 0)}% active) } label="Total Validators" tooltip="Active and disabled GHOST Validators in the current GHOST Epoch." /> 14400 ? "∞" : formatTime(transactionEta)} label="Max Bridge ETA" tooltip="Maximum estimated time for finalizing bridge transactions based on the latest update." /> Bridge Stability {bridgeStability ? `${formatNumber(bridgeStability, 0)}% ${progressBarPostfix}` : "N/A" } 0% - 50%: ❌ Do NOT Bridge 50% - 70%: ⚠️ Critical Risk 70% - 80%: ⚠️ High Risk 80% - 90%: ✅ Moderate Risk 90% - 100%: ✅ Safe } /> ) }