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;
onClose?: () => void;
folderUid: string;
onAnchorSuccess?: () => void;
onAnchorSuccess: () => void;
};
export default function AnchoringModal(props: IProps) {
@ -19,12 +19,22 @@ export default function AnchoringModal(props: IProps) {
const [isAnchoring, setIsAnchoring] = useState(false);
const anchor = useCallback(() => {
const timeoutDelay = 9800;
const timeoutPromise = new Promise((resolve) => {
setTimeout(resolve, timeoutDelay);
});
setIsAnchoring(true);
OfficeFolderAnchors.getInstance()
return OfficeFolderAnchors.getInstance()
.post(folderUid)
.then(() => timeoutPromise)
.then(() => setIsAnchoring(false))
.then(onAnchorSuccess)
.catch((e) => console.warn(e))
}, [folderUid, onAnchorSuccess]);
.then(onClose)
.catch((e) => {
console.warn(e);
setIsAnchoring(false);
});
}, [folderUid, onAnchorSuccess, onClose]);
return (
<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 AnchoringAlertSuccess from "./elements/AnchoringAlertSuccess";
import AnchoringModal from "./elements/AnchoringModal";
import AnchoringProcessingNeutral from "./elements/AnchoringProcessingNeutral";
import ArchiveAlertWarning from "./elements/ArchiveAlertWarning";
import ArchiveModal from "./elements/ArchiveModal";
import DownloadAnchoringProofModal from "./elements/DownloadAnchoringProofModal";
@ -121,8 +122,6 @@ export default function FolderInformation(props: IProps) {
fetchData();
}, [fetchData]);
const onAnchorSuccess = useCallback(() => fetchData().then(downloadAnchoringProofModal.open), [fetchData, downloadAnchoringProofModal]);
const onArchive = useCallback(() => {
if (anchorStatus === AnchorStatus.NOT_ANCHORED) return requireAnchoringModal.open();
archiveModal.open();
@ -149,17 +148,18 @@ export default function FolderInformation(props: IProps) {
isArchived={isArchived}
/>
)}
{!isArchived && anchorStatus === AnchorStatus.ANCHORING && <AnchoringProcessingNeutral />}
{isArchived && folderUid && (
<ArchiveAlertWarning folderUid={folderUid} onDownloadAnchoringProof={downloadAnchoringProofModal.open} />
)}
{folder && !doesFolderHaveClient && <NoClientView folder={folder} anchorStatus={anchorStatus} />}
{folder && doesFolderHaveClient && <ClientView folder={folder} anchorStatus={anchorStatus} />}
{folderUid && anchorStatus === AnchorStatus.NOT_ANCHORED && (
{folderUid && (
<AnchoringModal
isOpen={anchoringModal.isOpen}
onClose={anchoringModal.close}
folderUid={folderUid}
onAnchorSuccess={onAnchorSuccess}
onAnchorSuccess={fetchData}
/>
)}
{folder && anchorStatus === AnchorStatus.VERIFIED_ON_CHAIN && (