Skip to content

Commit fdd2630

Browse files
committed
refactor(web): use autogenerated function to prepare transaction
1 parent 4ceee36 commit fdd2630

File tree

1 file changed

+21
-36
lines changed

1 file changed

+21
-36
lines changed

web/src/pages/Cases/CaseDetails/Voting/Binary.tsx

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Button, Textarea } from "@kleros/ui-components-library";
55
import { useGetMetaEvidence } from "queries/useGetMetaEvidence";
66
import { wrapWithToast } from "utils/wrapWithToast";
77
import { useWalletClient, usePublicClient } from "wagmi";
8-
import { getDisputeKitClassic, disputeKitClassicABI, disputeKitClassicAddress } from "hooks/contracts/generated";
8+
import { prepareWriteDisputeKitClassic } from "hooks/contracts/generated";
99

1010
const Binary: React.FC<{ arbitrable?: string; voteIDs: string[] }> = ({ arbitrable, voteIDs }) => {
1111
const { id } = useParams();
@@ -16,7 +16,6 @@ const Binary: React.FC<{ arbitrable?: string; voteIDs: string[] }> = ({ arbitrab
1616
const [isSending, setIsSending] = useState(false);
1717
const [justification, setJustification] = useState("");
1818
const { data: walletClient } = useWalletClient();
19-
const disputeKit = getDisputeKitClassic({});
2019
const publicClient = usePublicClient();
2120

2221
return id ? (
@@ -40,22 +39,16 @@ const Binary: React.FC<{ arbitrable?: string; voteIDs: string[] }> = ({ arbitrab
4039
disabled={isSending}
4140
isLoading={chosenOption === i + 1}
4241
onClick={async () => {
43-
if (disputeKit) {
44-
const [address] = await walletClient!.getAddresses();
45-
const { request } = await publicClient.simulateContract({
46-
abi: disputeKitClassicABI,
47-
address: disputeKitClassicAddress[421613],
48-
functionName: "castVote",
49-
account: address,
50-
args: [parsedDisputeID, parsedVoteIDs, BigInt(i + 1), 0n, justification],
51-
});
52-
setIsSending(true);
53-
setChosenOption(i + 1);
54-
wrapWithToast(walletClient!.writeContract(request)).finally(() => {
55-
setChosenOption(-1);
56-
setIsSending(false);
57-
});
58-
}
42+
setIsSending(true);
43+
setChosenOption(i + 1);
44+
const { request } = await prepareWriteDisputeKitClassic({
45+
functionName: "castVote",
46+
args: [parsedDisputeID, parsedVoteIDs, BigInt(i + 1), 0n, justification],
47+
});
48+
wrapWithToast(walletClient!.writeContract(request)).finally(() => {
49+
setChosenOption(-1);
50+
setIsSending(false);
51+
});
5952
}}
6053
/>
6154
))}
@@ -68,24 +61,16 @@ const Binary: React.FC<{ arbitrable?: string; voteIDs: string[] }> = ({ arbitrab
6861
disabled={isSending}
6962
isLoading={chosenOption === 0}
7063
onClick={async () => {
71-
if (disputeKit) {
72-
setIsSending(true);
73-
setChosenOption(0);
74-
const [address] = await walletClient!.getAddresses();
75-
76-
await wrapWithToast(
77-
publicClient.simulateContract({
78-
abi: disputeKitClassicABI,
79-
address: disputeKitClassicAddress[421613],
80-
functionName: "castVote",
81-
account: address,
82-
args: [parsedDisputeID, parsedVoteIDs, 0n, 0n, justification],
83-
})
84-
).finally(() => {
85-
setChosenOption(-1);
86-
setIsSending(false);
87-
});
88-
}
64+
setIsSending(true);
65+
setChosenOption(0);
66+
const { request } = await prepareWriteDisputeKitClassic({
67+
functionName: "castVote",
68+
args: [parsedDisputeID, parsedVoteIDs, 0n, 0n, justification],
69+
});
70+
wrapWithToast(walletClient!.writeContract(request)).finally(() => {
71+
setChosenOption(-1);
72+
setIsSending(false);
73+
});
8974
}}
9075
/>
9176
</RefuseToArbitrateContainer>

0 commit comments

Comments
 (0)