From 4b56d0842e5e9d31ef8dd2444690526a867ad1d8 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 14 Mar 2024 18:33:29 -0300 Subject: [PATCH] ipfs gateway env CrossChain profiles (pending transfer) --- env.d.ts | 3 +- next.config.js | 3 +- src/app/[pohid]/CrossChain.tsx | 11 +++- src/app/[pohid]/page.tsx | 106 ++++++++++++++++++++++++-------- src/components/request/Grid.tsx | 2 +- src/contracts/index.ts | 3 +- src/utils/ipfs.ts | 5 +- 7 files changed, 102 insertions(+), 31 deletions(-) diff --git a/env.d.ts b/env.d.ts index 2149bb5..f8b9ad4 100644 --- a/env.d.ts +++ b/env.d.ts @@ -7,8 +7,9 @@ declare global { DATALAKE_URL: string; DATALAKE_KEY: string; LOGTAIL_SOURCE_TOKEN: string; + REACT_APP_IPFS_GATEWAY: string; } } } -export {}; +export {}; \ No newline at end of file diff --git a/next.config.js b/next.config.js index b862da3..ce789b6 100644 --- a/next.config.js +++ b/next.config.js @@ -14,7 +14,8 @@ const nextConfig = { remotePatterns: [ { protocol: "https", - hostname: "ipfs.kleros.io", + hostname: `${process.env.REACT_APP_IPFS_GATEWAY.slice(8)}`, + //hostname: "ipfs.kleros.io", port: "", pathname: "/ipfs/**", }, diff --git a/src/app/[pohid]/CrossChain.tsx b/src/app/[pohid]/CrossChain.tsx index a6941d1..53e8c55 100644 --- a/src/app/[pohid]/CrossChain.tsx +++ b/src/app/[pohid]/CrossChain.tsx @@ -31,6 +31,15 @@ interface CrossChainProps extends JSX.IntrinsicAttributes { lastTransferChain?: SupportedChain; } +type TransferType = { + transferHash: string, + foreignProxy: Address, + transferTimestamp: string, + senderChain: SupportedChain | undefined, + receivingChain: SupportedChain, + received: boolean, +} + export default withClientConnected(function CrossChain({ pohId, contractData, @@ -74,7 +83,7 @@ export default withClientConnected(function CrossChain({ ) ); - const transfer$ = useObservable({ + const transfer$ = useObservable({ transferHash: lastTransfer?.transferHash, foreignProxy: lastTransfer?.foreignProxy, transferTimestamp: lastTransfer?.transferTimestamp, diff --git a/src/app/[pohid]/page.tsx b/src/app/[pohid]/page.tsx index c2fb82e..bb03b93 100644 --- a/src/app/[pohid]/page.tsx +++ b/src/app/[pohid]/page.tsx @@ -39,6 +39,14 @@ async function Profile({ params: { pohid } }: PageProps) { (chain) => !!humanity[chain.id]?.humanity?.registration ); + const homeCrossChain = !(!!homeChain) && supportedChains.find( + (chain) => !!humanity[chain.id]?.crossChainRegistration + ); + + const humanityHomeChainRegistration = homeChain && humanity[homeChain.id]!.humanity!.registration; + const humanityCrossChainRegistration = homeCrossChain && humanity[homeCrossChain.id].crossChainRegistration; + + const arbitrationCost = homeChain ? await getArbitrationCost( homeChain, @@ -59,6 +67,8 @@ async function Profile({ params: { pohid } }: PageProps) { })[0] : null; + const humanityLEChainRegistration = lastEvidenceChain && humanity[lastEvidenceChain.id]!.humanity!.registration; + const pendingRequests = supportedChains.reduce( (acc, chain) => [ ...acc, @@ -75,13 +85,19 @@ async function Profile({ params: { pohid } }: PageProps) { [] as PoHRequest[] ); - const expired = lastEvidenceChain && humanity[lastEvidenceChain.id]!.humanity!.registration!.expirationTime < Date.now() / 1000; - const winnerClaimRequest = - lastEvidenceChain && + let expired = (lastEvidenceChain && humanity[lastEvidenceChain.id]!.humanity!.registration!.expirationTime < Date.now() / 1000) + + let winnerClaimRequest = + (lastEvidenceChain && !(expired) && // It did not expired - humanity[lastEvidenceChain.id].humanity!.winnerClaim[0]; + humanity[lastEvidenceChain.id].humanity!.winnerClaim[0]); + if (!winnerClaimRequest) { + winnerClaimRequest = (!!homeCrossChain && humanity[homeCrossChain.id].humanity!.winnerClaim[0]); + expired = (!!humanityCrossChainRegistration && humanityCrossChainRegistration.expirationTime < Date.now() / 1000); + } + // pastRequests must not contain pendingRequests nor winningClaimRequest if it did not expired const pastRequests = supportedChains.reduce( (acc, chain) => [ @@ -213,6 +229,18 @@ async function Profile({ params: { pohid } }: PageProps) { lastTransferChain={lastTransferChain} /> + ) : homeCrossChain && humanityCrossChainRegistration ? ( + ) : ( <> Not claimed @@ -224,34 +252,62 @@ async function Profile({ params: { pohid } }: PageProps) {
- {homeChain && winnerClaimRequest && ( + {((homeChain && lastEvidenceChain) || (homeCrossChain)) && winnerClaimRequest && (
-
Winning claim
+
+ {homeChain && lastEvidenceChain? + 'Winning claim' + : + 'Crossing chain (update)' + } +
- + {homeChain && lastEvidenceChain? + + : + homeCrossChain && humanityCrossChainRegistration && + + }
)} diff --git a/src/components/request/Grid.tsx b/src/components/request/Grid.tsx index 01beed3..7c2e911 100644 --- a/src/components/request/Grid.tsx +++ b/src/components/request/Grid.tsx @@ -58,7 +58,7 @@ const normalize = ( ...request, old: Number(chainId) === legacyChain.id, chainId: Number(chainId) as SupportedChainId, - expired: + expired: request.status.id === "resolved" && request.humanity.winnerClaim.length>0 && !!humanityLifespan && diff --git a/src/contracts/index.ts b/src/contracts/index.ts index 7a7568a..3fea8d2 100644 --- a/src/contracts/index.ts +++ b/src/contracts/index.ts @@ -3,7 +3,8 @@ import { gnosis, sepolia } from "viem/chains"; export const Contract = { ProofOfHumanity: { [sepolia.id]: "0x29defF3DbEf6f79ef20d3fe4f9CFa0547acCeC0D", - [gnosis.id]: "0xB6412c84eC958cafcC80B688d6F473e399be488f", + //[gnosis.id]: "0xB6412c84eC958cafcC80B688d6F473e399be488f", + [gnosis.id]: "0x4a594f0e73223c9a1CE0EfC16da92fFaA193a612", }, CrossChainProofOfHumanity: { [sepolia.id]: "0xd134748B972A320a73EfDe3AfF7a68718F6bA92c", diff --git a/src/utils/ipfs.ts b/src/utils/ipfs.ts index 246d7ca..81ce05e 100644 --- a/src/utils/ipfs.ts +++ b/src/utils/ipfs.ts @@ -1,11 +1,14 @@ import axios from "axios"; +export const IPFS_GATEWAY = process.env.REACT_APP_IPFS_GATEWAY || "https://ipfs.kleros.io"; + export const uploadToIPFS = async (data: FormData) => { const result = await axios.post("/api/ipfs-upload", data); return result.data.uri; }; -export const ipfs = (uri: string) => `https://ipfs.kleros.io${uri}`; +export const ipfs = (uri: string) => `${IPFS_GATEWAY}${uri}`; +//export const ipfs = (uri: string) => `https://ipfs.kleros.io${uri}`; export const ipfsFetch = async (ipfsURI: string) => (await axios.get(ipfs(ipfsURI))).data as F;