2023-01-02 16:01:06 +00:00
|
|
|
import React, { useCallback } from 'react';
|
2022-12-13 13:31:28 +00:00
|
|
|
import { useLocation } from 'react-router-dom';
|
|
|
|
import { Dialog } from '@vegaprotocol/ui-toolkit';
|
|
|
|
import {
|
|
|
|
t,
|
|
|
|
useDataProvider,
|
|
|
|
useLocalStorage,
|
|
|
|
} from '@vegaprotocol/react-helpers';
|
|
|
|
import { activeMarketsProvider } from '@vegaprotocol/market-list';
|
|
|
|
import { useEnvironment, Networks } from '@vegaprotocol/environment';
|
|
|
|
import * as constants from '../constants';
|
|
|
|
import { RiskNoticeDialog } from './risk-notice-dialog';
|
|
|
|
import { WelcomeNoticeDialog } from './welcome-notice-dialog';
|
|
|
|
import { WelcomeLandingDialog } from './welcome-landing-dialog';
|
2023-01-02 16:01:06 +00:00
|
|
|
import { useGlobalStore } from '../../stores';
|
2022-12-13 13:31:28 +00:00
|
|
|
|
|
|
|
export const WelcomeDialog = () => {
|
|
|
|
const { pathname } = useLocation();
|
|
|
|
const { VEGA_ENV } = useEnvironment();
|
2023-01-02 16:01:06 +00:00
|
|
|
let dialogContent: React.ReactNode = null;
|
|
|
|
let title = '';
|
|
|
|
let size: 'small' | 'medium' = 'small';
|
2022-12-13 13:31:28 +00:00
|
|
|
const [riskAccepted] = useLocalStorage(constants.RISK_ACCEPTED_KEY);
|
|
|
|
const { data } = useDataProvider({
|
|
|
|
dataProvider: activeMarketsProvider,
|
|
|
|
});
|
|
|
|
|
2023-01-02 16:01:06 +00:00
|
|
|
const { update, shouldDisplayWelcomeDialog } = useGlobalStore((store) => ({
|
|
|
|
update: store.update,
|
|
|
|
shouldDisplayWelcomeDialog: store.shouldDisplayWelcomeDialog,
|
|
|
|
}));
|
|
|
|
const isRiskDialogNeeded =
|
|
|
|
riskAccepted !== 'true' && VEGA_ENV === Networks.MAINNET;
|
|
|
|
const isWelcomeDialogNeeded = pathname === '/' || shouldDisplayWelcomeDialog;
|
|
|
|
const onClose = useCallback(() => {
|
|
|
|
update({ shouldDisplayWelcomeDialog: isRiskDialogNeeded });
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
dialogContent = null;
|
|
|
|
}, [update, isRiskDialogNeeded]);
|
|
|
|
|
|
|
|
if (isRiskDialogNeeded) {
|
|
|
|
dialogContent = <RiskNoticeDialog onClose={onClose} />;
|
|
|
|
title = t('WARNING');
|
|
|
|
size = 'medium';
|
|
|
|
} else if (isWelcomeDialogNeeded && data?.length === 0) {
|
|
|
|
dialogContent = <WelcomeNoticeDialog />;
|
|
|
|
} else if (isWelcomeDialogNeeded && (data?.length || 0) > 0) {
|
|
|
|
dialogContent = <WelcomeLandingDialog onClose={onClose} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-12-13 13:31:28 +00:00
|
|
|
<Dialog
|
2023-01-02 16:01:06 +00:00
|
|
|
open={Boolean(dialogContent)}
|
|
|
|
title={title}
|
|
|
|
size={size}
|
|
|
|
onChange={onClose}
|
2022-12-13 13:31:28 +00:00
|
|
|
>
|
2023-01-02 16:01:06 +00:00
|
|
|
{dialogContent}
|
2022-12-13 13:31:28 +00:00
|
|
|
</Dialog>
|
2023-01-02 16:01:06 +00:00
|
|
|
);
|
2022-12-13 13:31:28 +00:00
|
|
|
};
|