import React, { Component } from 'react'; import { withTranslation, Trans } from 'react-i18next'; import { Paper, Alert, AlertTitle, Button, Link } from '@mui/material'; import MediaQuery from 'react-responsive'; import { getHost } from '../utils'; class UnsafeAlert extends Component { constructor(props) { super(props); this.state = { show: true, }; } // To do. Read from Coordinators state Obj. safe_urls = [ 'robosats6tkf3eva7x2voqso3a5wcorsnw34jveyxfqi2fu7oyheasid.onion', 'robotestagw3dcxmd66r4rgksb4nmmr43fh77bzn2ia2eucduyeafnyd.onion', 'robodevs7ixniseezbv7uryxhamtz3hvcelzfwpx3rvoipttjomrmpqd.onion', 'robosats.i2p', 'r7r4sckft6ptmk4r2jajiuqbowqyxiwsle4iyg4fijtoordc6z7a.b32.i2p', ]; checkClient() { const http = new XMLHttpRequest(); const host = getHost(); const unsafeClient = !this.safe_urls.includes(host); try { http.open('HEAD', `${location.protocol}//${host}/selfhosted`, false); http.send(); this.props.setSettings({ ...this.props.settings, host, unsafeClient, selfhostedClient: http.status === 200, }); } catch { this.props.setSettings({ ...this.props.settings, host, unsafeClient, selfhostedClient: false, }); } } componentDidMount() { this.checkClient(); } render() { const { t } = this.props; // If alert is hidden return null if (!this.state.show) { return null; } // Show selfhosted notice else if (this.props.settings.selfhostedClient) { return (
this.setState({ show: 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 (this.props.settings.unsafeClient) { return (
this.setState({ show: 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 withTranslation()(UnsafeAlert);