62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import React, { useEffect, useRef } from 'react';
|
|
import { ProgressDots } from '@fractal-ui/core';
|
|
import { Text } from '@fractal-ui/styling';
|
|
import { to } from '@msb/http';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { olkCryptoModule as cryptoModule, LOCALE_NAME } from '../../core';
|
|
import { INTERVAL_CHECK_CRYPTO, AWAIT_TIME_CRYPTO_INSTALL, SOURCES } from '../constants';
|
|
import type { IViewProps } from '../interfaces';
|
|
import { LoaderWrapper } from './styled';
|
|
|
|
const CONTENT = {
|
|
[SOURCES.DST]: 'sign.modal.cryptoInstallerModal.txt.installCryptomodulForRegCert',
|
|
[SOURCES.VERIFY]: 'sign.modal.cryptoInstallerModal.txt.installCryptomodulForCheckSignature',
|
|
[SOURCES.OTHER]: 'sign.modal.cryptoInstallerModal.txt.installCryptomodulForSign',
|
|
};
|
|
|
|
/**
|
|
* Ожидание установки КМ.
|
|
*/
|
|
export const Info: React.FC<IViewProps> = ({ source, next, onClose }) => {
|
|
const { t } = useTranslation(LOCALE_NAME);
|
|
const timerIsRunning = useRef(false);
|
|
|
|
useEffect(() => {
|
|
if (timerIsRunning.current) return;
|
|
|
|
timerIsRunning.current = true;
|
|
|
|
const jobId = setInterval(async () => {
|
|
const [installed] = await to(cryptoModule.installationCheck());
|
|
|
|
if (installed) {
|
|
next();
|
|
}
|
|
}, INTERVAL_CHECK_CRYPTO);
|
|
|
|
const waitingTimeout = setTimeout(() => {
|
|
clearInterval(jobId);
|
|
|
|
onClose?.();
|
|
}, AWAIT_TIME_CRYPTO_INSTALL);
|
|
|
|
return () => {
|
|
timerIsRunning.current = false;
|
|
clearInterval(jobId);
|
|
clearTimeout(waitingTimeout);
|
|
};
|
|
}, [next, onClose]);
|
|
|
|
return (
|
|
<>
|
|
<Text.P2 color={'text.secondary'}>{t(CONTENT[source])}</Text.P2>
|
|
<br />
|
|
<LoaderWrapper>
|
|
<ProgressDots />
|
|
</LoaderWrapper>
|
|
</>
|
|
);
|
|
};
|
|
|
|
Info.displayName = 'Info';
|