2023-08-02 15:34:04 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { useNavigate } from 'react-router-dom';
|
|
|
|
import { Dialog, Intent } from '@vegaprotocol/ui-toolkit';
|
2023-02-28 18:56:29 +00:00
|
|
|
import { t } from '@vegaprotocol/i18n';
|
2023-05-08 01:01:07 +00:00
|
|
|
import { useLocalStorage } from '@vegaprotocol/react-helpers';
|
2023-08-02 15:34:04 +00:00
|
|
|
import { useEnvironment } from '@vegaprotocol/environment';
|
|
|
|
import { isBrowserWalletInstalled } from '@vegaprotocol/wallet';
|
2022-12-13 13:31:28 +00:00
|
|
|
import * as constants from '../constants';
|
2023-08-02 15:34:04 +00:00
|
|
|
import { WelcomeDialogContent } from './welcome-dialog-content';
|
|
|
|
import { getConfig } from '@vegaprotocol/wallet';
|
|
|
|
import { Links, Routes } from '../../pages/client-router';
|
2023-01-02 16:01:06 +00:00
|
|
|
import { useGlobalStore } from '../../stores';
|
2022-12-13 13:31:28 +00:00
|
|
|
|
|
|
|
export const WelcomeDialog = () => {
|
2023-05-02 21:01:33 +00:00
|
|
|
const { VEGA_ENV } = useEnvironment();
|
2023-08-02 15:34:04 +00:00
|
|
|
const [onBoardingViewed, setOnboardingViewed] = useLocalStorage(
|
|
|
|
constants.ONBOARDING_VIEWED_KEY
|
2023-04-26 15:17:23 +00:00
|
|
|
);
|
2023-08-02 15:34:04 +00:00
|
|
|
const navigate = useNavigate();
|
|
|
|
const isOnboardingDialogNeeded =
|
|
|
|
onBoardingViewed !== 'true' && !isBrowserWalletInstalled() && !getConfig();
|
|
|
|
const marketId = useGlobalStore((store) => store.marketId);
|
2023-05-19 21:27:45 +00:00
|
|
|
|
2023-08-02 15:34:04 +00:00
|
|
|
const onClose = () => {
|
|
|
|
setOnboardingViewed('true');
|
|
|
|
const link = marketId
|
|
|
|
? Links[Routes.MARKET](marketId)
|
|
|
|
: Links[Routes.HOME]();
|
|
|
|
navigate(link);
|
|
|
|
};
|
|
|
|
const title = (
|
|
|
|
<span className="font-alpha calt" data-testid="welcome-title">
|
|
|
|
{t('Console')}{' '}
|
|
|
|
<span className="text-vega-clight-100 dark:text-vega-cdark-100">
|
|
|
|
{VEGA_ENV}
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
);
|
2023-01-02 16:01:06 +00:00
|
|
|
|
2023-08-02 15:34:04 +00:00
|
|
|
return isOnboardingDialogNeeded ? (
|
2022-12-13 13:31:28 +00:00
|
|
|
<Dialog
|
2023-08-02 15:34:04 +00:00
|
|
|
open
|
2023-01-02 16:01:06 +00:00
|
|
|
title={title}
|
2023-08-02 15:34:04 +00:00
|
|
|
size="medium"
|
2023-01-02 16:01:06 +00:00
|
|
|
onChange={onClose}
|
2023-08-02 15:34:04 +00:00
|
|
|
intent={Intent.None}
|
|
|
|
dataTestId="welcome-dialog"
|
2022-12-13 13:31:28 +00:00
|
|
|
>
|
2023-08-02 15:34:04 +00:00
|
|
|
<WelcomeDialogContent />
|
2022-12-13 13:31:28 +00:00
|
|
|
</Dialog>
|
2023-08-02 15:34:04 +00:00
|
|
|
) : null;
|
2022-12-13 13:31:28 +00:00
|
|
|
};
|