2023-02-24 19:17:13 +00:00
|
|
|
import React, { useContext } from 'react';
|
2022-10-07 14:10:21 +00:00
|
|
|
import { Box, CircularProgress, Tooltip } from '@mui/material';
|
|
|
|
import { TorIcon } from './Icons';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-04-20 14:52:03 +00:00
|
|
|
import { AppContext, UseAppStoreType } from '../contexts/AppContext';
|
2022-10-07 19:33:22 +00:00
|
|
|
|
2023-02-21 17:22:48 +00:00
|
|
|
interface TorIndicatorProps {
|
2022-10-07 19:33:22 +00:00
|
|
|
color: 'inherit' | 'error' | 'warning' | 'success' | 'primary' | 'secondary' | 'info' | undefined;
|
|
|
|
tooltipOpen?: boolean | undefined;
|
|
|
|
title: string;
|
|
|
|
progress: boolean;
|
|
|
|
}
|
|
|
|
|
2023-02-21 17:22:48 +00:00
|
|
|
const TorIndicator = ({
|
|
|
|
color,
|
|
|
|
tooltipOpen = undefined,
|
|
|
|
title,
|
|
|
|
progress,
|
|
|
|
}: TorIndicatorProps): JSX.Element => {
|
2022-10-07 19:33:22 +00:00
|
|
|
return (
|
|
|
|
<Tooltip
|
|
|
|
open={tooltipOpen}
|
|
|
|
enterTouchDelay={0}
|
|
|
|
enterDelay={1000}
|
|
|
|
placement='right'
|
|
|
|
title={title}
|
|
|
|
>
|
|
|
|
<Box sx={{ display: 'inline-flex', position: 'fixed', left: '0.5em', top: '0.5em' }}>
|
|
|
|
{progress ? (
|
|
|
|
<>
|
|
|
|
<CircularProgress color={color} thickness={6} size={22} />
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
bottom: 0,
|
|
|
|
right: 0,
|
|
|
|
position: 'absolute',
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<TorIcon color={color} sx={{ width: 20, height: 20 }} />
|
|
|
|
</Box>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<Box>
|
|
|
|
<TorIcon color={color} sx={{ width: 20, height: 20 }} />
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
};
|
2022-10-07 14:10:21 +00:00
|
|
|
|
2023-02-24 19:17:13 +00:00
|
|
|
const TorConnectionBadge = (): JSX.Element => {
|
2023-04-20 14:52:03 +00:00
|
|
|
const { torStatus } = useContext<UseAppStoreType>(AppContext);
|
2023-02-21 17:22:48 +00:00
|
|
|
const { t } = useTranslation();
|
2022-10-07 14:10:21 +00:00
|
|
|
|
2022-10-14 12:10:12 +00:00
|
|
|
if (window?.NativeRobosats == null) {
|
2022-10-07 19:33:22 +00:00
|
|
|
return <></>;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (torStatus === 'NOTINIT') {
|
2022-10-07 14:10:21 +00:00
|
|
|
return (
|
2022-10-07 19:33:22 +00:00
|
|
|
<TorIndicator
|
|
|
|
color='primary'
|
|
|
|
progress={true}
|
|
|
|
tooltipOpen={true}
|
|
|
|
title={t('Initializing TOR daemon')}
|
|
|
|
/>
|
2022-10-07 14:10:21 +00:00
|
|
|
);
|
2022-10-07 19:33:22 +00:00
|
|
|
} else if (torStatus === 'STARTING') {
|
2022-10-07 14:10:21 +00:00
|
|
|
return (
|
2022-10-07 19:33:22 +00:00
|
|
|
<TorIndicator
|
|
|
|
color='warning'
|
|
|
|
progress={true}
|
|
|
|
tooltipOpen={true}
|
|
|
|
title={t('Connecting to TOR network')}
|
|
|
|
/>
|
2022-10-07 14:10:21 +00:00
|
|
|
);
|
2022-10-07 19:33:22 +00:00
|
|
|
} else if (torStatus === '"Done"' || torStatus === 'DONE') {
|
|
|
|
return <TorIndicator color='success' progress={false} title={t('Connected to TOR network')} />;
|
|
|
|
} else {
|
2022-10-07 14:10:21 +00:00
|
|
|
return (
|
2022-10-07 19:33:22 +00:00
|
|
|
<TorIndicator
|
|
|
|
color='error'
|
|
|
|
progress={false}
|
|
|
|
tooltipOpen={true}
|
|
|
|
title={t('Connection error')}
|
|
|
|
/>
|
2022-10-07 14:10:21 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-21 17:22:48 +00:00
|
|
|
export default TorConnectionBadge;
|