Skip to content

Commit dbb36c0

Browse files
committed
refactor(web): using the same IPFS gateway everywhere, configurable
1 parent ec8014f commit dbb36c0

File tree

5 files changed

+11
-13
lines changed

5 files changed

+11
-13
lines changed

web/src/components/EvidenceCard.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Card } from "@kleros/ui-components-library";
55
import AttachmentIcon from "svgs/icons/attachment.svg";
66
import { useIPFSQuery } from "hooks/useIPFSQuery";
77
import { shortenAddress } from "utils/shortenAddress";
8+
import { IPFS_GATEWAY } from "consts/index";
89

910
interface IEvidenceCard {
1011
evidence: string;
@@ -31,7 +32,7 @@ const EvidenceCard: React.FC<IEvidenceCard> = ({ evidence, sender, index }) => {
3132
<Identicon size="24" string={sender} />
3233
<p>{shortenAddress(sender)}</p>
3334
{data && typeof data.fileURI !== "undefined" && (
34-
<StyledA href={`https://cloudflare-ipfs.com${data.fileURI}`} target="_blank" rel="noreferrer">
35+
<StyledA href={`${IPFS_GATEWAY}${data.fileURI}`} target="_blank" rel="noreferrer">
3536
<AttachmentIcon />
3637
</StyledA>
3738
)}

web/src/consts/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ export const ONE_BASIS_POINT = 10000n;
33
export const KLEROS_CONTRACT_ADDRESS = "ethereum:0x93ed3fbe21207ec2e8f2d3c3de6e058cb73bc04d";
44
export const WETH_CONTRACT_ADDRESS = "ethereum:0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
55
export const PNK_FAUCET_CONTRACT_ADDRESS = "0x05648Ee14941630a649082e0dA5cb80D29cC9002";
6+
7+
export const IPFS_GATEWAY = process.env.REACT_APP_IPFS_GATEWAY || "https://cdn.kleros.link";

web/src/hooks/useIPFSQuery.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useQuery } from "@tanstack/react-query";
22
import { isUndefined } from "utils/index";
3+
import { IPFS_GATEWAY } from "consts/index";
34

45
export const useIPFSQuery = (ipfsPath?: string) => {
56
const isEnabled = !isUndefined(ipfsPath);
@@ -10,7 +11,7 @@ export const useIPFSQuery = (ipfsPath?: string) => {
1011
queryFn: async () => {
1112
if (isEnabled) {
1213
const formatedIPFSPath = ipfsPath.startsWith("/") ? ipfsPath : "/" + ipfsPath;
13-
return fetch(`https://cdn.kleros.link${formatedIPFSPath}`).then(async (res) => await res.json());
14+
return fetch(`${IPFS_GATEWAY}${formatedIPFSPath}`).then(async (res) => await res.json());
1415
}
1516
return undefined;
1617
},

web/src/pages/Cases/CaseDetails/Overview.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useCourtPolicy } from "queries/useCourtPolicy";
1010
import { useCourtPolicyURI } from "queries/useCourtPolicyURI";
1111
import { isUndefined } from "utils/index";
1212
import { Periods } from "consts/periods";
13+
import { IPFS_GATEWAY } from "consts/index";
1314
import PolicyIcon from "svgs/icons/policy.svg";
1415
import DisputeInfo from "components/DisputeCard/DisputeInfo";
1516
import Verdict from "components/Verdict/index";
@@ -131,17 +132,13 @@ const Overview: React.FC<IOverview> = ({ arbitrable, courtID, currentPeriodIndex
131132
<p>Make sure you understand the Policies</p>
132133
<LinkContainer>
133134
{disputeTemplate?.policyURI && (
134-
<StyledA href={`https://cloudflare-ipfs.com${disputeTemplate.policyURI}`} target="_blank" rel="noreferrer">
135+
<StyledA href={`${IPFS_GATEWAY}${disputeTemplate.policyURI}`} target="_blank" rel="noreferrer">
135136
<PolicyIcon />
136137
Dispute Policy
137138
</StyledA>
138139
)}
139140
{courtPolicy && (
140-
<StyledA
141-
href={`https://cloudflare-ipfs.com${courtPolicyURI?.court?.policy ?? ""}`}
142-
target="_blank"
143-
rel="noreferrer"
144-
>
141+
<StyledA href={`${IPFS_GATEWAY}${courtPolicyURI?.court?.policy ?? ""}`} target="_blank" rel="noreferrer">
145142
<PolicyIcon />
146143
Court Policy
147144
</StyledA>

web/src/pages/DisputeTemplateView.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Textarea } from "@kleros/ui-components-library";
55
import PolicyIcon from "svgs/icons/policy.svg";
66
import ReactMarkdown from "components/ReactMarkdown";
77
import { isUndefined } from "utils/index";
8+
import { IPFS_GATEWAY } from "consts/index";
89

910
const Wrapper = styled.div`
1011
min-height: calc(100vh - 144px);
@@ -138,11 +139,7 @@ const Overview: React.FC<{ disputeTemplate: any }> = ({ disputeTemplate }) => {
138139
<p>Make sure you understand the Policies</p>
139140
<LinkContainer>
140141
{disputeTemplate?.policyURI && (
141-
<StyledA
142-
href={`https://cloudflare-ipfs.com${disputeTemplate.policyURI}`}
143-
target="_blank"
144-
rel="noreferrer"
145-
>
142+
<StyledA href={`${IPFS_GATEWAY}${disputeTemplate.policyURI}`} target="_blank" rel="noreferrer">
146143
<PolicyIcon />
147144
Dispute Policy
148145
</StyledA>

0 commit comments

Comments
 (0)