2023-05-22 19:53:40 +00:00
|
|
|
import { useMemo, useState } from 'react';
|
2023-05-25 09:37:13 +00:00
|
|
|
import { gt, prerelease } from 'semver';
|
2023-05-22 19:53:40 +00:00
|
|
|
import {
|
|
|
|
ReleasesFeed,
|
|
|
|
useEnvironment,
|
|
|
|
useReleases,
|
|
|
|
Networks,
|
|
|
|
} from '@vegaprotocol/environment';
|
|
|
|
import { t } from '@vegaprotocol/i18n';
|
|
|
|
import {
|
|
|
|
CopyWithTooltip,
|
|
|
|
ExternalLink,
|
|
|
|
Intent,
|
|
|
|
NotificationBanner,
|
|
|
|
VegaIcon,
|
|
|
|
VegaIconNames,
|
|
|
|
} from '@vegaprotocol/ui-toolkit';
|
|
|
|
|
2023-05-25 09:37:13 +00:00
|
|
|
// v0.20.12-core-0.71.4 -> v0.20.12
|
|
|
|
// we need to strip the "core" suffix in order to determine whether a release
|
|
|
|
// is a pre-release (candidate); example: v.0.21.0-beta.1-core-0.71.4
|
|
|
|
const parseTagName = (tagName: string) => tagName.replace(/-core-[\d.]+$/i, '');
|
2023-05-22 19:53:40 +00:00
|
|
|
|
|
|
|
type UpgradeBannerProps = {
|
|
|
|
showVersionChange: boolean;
|
|
|
|
};
|
|
|
|
export const UpgradeBanner = ({ showVersionChange }: UpgradeBannerProps) => {
|
|
|
|
const [visible, setVisible] = useState(true);
|
|
|
|
const { data } = useReleases(ReleasesFeed.FrontEnd);
|
2023-05-25 09:37:13 +00:00
|
|
|
const { APP_VERSION, VEGA_ENV, VEGA_NETWORKS } = useEnvironment();
|
2023-05-22 19:53:40 +00:00
|
|
|
|
2023-05-25 21:27:51 +00:00
|
|
|
const CANONICAL_URL = VEGA_NETWORKS[VEGA_ENV] || 'https://console.vega.xyz';
|
2023-05-22 21:10:06 +00:00
|
|
|
|
2023-05-25 09:37:13 +00:00
|
|
|
const newest = useMemo(() => {
|
|
|
|
if (!APP_VERSION || !data) return undefined;
|
|
|
|
const newer = data.filter((r) => gt(r.tagName, APP_VERSION));
|
|
|
|
const valid =
|
|
|
|
// filter pre-releases on mainnet
|
|
|
|
VEGA_ENV === Networks.MAINNET
|
|
|
|
? newer?.filter((r) => !prerelease(parseTagName(r.tagName)))
|
|
|
|
: newer;
|
|
|
|
return valid.sort((a, b) => (gt(a.tagName, b.tagName) ? -1 : 1))[0];
|
|
|
|
}, [APP_VERSION, VEGA_ENV, data]);
|
2023-05-22 19:53:40 +00:00
|
|
|
|
2023-05-25 09:37:13 +00:00
|
|
|
if (!visible || !newest) {
|
|
|
|
return null;
|
|
|
|
}
|
2023-05-22 19:53:40 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<NotificationBanner
|
|
|
|
intent={Intent.Warning}
|
|
|
|
onClose={() => {
|
|
|
|
setVisible(false);
|
|
|
|
}}
|
|
|
|
>
|
2023-05-25 09:37:13 +00:00
|
|
|
<div className="uppercase mb-1">
|
|
|
|
<ExternalLink href={CANONICAL_URL}>
|
|
|
|
{t('Upgrade to the latest version of Console')}
|
|
|
|
</ExternalLink>
|
2023-05-22 19:53:40 +00:00
|
|
|
</div>
|
|
|
|
<div data-testid="bookmark-message">
|
2023-05-25 09:37:13 +00:00
|
|
|
<a
|
|
|
|
className="underline"
|
|
|
|
href={newest.htmlUrl}
|
|
|
|
rel="noreferrer nofollow noopener"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
{t("View what's changed")}
|
|
|
|
</a>{' '}
|
|
|
|
{t(' or bookmark')}{' '}
|
|
|
|
<a className="underline" href={CANONICAL_URL}>
|
|
|
|
{t('vega.trading')}
|
|
|
|
</a>{' '}
|
2023-05-22 19:53:40 +00:00
|
|
|
<CopyWithTooltip text={CANONICAL_URL}>
|
2023-05-22 21:10:06 +00:00
|
|
|
<button title={t('Copy %s', CANONICAL_URL)}>
|
2023-05-22 19:53:40 +00:00
|
|
|
<span className="sr-only">{t('Copy %s', CANONICAL_URL)}</span>
|
|
|
|
<VegaIcon size={14} name={VegaIconNames.COPY} />
|
|
|
|
</button>
|
|
|
|
</CopyWithTooltip>{' '}
|
|
|
|
{'to always see the latest version.'}
|
|
|
|
</div>
|
|
|
|
</NotificationBanner>
|
|
|
|
);
|
|
|
|
};
|