Skip to content
This repository was archived by the owner on Mar 16, 2026. It is now read-only.

Commit a8146c5

Browse files
authored
Merge pull request #694 from aibtcdev/r-contri
auto retry submitting contribution after approving contract
2 parents a9f34f2 + 55b3cb6 commit a8146c5

1 file changed

Lines changed: 65 additions & 5 deletions

File tree

src/components/proposals/ProposalSubmission.tsx

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,70 @@ export function ProposalSubmission({
629629
setSubmissionButtonText(stepMessages[submissionStep] || "submitting...");
630630
}, [isSubmitting, submissionStep, daoName]);
631631

632+
// Auto-close approval modal on success and trigger resubmission
633+
useEffect(() => {
634+
if (showApprovalModal && approvalTransactionStatus === "success") {
635+
// Auto-close after a brief delay to show success state
636+
const timer = setTimeout(async () => {
637+
setShowApprovalModal(false);
638+
handleRetry();
639+
640+
// Show the submission animation
641+
setIsSubmitting(true);
642+
setSubmissionStep(0);
643+
644+
// Rebuild and resubmit the proposal
645+
const extensionData = buildExtensionData();
646+
if (!extensionData) {
647+
console.error(
648+
"Could not determine required DAO extensions for resubmission"
649+
);
650+
setIsSubmitting(false);
651+
setSubmissionStep(0);
652+
return;
653+
}
654+
655+
try {
656+
const response = await sendRequest(extensionData);
657+
658+
// Small delay before showing transaction status modal
659+
await new Promise((resolve) => setTimeout(resolve, 300));
660+
661+
setApiResponse(response);
662+
setShowResultDialog(true);
663+
setTxStatusView("initial");
664+
setIsSubmitting(false);
665+
setSubmissionStep(0);
666+
667+
if (response.success) {
668+
const parsed = parseOutput(response.output);
669+
const txid = parsed?.data?.txid;
670+
if (txid) {
671+
await connectToWebSocket(txid);
672+
}
673+
onSubmissionSuccess?.();
674+
}
675+
} catch (err) {
676+
const networkErrorResponse: ApiResponse = {
677+
success: false,
678+
error:
679+
err instanceof Error
680+
? err.message
681+
: "Failed to connect to the server",
682+
output: "",
683+
};
684+
setApiResponse(networkErrorResponse);
685+
setShowResultDialog(true);
686+
setTxStatusView("initial");
687+
setIsSubmitting(false);
688+
setSubmissionStep(0);
689+
}
690+
}, 1000); // Show success state for 1 second before auto-closing
691+
692+
return () => clearTimeout(timer);
693+
}
694+
}, [showApprovalModal, approvalTransactionStatus]);
695+
632696
// Check for proposals in current Bitcoin block
633697
useEffect(() => {
634698
const checkBitcoinBlockProposals = async () => {
@@ -2039,18 +2103,14 @@ export function ProposalSubmission({
20392103
isOpen={showApprovalModal}
20402104
onClose={() => {
20412105
setShowApprovalModal(false);
2042-
if (approvalTransactionStatus === "success") {
2043-
// After successful approval, retry the original submission
2044-
handleRetry();
2045-
}
20462106
}}
20472107
txId={approvalTxId || undefined}
20482108
transactionStatus={approvalTransactionStatus}
20492109
transactionMessage={approvalTransactionMessage}
20502110
title="Contract Approval Status"
20512111
successTitle="Approval Confirmed"
20522112
failureTitle="Approval Failed"
2053-
successDescription="The contract has been successfully approved for voting operations. You can now retry your submission."
2113+
successDescription="The contract has been successfully approved for voting operations. Resubmitting your contribution now..."
20542114
failureDescription="The contract approval could not be completed. Please try again."
20552115
pendingDescription="The contract approval is being processed on the blockchain. This may take a few minutes."
20562116
onRetry={() => {

0 commit comments

Comments
 (0)