Skip to content

Commit

Permalink
fix pages
Browse files Browse the repository at this point in the history
  • Loading branch information
arjanjohan committed Jul 13, 2024
1 parent f0ac374 commit aeaff74
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/nextjs/app/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const CreateNote: NextPage = () => {
console.log("note_ipfs", note_ipfs);

const response = await axios.post(`${process.env.NEXT_PUBLIC_IPFS_API}/createNewNote`, {
note: note_ipfs,
...note,
});

console.log("response", response.status);
Expand Down
40 changes: 34 additions & 6 deletions packages/nextjs/app/view/[address]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ import { isAddress } from "viem";
import { Address } from "~~/components/scaffold-eth";
import { useTargetNetwork } from "~~/hooks/scaffold-eth";
import { useScaffoldReadContract, useScaffoldWriteContract } from "~~/hooks/scaffold-eth";
import { useAccount } from "wagmi";
import { decodeAbiParameters, parseAbiParameters } from "viem";



const ViewNote: NextPage = () => {
const { targetNetwork } = useTargetNetwork();
const { address } = useParams();
const [notes, setNotes] = useState<any[]>([]);
const [votes, setVotes] = useState<any[]>([]);
const { address: connectedAccount } = useAccount();

const [proof, setProof] = useState("");
const { resolvedTheme } = useTheme();
const isDarkMode = resolvedTheme === "dark";
Expand All @@ -27,7 +33,6 @@ const ViewNote: NextPage = () => {
functionName: "retrieveContractNotes",
args: [address],
});
console.log("notesData", notesData);

const { writeContractAsync: writeNotesContract, isPending } = useScaffoldWriteContract("Notes");

Expand All @@ -47,11 +52,9 @@ const ViewNote: NextPage = () => {

const contentsPromises = noteInfo.map(async (note: any) => {
try {
console.log("Note content response: TRY");

const response = await axios.get(`${process.env.NEXT_PUBLIC_IPFS_API}/getNote?cid=${note.uri}`);
console.log("Note content response:", response);
return response.data.content;
console.log("response", response);
return response.data.response.comment;
} catch (error) {
console.error("Error fetching note content:", error);
return "Failed to fetch content";
Expand All @@ -70,11 +73,36 @@ const ViewNote: NextPage = () => {

const handleVote = async (noteIndex: number, rating: number) => {
const noteAddress = address;


let transformedProof = {
root: BigInt(0),
signal: "0x0000000000000000000000000000000000000000",
nullifierHash: BigInt(0),
proof: Array(8).fill(BigInt(0)),
};

// If the proof is available, use it.
if (proof) {
transformedProof = {
root: BigInt(proof!.merkle_root),
signal: connectedAccount,
nullifierHash: BigInt(proof!.nullifier_hash),
proof: decodeAbiParameters(parseAbiParameters("uint256[8]"), proof!.proof as `0x${string}`)[0],
};
}writeNotesContract



try {
console.log("Submitting vote...");
console.log("Rating:", rating);
console.log("Note index:", noteIndex);
console.log("Note address:", noteAddress);
console.log("Proof:", proof);
await writeNotesContract({
functionName: "vote",
args: [rating, BigInt(noteIndex), noteAddress, proof],
args: [rating, BigInt(noteIndex), noteAddress, transformedProof],
});
console.log("Vote submitted successfully");
} catch (error) {
Expand Down
Binary file removed packages/nextjs/public/thumbnail.jpg
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/nextjs/utils/scaffold-eth/getMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const titleTemplate = "%s | Scaffold-ETH 2";
export const getMetadata = ({
title,
description,
imageRelativePath = "/thumbnail.jpg",
imageRelativePath = "/logo.jpg",
}: {
title: string;
description: string;
Expand Down

0 comments on commit aeaff74

Please sign in to comment.