From 07d0ef625ad38f1a09c20e196b30c73476eb2d03 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 1 Nov 2024 17:17:41 -0300 Subject: [PATCH 1/3] fix: attachments on evidence --- .../[pohid]/[chain]/[request]/Evidence.tsx | 30 +++++++++---------- src/types/docs.ts | 1 + 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/app/[pohid]/[chain]/[request]/Evidence.tsx b/src/app/[pohid]/[chain]/[request]/Evidence.tsx index 733aee1..8452b86 100644 --- a/src/app/[pohid]/[chain]/[request]/Evidence.tsx +++ b/src/app/[pohid]/[chain]/[request]/Evidence.tsx @@ -1,15 +1,8 @@ "use client"; import { enableReactUse } from "@legendapp/state/config/enableReactUse"; -import usePoHWrite from "contracts/hooks/usePoHWrite"; -import AttachmentIcon from "icons/AttachmentMajor.svg"; -import DocumentIcon from "icons/NoteMajor.svg"; -import Link from "next/link"; -import { useEffect, useMemo, useState } from "react"; -import { toast } from "react-toastify"; -import useSWR from "swr"; -import { Address, Hash } from "viem"; import Accordion from "components/Accordion"; +import Attachment from "components/Attachment"; import ExternalLink from "components/ExternalLink"; import Field from "components/Field"; import withClientConnected from "components/HighOrder/withClientConnected"; @@ -18,15 +11,21 @@ import Label from "components/Label"; import Modal from "components/Modal"; import TimeAgo from "components/TimeAgo"; import Uploader from "components/Uploader"; +import { explorerLink } from "config/chains"; +import usePoHWrite from "contracts/hooks/usePoHWrite"; import { RequestQuery } from "generated/graphql"; import useChainParam from "hooks/useChainParam"; import useIPFS from "hooks/useIPFS"; import { useLoading } from "hooks/useLoading"; +import DocumentIcon from "icons/NoteMajor.svg"; +import { useEffect, useMemo, useState } from "react"; +import { toast } from "react-toastify"; +import useSWR from "swr"; import { EvidenceFile, MetaEvidenceFile } from "types/docs"; import { shortenAddress } from "utils/address"; -import { explorerLink } from "config/chains"; import { ipfs, ipfsFetch, uploadToIPFS } from "utils/ipfs"; import { romanize } from "utils/misc"; +import { Address, Hash } from "viem"; import { usePublicClient } from "wagmi"; enableReactUse(); @@ -41,6 +40,11 @@ interface ItemInterface { function Item({ index, uri, creationTime, sender }: ItemInterface) { const chain = useChainParam()!; const [evidence] = useIPFS(uri); + const ipfsUri = evidence?.fileURI + ? evidence?.fileURI + : evidence?.evidence + ? evidence?.evidence + : undefined; return (
@@ -50,13 +54,7 @@ function Item({ index, uri, creationTime, sender }: ItemInterface) {
{evidence?.name} - {evidence?.fileURI && ( - - - - )} + {ipfsUri && }

{evidence?.description}

diff --git a/src/types/docs.ts b/src/types/docs.ts index 506b497..23b1a70 100644 --- a/src/types/docs.ts +++ b/src/types/docs.ts @@ -2,6 +2,7 @@ export interface EvidenceFile { name: string; description?: string; fileURI?: string; + evidence?: string; } export interface RegistrationFile { From 5bcf22dccb62a27a2e3feeed15c1eeb594e8dbff Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 1 Nov 2024 20:08:27 -0300 Subject: [PATCH 2/3] fix: toasts submitting evidence --- .../[pohid]/[chain]/[request]/Evidence.tsx | 23 +++++++++++++------ src/contracts/index.ts | 4 +++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/app/[pohid]/[chain]/[request]/Evidence.tsx b/src/app/[pohid]/[chain]/[request]/Evidence.tsx index 8452b86..a2edb07 100644 --- a/src/app/[pohid]/[chain]/[request]/Evidence.tsx +++ b/src/app/[pohid]/[chain]/[request]/Evidence.tsx @@ -1,6 +1,7 @@ "use client"; import { enableReactUse } from "@legendapp/state/config/enableReactUse"; +import { useObservable } from "@legendapp/state/react"; import Accordion from "components/Accordion"; import Attachment from "components/Attachment"; import ExternalLink from "components/ExternalLink"; @@ -12,6 +13,7 @@ import Modal from "components/Modal"; import TimeAgo from "components/TimeAgo"; import Uploader from "components/Uploader"; import { explorerLink } from "config/chains"; +import { Effects } from "contracts/hooks/types"; import usePoHWrite from "contracts/hooks/usePoHWrite"; import { RequestQuery } from "generated/graphql"; import useChainParam from "hooks/useChainParam"; @@ -98,12 +100,12 @@ export default withClientConnected(function Evidence({ (await ipfsFetch(metaEvidenceLink)).fileURI, ); const [modalOpen, setModalOpen] = useState(false); - const loading = useLoading(false, "Revoke"); + const loading = useLoading(); const [pending] = loading.use(); const [prepare] = usePoHWrite( "submitEvidence", - useMemo( + useMemo( () => ({ onReady(fire) { fire(); @@ -114,13 +116,18 @@ export default withClientConnected(function Evidence({ toast.error("Transaction rejected"); }, onSuccess() { - setModalOpen(false); + loading.stop(); toast.success("Request created"); }, }), [loading], ), ); + + const state$ = useObservable({ + uri: "", + }); + const [title, setTitle] = useState(""); const [description, setDescription] = useState(""); const [file, setFile] = useState(null); @@ -133,12 +140,14 @@ export default withClientConnected(function Evidence({ data.append("name", title); if (description) data.append("description", description); if (file) data.append("evidence", file, file.name); - - prepare({ args: [pohId, BigInt(requestIndex), await uploadToIPFS(data)] }); - - loading.stop(); + state$.uri.set(await uploadToIPFS(data)); }; + state$.onChange(({ value }) => { + if (!value.uri) return; + prepare({ args: [pohId, BigInt(requestIndex), value.uri] }); + }); + const [isEvidenceDisabled, setIsEvidenceDisabled] = useState(false); useEffect(() => { diff --git a/src/contracts/index.ts b/src/contracts/index.ts index 538f59b..6771eda 100644 --- a/src/contracts/index.ts +++ b/src/contracts/index.ts @@ -17,11 +17,13 @@ export const configSets = { }, }; -export const configSetSelection = +/* export const configSetSelection = process.env.DEPLOYED_APP == "https://testnets--proof-of-humanity-v2.netlify.app/" ? configSets.testOld : configSets.main; + */ +export const configSetSelection = configSets.mainOld; export const Contract = { ProofOfHumanity: From deac2ddc7621275afa09e3c7c77e8a4c37ad3b28 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 1 Nov 2024 20:10:03 -0300 Subject: [PATCH 3/3] fix: prepare index for production --- src/contracts/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/contracts/index.ts b/src/contracts/index.ts index 6771eda..538f59b 100644 --- a/src/contracts/index.ts +++ b/src/contracts/index.ts @@ -17,13 +17,11 @@ export const configSets = { }, }; -/* export const configSetSelection = +export const configSetSelection = process.env.DEPLOYED_APP == "https://testnets--proof-of-humanity-v2.netlify.app/" ? configSets.testOld : configSets.main; - */ -export const configSetSelection = configSets.mainOld; export const Contract = { ProofOfHumanity: