import React, { useState, useEffect, useContext } from 'react'; import { AppContext, type UseAppStoreType } from '../contexts/AppContext'; import { useTranslation, Trans } from 'react-i18next'; import { Paper, Alert, AlertTitle, Button, Link } from '@mui/material'; import { getHost } from '../utils'; const UnsafeAlert = (): JSX.Element => { const { windowSize } = useContext(AppContext); const { t } = useTranslation(); const [show, setShow] = useState(true); const [unsafeClient, setUnsafeClient] = useState(false); const [selfHostedClient, setSelfHostedClient] = useState(false); // To do. Read from Coordinators Obj. const safe_urls = [ 'robosats6tkf3eva7x2voqso3a5wcorsnw34jveyxfqi2fu7oyheasid.onion', 'robotestagw3dcxmd66r4rgksb4nmmr43fh77bzn2ia2eucduyeafnyd.onion', 'robodevs7ixniseezbv7uryxhamtz3hvcelzfwpx3rvoipttjomrmpqd.onion', 'robosats.i2p', 'r7r4sckft6ptmk4r2jajiuqbowqyxiwsle4iyg4fijtoordc6z7a.b32.i2p', ]; const checkClient = () => { const http = new XMLHttpRequest(); const h = getHost(); const unsafe = !safe_urls.includes(h); let selfHosted = false; try { http.open('HEAD', `${location.protocol}//${h}/selfhosted`, false); http.send(); selfHosted = http.status === 200; } catch { selfHosted = false; } setUnsafeClient(unsafe); setSelfHostedClient(selfHosted); }; useEffect(() => { checkClient(); }, []); // If alert is hidden return null if (!show) { return <>; } // Show selfhosted notice else if (selfHostedClient) { return (
{ setShow(false); }} > {t('Hide')} } > {t('You are self-hosting RoboSats')} {t( 'RoboSats client is served from your own node granting you the strongest security and privacy.', )}
); } // Show unsafe alert else if (unsafeClient) { return ( {windowSize.width > 57 ? ( { setShow(false); }} > {t('Hide')} } > {t('You are not using RoboSats privately')} Some features are disabled for your protection (e.g. chat) and you will not be able to complete a trade without them. To protect your privacy and fully enable RoboSats, use{' '} Tor Browser and visit the Onion site. ) : ( {t('You are not using RoboSats privately')} You will not be able to complete a trade. Use Tor Browser and visit the Onion {' '} site.
)}
); } }; export default UnsafeAlert;