Skip to content

Commit 4ceee36

Browse files
committed
refactor(web): use autogenerated function
1 parent 0a53259 commit 4ceee36

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ import Modal from "react-modal";
55
import { Textarea, Button } from "@kleros/ui-components-library";
66
import { wrapWithToast, OPTIONS as toastOptions } from "utils/wrapWithToast";
77
import { uploadFormDataToIPFS } from "utils/uploadFormDataToIPFS";
8-
import { useWalletClient, usePublicClient } from "wagmi";
9-
import { getDisputeKitClassic, disputeKitClassicABI, disputeKitClassicAddress } from "hooks/contracts/generated";
8+
import { useWalletClient } from "wagmi";
9+
import { prepareWriteDisputeKitClassic } from "hooks/contracts/generated";
1010

1111
const SubmitEvidenceModal: React.FC<{
1212
isOpen: boolean;
1313
evidenceGroup: string;
1414
close: () => void;
1515
}> = ({ isOpen, evidenceGroup, close }) => {
16-
const disputeKit = getDisputeKitClassic({});
1716
const { data: walletClient } = useWalletClient();
18-
const publicClient = usePublicClient();
1917
const [isSending, setIsSending] = useState(false);
2018
const [message, setMessage] = useState("");
2119
return (
@@ -29,32 +27,26 @@ const SubmitEvidenceModal: React.FC<{
2927
isLoading={isSending}
3028
disabled={isSending}
3129
onClick={() => {
32-
if (disputeKit) {
33-
setIsSending(true);
34-
const formData = constructEvidence(message);
35-
toast.info("Uploading to IPFS", toastOptions);
36-
uploadFormDataToIPFS(formData)
37-
.then(async (res) => {
38-
const response = await res.json();
39-
if (res.status === 200) {
40-
const cid = "/ipfs/" + response["cid"];
41-
const [address] = await walletClient!.getAddresses();
42-
const { request } = await publicClient.simulateContract({
43-
abi: disputeKitClassicABI,
44-
address: disputeKitClassicAddress[421613],
45-
functionName: "submitEvidence",
46-
account: address,
47-
args: [BigInt(evidenceGroup), cid],
48-
});
49-
await wrapWithToast(walletClient!.writeContract(request)).then(() => {
50-
setMessage("");
51-
close();
52-
});
53-
}
54-
})
55-
.catch()
56-
.finally(() => setIsSending(false));
57-
}
30+
setIsSending(true);
31+
const formData = constructEvidence(message);
32+
toast.info("Uploading to IPFS", toastOptions);
33+
uploadFormDataToIPFS(formData)
34+
.then(async (res) => {
35+
const response = await res.json();
36+
if (res.status === 200) {
37+
const cid = "/ipfs/" + response["cid"];
38+
const { request } = await prepareWriteDisputeKitClassic({
39+
functionName: "submitEvidence",
40+
args: [BigInt(evidenceGroup), cid],
41+
});
42+
await wrapWithToast(walletClient!.writeContract(request)).then(() => {
43+
setMessage("");
44+
close();
45+
});
46+
}
47+
})
48+
.catch()
49+
.finally(() => setIsSending(false));
5850
}}
5951
/>
6052
</ButtonArea>

0 commit comments

Comments
 (0)