From 550651885c29e911bf13109ca80637e6244b8d6b Mon Sep 17 00:00:00 2001 From: John Shaw Date: Wed, 27 Mar 2024 15:20:37 -0700 Subject: [PATCH 1/6] feature: store cid --- src/pages/History/index.tsx | 50 ++++++++++++++++++++++--------------- src/utils/misc.ts | 1 - 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/pages/History/index.tsx b/src/pages/History/index.tsx index 03740641..29eeb10d 100644 --- a/src/pages/History/index.tsx +++ b/src/pages/History/index.tsx @@ -1,4 +1,4 @@ -import React, { ReactElement, useState, useCallback } from 'react'; +import React, { ReactElement, useState, useCallback, useEffect } from 'react'; import { useDispatch } from 'react-redux'; import { useNavigate } from 'react-router'; import { @@ -27,25 +27,30 @@ export default function History(): ReactElement { return (
{history.map((id) => { - return ; + return ; })}
); } -function OneRequestHistory(props: { requestId: string }): ReactElement { +function OnRequestHistory(props: { requestId: string }): ReactElement { const dispatch = useDispatch(); const request = useRequestHistory(props.requestId); - const [showingError, showError] = useState(false); + const [showingError, setShowError] = useState(false); const [uploadError, setUploadError] = useState(''); - const [showingShareConfirmation, setShowingShareConfirmation] = - useState(false); - const [cid, setCid] = useState(''); + const [showingShareConfirmation, setShowingShareConfirmation] = useState(false); + const [cid, setCid] = useState<{ [key: string]: string}>({}) const [uploading, setUploading] = useState(false); const navigate = useNavigate(); const { status } = request || {}; const requestUrl = urlify(request?.url || ''); + useEffect(() => { + chrome.storage.sync.get(null, (data) => { + setCid(data) + }) + }, []); + const onRetry = useCallback(async () => { const notaryUrl = await getNotaryApi(); const websocketProxyUrl = await getProxyApi(); @@ -72,28 +77,33 @@ function OneRequestHistory(props: { requestId: string }): ReactElement { }, [props.requestId]); const onShowError = useCallback(async () => { - showError(true); - }, [request?.error, showError]); + setShowError(true); + }, [request?.error, setShowError]); const closeAllModal = useCallback(() => { setShowingShareConfirmation(false); - showError(false); - }, [setShowingShareConfirmation, showError]); + setShowError(false); + }, [setShowingShareConfirmation, setShowError]); const handleUpload = useCallback(async () => { setUploading(true); try { const data = await upload( `${request?.id}.json`, - JSON.stringify(request?.proof), + JSON.stringify(request?.proof) ); - setCid(data); + const newCids = { ...cid, [props.requestId]: data }; + setCid(newCids); + console.log(newCids) + chrome.storage.sync.set({ + ...newCids, + }); } catch (e: any) { setUploadError(e.message); } finally { setUploading(false); } - }, []); + }, [props.requestId, request]); return (
@@ -141,7 +151,7 @@ function OneRequestHistory(props: { requestId: string }): ReactElement { ctaText="Download" /> setShowingShareConfirmation(true)} fa="fa-solid fa-upload" ctaText="Share" @@ -221,7 +231,7 @@ function OneRequestHistory(props: { requestId: string }): ReactElement { onClose={closeAllModal} > - {!cid ? ( + {!cid[props.requestId] ? (

{uploadError || 'This will make your proof publicly accessible by anyone with the CID'} @@ -230,13 +240,13 @@ function OneRequestHistory(props: { requestId: string }): ReactElement { e.target.select()} /> )}

- {!cid ? ( + {!cid[props.requestId] ? ( <> {!uploadError && (