Skip to content

Commit

Permalink
add-signHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
kientt265 committed Nov 20, 2024
1 parent 5b0b6d4 commit 5d92a6e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/component/SignHistory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

import { ethers, JsonRpcProvider, Signer} from "ethers";
import React, { useEffect, useState } from 'react';

interface ChildComponentProps{
signer: Signer;
proof: string;
res: string;
provider: JsonRpcProvider;
}
const SignHistory: React.FC<ChildComponentProps> = ({ signer, proof, res, provider }) => {
const [loading, setLoading] = useState<boolean>(false);
const contractAdr = import.meta.env.VITE_CONTRACT_ADDRESS_HISTORY || "";
const contractABI = JSON.parse(import.meta.env.VITE_CONTRACT_ABI_HISTORY || "[]");
const contract = new ethers.Contract(contractAdr, contractABI, signer )
useEffect(() => {
const fetchAddress = async () => {
if (signer) {
const addressAcc = await signer.getAddress();
console.log("Signer Address:", addressAcc);
await contract.addHistory(addressAcc, proof, res)
setLoading(true)
}
};
fetchAddress();
}, [signer]);



return (
<div>
<div>loading: {loading}</div>
</div>
);
};

export default SignHistory;
4 changes: 4 additions & 0 deletions src/component/SnarkjsProof.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState } from "react";
import * as snarkjs from "snarkjs";
import { ethers, JsonRpcProvider, Wallet, Contract } from "ethers";
import GetInputPatient from "./GetInputPatient";
import SignHistory from "./SignHistory"
// Define types for proof and public signals
interface Proof {
pi_a: [string, string];
Expand Down Expand Up @@ -158,6 +159,9 @@ function SnarkjsProof({ signer, age }: SnarkjsProofProps) {
<button onClick={verifyProof} className="bg-red-400">Verify Proof</button>
<code>{verificationResult}</code>
</pre>
<div>
<SignHistory signer={wallet} proof={generateCall} res={verificationResult} provider={provider} />
</div>
</div>
);
}
Expand Down

0 comments on commit 5d92a6e

Please sign in to comment.