import { useState, useEffect, ReactNode } from 'react'; import { useLegalStore } from '../../stores/legalStore'; import { TermsModal } from './TermsModal'; import { PrivacyModal } from './PrivacyModal'; import Typography from './Typography'; import Logo from './Logo'; import { FiCheck } from 'react-icons/fi'; interface LegalGuardProps { children: ReactNode; } /** * Legal Guard component that enforces acceptance of Terms of Service and Privacy Policy * on first launch before allowing access to the application */ export const LegalGuard = ({ children }: LegalGuardProps) => { const { legalAcceptance, hasAcceptedAll, acceptTerms, acceptPrivacy, loadFromStorage, } = useLegalStore(); const [isTermsModalOpen, setIsTermsModalOpen] = useState(false); const [isPrivacyModalOpen, setIsPrivacyModalOpen] = useState(false); const [hasInitialized, setHasInitialized] = useState(false); useEffect(() => { const loadData = async () => { await loadFromStorage(); setHasInitialized(true); }; loadData(); }, [loadFromStorage]); useEffect(() => { if (hasInitialized) { if (!legalAcceptance.termsAccepted) { setIsTermsModalOpen(true); } else if (!legalAcceptance.privacyAccepted) { setIsPrivacyModalOpen(true); } } }, [hasInitialized, legalAcceptance]); const handleAcceptTerms = async () => { await acceptTerms(); setIsTermsModalOpen(false); setTimeout(() => { setIsPrivacyModalOpen(true); }, 300); }; const handleAcceptPrivacy = async () => { await acceptPrivacy(); setIsPrivacyModalOpen(false); }; const handleDeclineTerms = () => { alert('You must accept the Terms of Service to use this application.'); }; const handleDeclinePrivacy = () => { alert('You must accept the Privacy Policy to use this application.'); }; if (!hasInitialized) { return (
); } if (!hasAcceptedAll()) { return (
Welcome to Hashgraph Online Your AI assistant for Hedera - transactions, tokens, HCS standards, and more
Before you can continue, please review and accept our legal agreements:
{legalAcceptance.termsAccepted && ( )}
Terms of Service
{legalAcceptance.privacyAccepted && ( )}
Privacy Policy
); } return <>{children}; };