Skip to content

Commit 6db546e

Browse files
committed
Fix proposal xdr execution
1 parent 9c8f3fe commit 6db546e

File tree

2 files changed

+50
-48
lines changed

2 files changed

+50
-48
lines changed

dapp/src/components/page/proposal/ExecuteProposalModal.tsx

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,8 @@ const ExecuteProposalModal: React.FC<ExecuteProposalModalProps> = ({
7070

7171
try {
7272
const { executeProposal } = await import("@service/WriteContractService");
73-
const res = await executeProposal(
74-
projectName,
75-
proposalId,
76-
voteResultAndXdr.xdr,
77-
);
73+
await executeProposal(projectName, proposalId, voteResultAndXdr.xdr);
7874
setStep(step + 1);
79-
console.log("execute result:", res.data);
8075
toast.success("Congratulation!", "Proposal executed successfully");
8176
} catch (error: any) {
8277
toast.error("Execute Proposal", error.message);
@@ -114,25 +109,24 @@ const ExecuteProposalModal: React.FC<ExecuteProposalModalProps> = ({
114109
<Step step={step} totalSteps={3} />
115110
<Title
116111
title="Finalize the Vote Execution"
117-
description="Review the transaction details before execution. You can verify the XDR and proceed with the final step."
112+
description={
113+
voteResultAndXdr.xdr
114+
? "Review the transaction details before execution. You can verify the XDR and proceed with the final step."
115+
: "Review the vote outcome and proceed with finalizing the proposal."
116+
}
118117
/>
119118
<VotingResult voteStatus={voteStatus} />
120-
{/* <div className="flex flex-col gap-[18px]">
121-
<p className="leading-4 text-base text-secondary">
122-
Description
123-
</p>
124-
<p className="text-lg text-primary">
125-
</p>
126-
</div> */}
127-
<div className="flex flex-col items-start gap-[18px]">
128-
<p className="leading-4 text-base text-secondary">XDR</p>
129-
<div className="p-[8px_18px] bg-[#FFEFA8] flex items-center gap-[18px]">
130-
<p className="leading-[18px] text-lg text-primary">
131-
{(voteResultAndXdr.xdr || "").slice(0, 24) + "..."}
132-
</p>
133-
<img src="/icons/clipboard.svg" />
119+
{voteResultAndXdr.xdr && (
120+
<div className="flex flex-col items-start gap-[18px]">
121+
<p className="leading-4 text-base text-secondary">XDR</p>
122+
<div className="p-[8px_18px] bg-[#FFEFA8] flex items-center gap-[18px]">
123+
<p className="leading-[18px] text-lg text-primary">
124+
{voteResultAndXdr.xdr.slice(0, 24) + "..."}
125+
</p>
126+
<img src="/icons/clipboard.svg" />
127+
</div>
134128
</div>
135-
</div>
129+
)}
136130
</div>
137131
</div>
138132
<div className="flex justify-end gap-[18px]">

dapp/src/service/WriteContractService.ts

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -297,41 +297,49 @@ async function executeProposal(
297297
}
298298

299299
try {
300-
await execute(project_name, proposal_id);
301-
const executorAccount = await server.getAccount(publicKey);
302-
const outcomeTransactionEnvelope = executeXdr
303-
? xdr.TransactionEnvelope.fromXDR(executeXdr, "base64")
304-
: undefined;
300+
// Execute the proposal in the smart contract first
301+
const result = await execute(project_name, proposal_id);
305302

306-
const outcomeTransaction = outcomeTransactionEnvelope?.v1().tx();
303+
// Only proceed with the outcome transaction if we have an XDR to execute
304+
if (executeXdr) {
305+
const executorAccount = await server.getAccount(publicKey);
306+
const outcomeTransactionEnvelope = xdr.TransactionEnvelope.fromXDR(
307+
executeXdr,
308+
"base64",
309+
);
310+
const outcomeTransaction = outcomeTransactionEnvelope?.v1().tx();
307311

308-
const transactionBuilder = new TransactionBuilder(executorAccount, {
309-
fee: import.meta.env.PUBLIC_DEFAULT_FEE,
310-
networkPassphrase: import.meta.env.PUBLIC_SOROBAN_NETWORK_PASSPHRASE,
311-
});
312+
const transactionBuilder = new TransactionBuilder(executorAccount, {
313+
fee: import.meta.env.PUBLIC_DEFAULT_FEE,
314+
networkPassphrase: import.meta.env.PUBLIC_SOROBAN_NETWORK_PASSPHRASE,
315+
});
312316

313-
outcomeTransaction?.operations().forEach((operation) => {
314-
transactionBuilder.addOperation(operation);
315-
});
317+
outcomeTransaction?.operations().forEach((operation) => {
318+
transactionBuilder.addOperation(operation);
319+
});
320+
321+
const compositeTransaction = transactionBuilder.setTimeout(180).build();
316322

317-
const compositeTransaction = transactionBuilder.setTimeout(180).build();
323+
const { signedTxXdr } = await kit.signTransaction(
324+
compositeTransaction.toXDR(),
325+
);
318326

319-
const { signedTxXdr } = await kit.signTransaction(
320-
compositeTransaction.toXDR(),
321-
);
327+
const signedTransaction = new Transaction(
328+
signedTxXdr,
329+
import.meta.env.PUBLIC_SOROBAN_NETWORK_PASSPHRASE,
330+
);
322331

323-
const signedTransaction = new Transaction(
324-
signedTxXdr,
325-
import.meta.env.PUBLIC_SOROBAN_NETWORK_PASSPHRASE,
326-
);
332+
const txResult = await server.sendTransaction(signedTransaction);
327333

328-
const result = await server.sendTransaction(signedTransaction);
334+
if (txResult.status === "ERROR") {
335+
throw new Error("Outcome transaction failed");
336+
}
329337

330-
if (result.status === "ERROR") {
331-
throw new Error("Transaction failed");
332-
} else {
333-
return result.hash;
338+
return txResult.hash;
334339
}
340+
341+
// If no XDR to execute, just return the execution result
342+
return result.result;
335343
} catch (e: any) {
336344
throw new Error(e.message);
337345
}

0 commit comments

Comments
 (0)