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';
|
2023-02-28 18:56:29 +00:00
|
|
|
import { t } from '@vegaprotocol/i18n';
|
|
|
|
import { useDataProvider, useLocalStorage } from '@vegaprotocol/react-helpers';
|
2022-12-13 13:31:28 +00:00
|
|
|
import { activeMarketsProvider } from '@vegaprotocol/market-list';
|
|
|
|
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();
|
2023-04-26 15:17:23 +00:00
|
|
|
let dialogContent: React.ReactNode;
|
2023-01-02 16:01:06 +00:00
|
|
|
let title = '';
|
|
|
|
let size: 'small' | 'medium' = 'small';
|
2023-04-26 15:17:23 +00:00
|
|
|
let onClose: ((open: boolean) => void) | undefined = undefined;
|
2022-12-13 13:31:28 +00:00
|
|
|
const [riskAccepted] = useLocalStorage(constants.RISK_ACCEPTED_KEY);
|
|
|
|
const { data } = useDataProvider({
|
|
|
|
dataProvider: activeMarketsProvider,
|
2023-03-09 10:03:50 +00:00
|
|
|
variables: undefined,
|
2022-12-13 13:31:28 +00:00
|
|
|
});
|
|
|
|
|
2023-04-26 15:17:23 +00:00
|
|
|
const update = useGlobalStore((store) => store.update);
|
|
|
|
const shouldDisplayWelcomeDialog = useGlobalStore(
|
|
|
|
(store) => store.shouldDisplayWelcomeDialog
|
|
|
|
);
|
|
|
|
const isRiskDialogNeeded = riskAccepted !== 'true' && !('Cypress' in window);
|
2023-01-02 16:01:06 +00:00
|
|
|
const isWelcomeDialogNeeded = pathname === '/' || shouldDisplayWelcomeDialog;
|
2023-04-26 15:17:23 +00:00
|
|
|
const onCloseDialog = useCallback(() => {
|
2023-01-02 16:01:06 +00:00
|
|
|
update({ shouldDisplayWelcomeDialog: isRiskDialogNeeded });
|
|
|
|
}, [update, isRiskDialogNeeded]);
|
|
|
|
|
|
|
|
if (isRiskDialogNeeded) {
|
2023-04-26 15:17:23 +00:00
|
|
|
dialogContent = <RiskNoticeDialog onClose={onCloseDialog} />;
|
2023-01-02 16:01:06 +00:00
|
|
|
title = t('WARNING');
|
|
|
|
size = 'medium';
|
|
|
|
} else if (isWelcomeDialogNeeded && data?.length === 0) {
|
|
|
|
dialogContent = <WelcomeNoticeDialog />;
|
2023-04-26 15:17:23 +00:00
|
|
|
onClose = onCloseDialog;
|
2023-01-02 16:01:06 +00:00
|
|
|
} else if (isWelcomeDialogNeeded && (data?.length || 0) > 0) {
|
2023-04-26 15:17:23 +00:00
|
|
|
dialogContent = <WelcomeLandingDialog onClose={onCloseDialog} />;
|
|
|
|
onClose = onCloseDialog;
|
|
|
|
} else {
|
|
|
|
dialogContent = null as React.ReactNode;
|
2023-01-02 16:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
};
|