Skip to content

Commit 7cf0b1e

Browse files
committed
refactor(web): support-new-evidence-refactors
1 parent 4822433 commit 7cf0b1e

File tree

4 files changed

+35
-38
lines changed

4 files changed

+35
-38
lines changed

web/src/components/EvidenceCard.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import { Card } from "@kleros/ui-components-library";
99

1010
import AttachmentIcon from "svgs/icons/attachment.svg";
1111

12-
import { useIPFSQuery } from "hooks/useIPFSQuery";
1312
import { formatDate } from "utils/date";
1413
import { getIpfsUrl } from "utils/getIpfsUrl";
1514
import { shortenAddress } from "utils/shortenAddress";
1615

16+
import { type Evidence } from "src/graphql/graphql";
17+
1718
import { landscapeStyle } from "styles/landscapeStyle";
1819
import { responsiveSize } from "styles/responsiveSize";
1920

@@ -136,24 +137,20 @@ const AttachedFileText: React.FC = () => (
136137
</>
137138
);
138139

139-
interface IEvidenceCard {
140-
evidence: string;
140+
interface IEvidenceCard extends Pick<Evidence, "evidence" | "timestamp" | "name" | "description" | "fileURI"> {
141141
sender: string;
142142
index: number;
143-
timestamp: string;
144143
}
145144

146-
const EvidenceCard: React.FC<IEvidenceCard> = ({ evidence, sender, index, timestamp }) => {
147-
const { data } = useIPFSQuery(evidence);
148-
145+
const EvidenceCard: React.FC<IEvidenceCard> = ({ evidence, sender, index, timestamp, name, description, fileURI }) => {
149146
return (
150147
<StyledCard>
151148
<TextContainer>
152149
<Index>#{index}:</Index>
153-
{data ? (
150+
{name && description ? (
154151
<>
155-
<h3>{data.name}</h3>
156-
<StyledReactMarkdown>{data.description}</StyledReactMarkdown>
152+
<h3>{name}</h3>
153+
<StyledReactMarkdown>{description}</StyledReactMarkdown>
157154
</>
158155
) : (
159156
<p>{evidence}</p>
@@ -165,8 +162,8 @@ const EvidenceCard: React.FC<IEvidenceCard> = ({ evidence, sender, index, timest
165162
<p>{shortenAddress(sender)}</p>
166163
</AccountContainer>
167164
<Timestamp>{formatDate(Number(timestamp), true)}</Timestamp>
168-
{data && typeof data.fileURI !== "undefined" && (
169-
<StyledLink to={`attachment/?url=${getIpfsUrl(data.fileURI)}`}>
165+
{fileURI && (
166+
<StyledLink to={`attachment/?url=${getIpfsUrl(fileURI)}`}>
170167
<AttachmentIcon />
171168
<AttachedFileText />
172169
</StyledLink>

web/src/hooks/queries/useEvidences.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const evidencesQuery = graphql(`
1515
id
1616
}
1717
timestamp
18+
name
19+
description
20+
fileURI
21+
fileTypeExtension
1822
}
1923
}
2024
`);
@@ -23,7 +27,7 @@ export const useEvidences = (evidenceGroup?: string) => {
2327
const isEnabled = evidenceGroup !== undefined;
2428
const { graphqlBatcher } = useGraphqlBatcher();
2529

26-
return useQuery({
30+
return useQuery<EvidencesQuery>({
2731
queryKey: ["refetchOnBlock", `evidencesQuery${evidenceGroup}`],
2832
enabled: isEnabled,
2933
queryFn: async () =>

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

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,18 @@ const SubmitEvidenceModal: React.FC<{
6464

6565
const submitEvidence = useCallback(async () => {
6666
setIsSending(true);
67-
toast.info("Uploading to IPFS", toastOptions);
68-
const formData = await constructEvidence(message, file);
69-
uploadFormDataToIPFS(formData)
70-
.then(async (res) => {
71-
const response = await res.json();
72-
if (res.status === 200 && walletClient) {
73-
const cid = response["cids"][0];
74-
const { request } = await simulateEvidenceModuleSubmitEvidence(wagmiConfig, {
75-
args: [BigInt(evidenceGroup), cid],
76-
});
77-
await wrapWithToast(async () => await walletClient.writeContract(request), publicClient).then(() => {
78-
setMessage("");
79-
close();
80-
});
81-
}
67+
const evidenceJSON = await constructEvidence(message, file);
68+
69+
const { request } = await simulateEvidenceModuleSubmitEvidence(wagmiConfig, {
70+
args: [BigInt(evidenceGroup), JSON.stringify(evidenceJSON)],
71+
});
72+
73+
if (!walletClient) return;
74+
await wrapWithToast(async () => await walletClient.writeContract(request), publicClient)
75+
.then(() => {
76+
setMessage("");
77+
close();
8278
})
83-
.catch()
8479
.finally(() => setIsSending(false));
8580
}, [publicClient, wagmiConfig, walletClient, close, evidenceGroup, file, message, setIsSending]);
8681

@@ -101,22 +96,18 @@ const SubmitEvidenceModal: React.FC<{
10196
);
10297
};
10398

104-
const constructEvidence = async (msg: string, file?: File): Promise<FormData> => {
99+
const constructEvidence = async (msg: string, file?: File) => {
105100
let fileURI: string | undefined = undefined;
106101
if (file) {
102+
toast.info("Uploading to IPFS", toastOptions);
107103
const fileFormData = new FormData();
108104
fileFormData.append("data", file, file.name);
109105
fileURI = await uploadFormDataToIPFS(fileFormData).then(async (res) => {
110106
const response = await res.json();
111107
return response["cids"][0];
112108
});
113109
}
114-
const formData = new FormData();
115-
const evidenceFile = new File([JSON.stringify({ name: "Evidence", description: msg, fileURI })], "evidence.json", {
116-
type: "text/plain",
117-
});
118-
formData.append("data", evidenceFile, evidenceFile.name);
119-
return formData;
110+
return { name: "Evidence", description: msg, fileURI };
120111
};
121112

122113
export default SubmitEvidenceModal;

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ const Evidence: React.FC<{ arbitrable?: `0x${string}` }> = ({ arbitrable }) => {
6262
/>
6363
</EnsureChain>
6464
{data ? (
65-
data.evidences.map(({ key, evidence, sender, timestamp }, i) => (
66-
<EvidenceCard key={key} index={i + 1} sender={sender?.id} {...{ evidence, timestamp }} />
65+
data.evidences.map(({ evidence, sender, timestamp, name, description, fileURI }, i) => (
66+
<EvidenceCard
67+
key={timestamp}
68+
index={i + 1}
69+
sender={sender?.id}
70+
{...{ evidence, timestamp, name, description, fileURI }}
71+
/>
6772
))
6873
) : (
6974
<SkeletonEvidenceCard />

0 commit comments

Comments
 (0)