2022-11-08 00:53:43 +00:00
|
|
|
import { useEnvironment } from '@vegaprotocol/environment';
|
2023-01-27 10:31:23 +00:00
|
|
|
import { t, useNavigatorOnline } from '@vegaprotocol/react-helpers';
|
|
|
|
import { ButtonLink, Indicator, Intent } from '@vegaprotocol/ui-toolkit';
|
2022-11-08 00:53:43 +00:00
|
|
|
|
2022-08-31 04:35:46 +00:00
|
|
|
export const Footer = () => {
|
2023-01-27 10:31:23 +00:00
|
|
|
const { VEGA_URL, blockDifference, setNodeSwitcherOpen } = useEnvironment();
|
2022-08-31 04:35:46 +00:00
|
|
|
return (
|
2022-11-08 00:53:43 +00:00
|
|
|
<footer className="px-4 py-1 text-xs border-t border-default">
|
2022-08-31 04:35:46 +00:00
|
|
|
<div className="flex justify-between">
|
2022-11-08 00:53:43 +00:00
|
|
|
<div className="flex gap-2">
|
2023-01-27 10:31:23 +00:00
|
|
|
{VEGA_URL && (
|
|
|
|
<>
|
|
|
|
<NodeHealth
|
|
|
|
blockDiff={blockDifference}
|
|
|
|
openNodeSwitcher={setNodeSwitcherOpen}
|
|
|
|
/>
|
|
|
|
{' | '}
|
|
|
|
<NodeUrl url={VEGA_URL} openNodeSwitcher={setNodeSwitcherOpen} />
|
|
|
|
</>
|
|
|
|
)}
|
2022-11-08 00:53:43 +00:00
|
|
|
</div>
|
2022-08-31 04:35:46 +00:00
|
|
|
</div>
|
|
|
|
</footer>
|
|
|
|
);
|
|
|
|
};
|
2022-11-08 00:53:43 +00:00
|
|
|
|
2023-01-27 10:31:23 +00:00
|
|
|
interface NodeUrlProps {
|
|
|
|
url: string;
|
|
|
|
openNodeSwitcher: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NodeUrl = ({ url, openNodeSwitcher }: NodeUrlProps) => {
|
2022-11-08 00:53:43 +00:00
|
|
|
// get base url from api url, api sub domain
|
|
|
|
const urlObj = new URL(url);
|
|
|
|
const nodeUrl = urlObj.origin.replace(/^[^.]+\./g, '');
|
2023-01-27 10:31:23 +00:00
|
|
|
return <ButtonLink onClick={openNodeSwitcher}>{nodeUrl}</ButtonLink>;
|
|
|
|
};
|
|
|
|
|
|
|
|
interface NodeHealthProps {
|
|
|
|
openNodeSwitcher: () => void;
|
|
|
|
blockDiff: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
// How many blocks behind the most advanced block that is
|
|
|
|
// deemed acceptable for "Good" status
|
|
|
|
const BLOCK_THRESHOLD = 3;
|
|
|
|
|
|
|
|
export const NodeHealth = ({
|
|
|
|
blockDiff,
|
|
|
|
openNodeSwitcher,
|
|
|
|
}: NodeHealthProps) => {
|
|
|
|
const online = useNavigatorOnline();
|
|
|
|
|
|
|
|
let intent = Intent.Success;
|
|
|
|
let text = 'Operational';
|
|
|
|
|
|
|
|
if (!online) {
|
|
|
|
text = t('Offline');
|
|
|
|
intent = Intent.Danger;
|
|
|
|
} else if (blockDiff < 0) {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2022-11-08 00:53:43 +00:00
|
|
|
return (
|
2023-01-27 10:31:23 +00:00
|
|
|
<span>
|
|
|
|
<Indicator variant={intent} />
|
|
|
|
<ButtonLink onClick={openNodeSwitcher}>{text}</ButtonLink>
|
|
|
|
</span>
|
2022-11-08 00:53:43 +00:00
|
|
|
);
|
|
|
|
};
|