mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-31 10:31:35 +00:00
Fix unsafe/selfhosted alert
This commit is contained in:
parent
55a22955db
commit
de18fb0d4c
@ -5,10 +5,13 @@ import { Paper, Alert, AlertTitle, Button, Link } from '@mui/material';
|
|||||||
import { getHost } from '../utils';
|
import { getHost } from '../utils';
|
||||||
|
|
||||||
const UnsafeAlert = (): JSX.Element => {
|
const UnsafeAlert = (): JSX.Element => {
|
||||||
const { settings, setSettings, windowSize } = useContext<AppContextProps>(AppContext);
|
const { windowSize } = useContext<AppContextProps>(AppContext);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [show, setShow] = useState<boolean>(true);
|
const [show, setShow] = useState<boolean>(true);
|
||||||
|
|
||||||
|
const [unsafeClient, setUnsafeClient] = useState<boolean>(false);
|
||||||
|
const [selfHostedClient, setSelfHostedClient] = useState<boolean>(false);
|
||||||
|
|
||||||
// To do. Read from Coordinators Obj.
|
// To do. Read from Coordinators Obj.
|
||||||
const safe_urls = [
|
const safe_urls = [
|
||||||
'robosats6tkf3eva7x2voqso3a5wcorsnw34jveyxfqi2fu7oyheasid.onion',
|
'robosats6tkf3eva7x2voqso3a5wcorsnw34jveyxfqi2fu7oyheasid.onion',
|
||||||
@ -20,25 +23,20 @@ const UnsafeAlert = (): JSX.Element => {
|
|||||||
|
|
||||||
const checkClient = () => {
|
const checkClient = () => {
|
||||||
const http = new XMLHttpRequest();
|
const http = new XMLHttpRequest();
|
||||||
const host = getHost();
|
const h = getHost();
|
||||||
const unsafeClient = !safe_urls.includes(host);
|
const unsafe = !safe_urls.includes(h);
|
||||||
|
let selfHosted = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
http.open('HEAD', `${location.protocol}//${host}/selfhosted`, false);
|
http.open('HEAD', `${location.protocol}//${h}/selfhosted`, false);
|
||||||
http.send();
|
http.send();
|
||||||
setSettings({
|
selfHosted = http.status === 200;
|
||||||
...settings,
|
|
||||||
host,
|
|
||||||
unsafeClient,
|
|
||||||
selfhostedClient: http.status === 200,
|
|
||||||
});
|
|
||||||
} catch {
|
} catch {
|
||||||
setSettings({
|
selfHosted = false;
|
||||||
...settings,
|
|
||||||
host,
|
|
||||||
unsafeClient,
|
|
||||||
selfhostedClient: false,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setUnsafeClient(unsafe);
|
||||||
|
setSelfHostedClient(selfHosted);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -51,7 +49,7 @@ const UnsafeAlert = (): JSX.Element => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show selfhosted notice
|
// Show selfhosted notice
|
||||||
else if (settings.selfhostedClient) {
|
else if (selfHostedClient) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Paper elevation={6} className='unsafeAlert'>
|
<Paper elevation={6} className='unsafeAlert'>
|
||||||
@ -75,7 +73,7 @@ const UnsafeAlert = (): JSX.Element => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show unsafe alert
|
// Show unsafe alert
|
||||||
else if (settings.unsafeClient) {
|
else if (unsafeClient) {
|
||||||
return (
|
return (
|
||||||
<Paper elevation={6} className='unsafeAlert'>
|
<Paper elevation={6} className='unsafeAlert'>
|
||||||
{windowSize.width > 57 ? (
|
{windowSize.width > 57 ? (
|
||||||
|
Loading…
Reference in New Issue
Block a user