Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring and fixing some components #14

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion server/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ app.get('/ipfs/:cid', async (req, res) => {

const imgUrl= 'data:image/png;base64,' + img.toString('base64');

console.log(imgUrl);
res.send(`
<!DOCTYPE html>
<html lang="en">
Expand Down
2 changes: 1 addition & 1 deletion web/components/FileUpload/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ReactElement, useCallback, useState } from 'react';
import { useDispatch } from 'react-redux';
import { uploadFile } from '../../store/proofupload';
import { uploadFile, selectProof } from '../../store/proofupload';
import { readFileAsync } from '../../utils';
import NotaryKey from '../NotaryKey';
import ProofDetails from '../ProofDetails';
Expand Down
4 changes: 2 additions & 2 deletions web/components/ProofDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ const ProofDetails: React.FC<ProofDetailsProps> = ({proof, cid, file}): ReactEle

const proofToDisplay = selectedProof?.proof || proof;
const inputValue = process.env.NODE_ENV === "development"
? `http://localhost:3000/${selectedProof?.ipfsCID ? selectedProof?.ipfsCID : cid}`
: `www.tlsnexplorer.com/${selectedProof?.ipfsCID ? selectedProof?.ipfsCID : cid}`;
? `http://localhost:3000/ipfs/${selectedProof?.ipfsCID ? selectedProof?.ipfsCID : cid}`
: `https://explorer-tlsn.pse.dev/ipfs/${selectedProof?.ipfsCID ? selectedProof?.ipfsCID : cid}`;

// TODO - Format proof details for redacted data

Expand Down
13 changes: 7 additions & 6 deletions web/components/ProofSelect/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import React, { ReactElement } from 'react';
import React, { ReactElement, useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { selectProof } from '../../store/proofupload';
import { selectProof, useSelectedProof } from '../../store/proofupload';

export default function ProofSelect(): ReactElement {
const dispatch = useDispatch();

const selectedProof = useSelectedProof();
const proofs = useSelector((state: any) => state.proofUpload.proofs);


const handleChange = async (e: React.ChangeEvent<HTMLSelectElement>) => {

const handleChange = useCallback(async (e: React.ChangeEvent<HTMLSelectElement>) => {
const selectedIndex = e.target.selectedIndex;
const proof = proofs[selectedIndex - 1];
dispatch(selectProof(proof));
}
}, []);

return (
<div className='flex flex-row m-auto items-center h-10 bg-gray-800 rounded gap-4 text-black'>
{proofs && (
<select onChange={handleChange} className='bg-gray-800 text-white font-bold'>
<option disabled className='font-bold'>Select a proof</option>
{proofs && proofs.map((proof: any, index: number) => (
<option key={index} className='bg-gray-800 text-white font-bold'>
<option key={index} className='bg-gray-800 text-white font-bold' selected={selectedProof === proof ? selectedProof : proof}>
{proof.fileName}
</option>
))}
Expand Down
41 changes: 8 additions & 33 deletions web/components/SharedProof/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,23 @@ import NotaryKey from '../NotaryKey';
import { fetchProofFromIPFS, useIPFSProof } from '../../store/proofs';
import { useDispatch } from 'react-redux';


export default function SharedProof(): ReactElement {
const { cid } = useParams();
const [errors, setErrors] = useState<string | null>(null);


const notaryKey = useNotaryKey();
const proofData = useIPFSProof(cid);
const dispatch = useDispatch();

useEffect(() => {
dispatch(fetchProofFromIPFS(cid!, notaryKey))
.catch(e => {
console.error(e);
setErrors(e.message);
});

async function fetchFile() {
if (!cid) {
setErrors('No CID provided');
return;
}
const response = await fetch(`/gateway/ipfs/${cid}`);
if (!response.ok) {
setErrors('Failed to fetch file from IPFS');
throw new Error('Failed to fetch file from IPFS');
}
const data = await response.json();
try {
let pubKey: any;
if (data.notaryUrl) {
const notaryFetch = await fetch(data.notaryUrl + '/info');
const notaryData = await notaryFetch.json();
pubKey = notaryData.publicKey;
}

const proof = await verify(data, pubKey || notaryKey);

setVerifiedProof(proof);

} catch (e) {
setErrors('Provide a valid public key')
}
return data;
}
dispatch(fetchProofFromIPFS(cid, notaryKey))
.catch(e => {
console.error(e);
setErrors(e.message);
});
}, [cid, notaryKey]);

return (
Expand Down
2 changes: 1 addition & 1 deletion web/utils/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactElement, useRef } from 'react';
import React, { ReactElement } from 'react';


export const readFileAsync = (file: File): Promise<string> => {
Expand Down