// TODO rework with notification import React, { useEffect, useState } from 'react'; import { Modal, styled } from '@jarvisnetwork/ui'; import { useWeb3React } from '@web3-react/core'; import { WalletPicker } from './WalletPicker'; const ModalWrapper = styled.div` @media screen and (max-width: ${(props) => props.theme.rwd.breakpoints[props.theme.rwd.desktopIndex]}px) { .auth-modal { > * { height: auto; padding-bottom: 30px; } } } `; interface PageProps { onNext(): void; onPrev(): void; } type Page = React.FC; interface Props { appName: string; closeAuthModal: () => void; isAuthModalOpen: boolean; Welcome: Page; } export const AuthFlow = ({ appName, closeAuthModal, isAuthModalOpen, Welcome, }: Props): JSX.Element => { const { account } = useWeb3React(); const [current, setPage] = useState(0); const next = () => { if (current === 0) { localStorage.setItem(`${appName}/tos-accepted`, 'true'); } setPage((p) => p + 1); }; const prev = () => setPage((p) => p - 1); const pages = [Welcome, WalletPicker]; const Page = pages[current]; useEffect(() => { if (account) { closeAuthModal(); } }, [account]); useEffect(() => { if (isAuthModalOpen) { if (localStorage.getItem(`${appName}/tos-accepted`) === 'true') { setPage(1); return; } setPage(0); } }, [appName, isAuthModalOpen]); return ( {Page && } ); };