handle anchoring delay

This commit is contained in:
Max S 2024-07-23 15:55:07 +02:00
parent ccb82bb089
commit 814460412e
3 changed files with 30 additions and 8 deletions

View File

@ -11,7 +11,7 @@ type IProps = {
isOpen: boolean; isOpen: boolean;
onClose?: () => void; onClose?: () => void;
folderUid: string; folderUid: string;
onAnchorSuccess?: () => void; onAnchorSuccess: () => void;
}; };
export default function AnchoringModal(props: IProps) { export default function AnchoringModal(props: IProps) {
@ -19,12 +19,22 @@ export default function AnchoringModal(props: IProps) {
const [isAnchoring, setIsAnchoring] = useState(false); const [isAnchoring, setIsAnchoring] = useState(false);
const anchor = useCallback(() => { const anchor = useCallback(() => {
const timeoutDelay = 9800;
const timeoutPromise = new Promise((resolve) => {
setTimeout(resolve, timeoutDelay);
});
setIsAnchoring(true); setIsAnchoring(true);
OfficeFolderAnchors.getInstance() return OfficeFolderAnchors.getInstance()
.post(folderUid) .post(folderUid)
.then(() => timeoutPromise)
.then(() => setIsAnchoring(false))
.then(onAnchorSuccess) .then(onAnchorSuccess)
.catch((e) => console.warn(e)) .then(onClose)
}, [folderUid, onAnchorSuccess]); .catch((e) => {
console.warn(e);
setIsAnchoring(false);
});
}, [folderUid, onAnchorSuccess, onClose]);
return ( return (
<Modal <Modal

View File

@ -0,0 +1,12 @@
import Alert, { EAlertVariant } from "@Front/Components/DesignSystem/Alert";
export default function AnchoringProcessingNeutral() {
return (
<Alert
title="Ancrage en cours..."
description="Vos documents sont en train d'être ancrés dans la blockchain. Cela peut prendre quelques instants. Merci de votre patience."
variant={EAlertVariant.NEUTRAL}
fullWidth
/>
);
}

View File

@ -13,6 +13,7 @@ import ClientView from "./ClientView";
import AnchoringAlertInfo from "./elements/AnchoringAlertInfo"; import AnchoringAlertInfo from "./elements/AnchoringAlertInfo";
import AnchoringAlertSuccess from "./elements/AnchoringAlertSuccess"; import AnchoringAlertSuccess from "./elements/AnchoringAlertSuccess";
import AnchoringModal from "./elements/AnchoringModal"; import AnchoringModal from "./elements/AnchoringModal";
import AnchoringProcessingNeutral from "./elements/AnchoringProcessingNeutral";
import ArchiveAlertWarning from "./elements/ArchiveAlertWarning"; import ArchiveAlertWarning from "./elements/ArchiveAlertWarning";
import ArchiveModal from "./elements/ArchiveModal"; import ArchiveModal from "./elements/ArchiveModal";
import DownloadAnchoringProofModal from "./elements/DownloadAnchoringProofModal"; import DownloadAnchoringProofModal from "./elements/DownloadAnchoringProofModal";
@ -121,8 +122,6 @@ export default function FolderInformation(props: IProps) {
fetchData(); fetchData();
}, [fetchData]); }, [fetchData]);
const onAnchorSuccess = useCallback(() => fetchData().then(downloadAnchoringProofModal.open), [fetchData, downloadAnchoringProofModal]);
const onArchive = useCallback(() => { const onArchive = useCallback(() => {
if (anchorStatus === AnchorStatus.NOT_ANCHORED) return requireAnchoringModal.open(); if (anchorStatus === AnchorStatus.NOT_ANCHORED) return requireAnchoringModal.open();
archiveModal.open(); archiveModal.open();
@ -149,17 +148,18 @@ export default function FolderInformation(props: IProps) {
isArchived={isArchived} isArchived={isArchived}
/> />
)} )}
{!isArchived && anchorStatus === AnchorStatus.ANCHORING && <AnchoringProcessingNeutral />}
{isArchived && folderUid && ( {isArchived && folderUid && (
<ArchiveAlertWarning folderUid={folderUid} onDownloadAnchoringProof={downloadAnchoringProofModal.open} /> <ArchiveAlertWarning folderUid={folderUid} onDownloadAnchoringProof={downloadAnchoringProofModal.open} />
)} )}
{folder && !doesFolderHaveClient && <NoClientView folder={folder} anchorStatus={anchorStatus} />} {folder && !doesFolderHaveClient && <NoClientView folder={folder} anchorStatus={anchorStatus} />}
{folder && doesFolderHaveClient && <ClientView folder={folder} anchorStatus={anchorStatus} />} {folder && doesFolderHaveClient && <ClientView folder={folder} anchorStatus={anchorStatus} />}
{folderUid && anchorStatus === AnchorStatus.NOT_ANCHORED && ( {folderUid && (
<AnchoringModal <AnchoringModal
isOpen={anchoringModal.isOpen} isOpen={anchoringModal.isOpen}
onClose={anchoringModal.close} onClose={anchoringModal.close}
folderUid={folderUid} folderUid={folderUid}
onAnchorSuccess={onAnchorSuccess} onAnchorSuccess={fetchData}
/> />
)} )}
{folder && anchorStatus === AnchorStatus.VERIFIED_ON_CHAIN && ( {folder && anchorStatus === AnchorStatus.VERIFIED_ON_CHAIN && (