2023-03-15 11:49:31 +00:00
|
|
|
import { useCallback } from 'react';
|
2023-02-16 03:52:54 +00:00
|
|
|
import { useEnvironment, useNodeHealth } from '@vegaprotocol/environment';
|
2023-02-28 18:56:29 +00:00
|
|
|
import { t } from '@vegaprotocol/i18n';
|
2023-03-15 11:49:31 +00:00
|
|
|
import type { Intent } from '@vegaprotocol/ui-toolkit';
|
2023-03-21 15:19:54 +00:00
|
|
|
import { Indicator, ExternalLink } from '@vegaprotocol/ui-toolkit';
|
2023-02-27 09:16:19 +00:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import type { ButtonHTMLAttributes, ReactNode } from 'react';
|
2023-02-16 03:52:54 +00:00
|
|
|
import { useGlobalStore } from '../../stores';
|
2022-11-08 00:53:43 +00:00
|
|
|
|
2022-08-31 04:35:46 +00:00
|
|
|
export const Footer = () => {
|
|
|
|
return (
|
2023-03-09 23:52:38 +00:00
|
|
|
<footer className="px-4 py-1 text-xs border-t border-default text-vega-light-300 dark:text-vega-dark-300 lg:fixed bottom-0 left-0 border-r bg-white dark:bg-black">
|
2023-02-27 09:16:19 +00:00
|
|
|
{/* Pull left to align with top nav, due to button padding */}
|
|
|
|
<div className="-ml-2">
|
2023-03-15 11:49:31 +00:00
|
|
|
<NodeHealth />
|
2022-08-31 04:35:46 +00:00
|
|
|
</div>
|
|
|
|
</footer>
|
|
|
|
);
|
|
|
|
};
|
2023-02-27 09:16:19 +00:00
|
|
|
|
2023-03-15 11:49:31 +00:00
|
|
|
export const NodeHealth = () => {
|
2023-03-21 15:19:54 +00:00
|
|
|
const { VEGA_URL, VEGA_INCIDENT_URL } = useEnvironment();
|
2023-03-15 11:49:31 +00:00
|
|
|
const setNodeSwitcher = useGlobalStore(
|
|
|
|
(store) => (open: boolean) => store.update({ nodeSwitcherDialog: open })
|
|
|
|
);
|
|
|
|
const { datanodeBlockHeight, text, intent } = useNodeHealth();
|
|
|
|
const onClick = useCallback(() => {
|
|
|
|
setNodeSwitcher(true);
|
|
|
|
}, [setNodeSwitcher]);
|
2023-03-21 15:19:54 +00:00
|
|
|
const incidentsLink = VEGA_INCIDENT_URL && (
|
|
|
|
<ExternalLink className="ml-1" href={VEGA_INCIDENT_URL}>
|
|
|
|
{t('Mainnet status & incidents')}
|
|
|
|
</ExternalLink>
|
|
|
|
);
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{VEGA_URL && (
|
|
|
|
<FooterButton onClick={onClick} data-testid="node-health">
|
|
|
|
<FooterButtonPart>
|
|
|
|
<HealthIndicator text={text} intent={intent} />
|
|
|
|
</FooterButtonPart>
|
|
|
|
<FooterButtonPart>
|
|
|
|
<NodeUrl url={VEGA_URL} />
|
|
|
|
</FooterButtonPart>
|
|
|
|
{/* create a monospace effect - avoiding jumps of width */}
|
|
|
|
<FooterButtonPart
|
|
|
|
width={`${
|
|
|
|
datanodeBlockHeight
|
|
|
|
? String(datanodeBlockHeight).length + 'ch'
|
|
|
|
: 'auto'
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<span title={t('Block height')}>{datanodeBlockHeight}</span>
|
|
|
|
</FooterButtonPart>
|
|
|
|
</FooterButton>
|
|
|
|
)}
|
|
|
|
{incidentsLink}
|
|
|
|
</>
|
|
|
|
);
|
2023-02-27 09:16:19 +00:00
|
|
|
};
|
2022-11-08 00:53:43 +00:00
|
|
|
|
2023-01-27 10:31:23 +00:00
|
|
|
interface NodeUrlProps {
|
|
|
|
url: string;
|
|
|
|
}
|
|
|
|
|
2023-02-27 09:16:19 +00:00
|
|
|
export const NodeUrl = ({ url }: 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-02-27 09:16:19 +00:00
|
|
|
return <span title={t('Connected node')}>{nodeUrl}</span>;
|
2023-01-27 10:31:23 +00:00
|
|
|
};
|
|
|
|
|
2023-02-27 09:16:19 +00:00
|
|
|
interface HealthIndicatorProps {
|
2023-03-15 11:49:31 +00:00
|
|
|
text: string;
|
|
|
|
intent: Intent;
|
2023-01-27 10:31:23 +00:00
|
|
|
}
|
|
|
|
|
2023-03-15 11:49:31 +00:00
|
|
|
export const HealthIndicator = ({ text, intent }: HealthIndicatorProps) => {
|
2022-11-08 00:53:43 +00:00
|
|
|
return (
|
2023-02-27 09:16:19 +00:00
|
|
|
<span title={t('Node health')}>
|
2023-01-27 10:31:23 +00:00
|
|
|
<Indicator variant={intent} />
|
2023-02-27 09:16:19 +00:00
|
|
|
{text}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
type FooterButtonProps = ButtonHTMLAttributes<HTMLButtonElement>;
|
|
|
|
|
|
|
|
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 <button {...props} className={buttonClasses} />;
|
|
|
|
};
|
|
|
|
|
2023-03-21 15:19:54 +00:00
|
|
|
const FooterButtonPart = ({
|
|
|
|
width = 'auto',
|
|
|
|
children,
|
|
|
|
}: {
|
|
|
|
children: ReactNode;
|
|
|
|
width?: string;
|
|
|
|
}) => {
|
2023-02-27 09:16:19 +00:00
|
|
|
return (
|
|
|
|
<span
|
2023-03-21 15:19:54 +00:00
|
|
|
style={{ width }}
|
2023-02-27 09:16:19 +00:00
|
|
|
className={classNames(
|
|
|
|
'relative inline-block mr-2 last:mr-0 pr-2 last:pr-0',
|
|
|
|
'last:after:hidden',
|
|
|
|
'after:content after:absolute after:right-0 after:top-1/2 after:-translate-y-1/2',
|
|
|
|
'after:h-3 after:w-1 after:border-r',
|
|
|
|
'after:border-vega-light-300 dark:after:border-vega-dark-300'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</span>
|
2022-11-08 00:53:43 +00:00
|
|
|
);
|
|
|
|
};
|