diff --git a/packages/nextjs/app/(app)/onboarding/page.tsx b/packages/nextjs/app/(app)/onboarding/page.tsx index 25ab864..1a507a4 100644 --- a/packages/nextjs/app/(app)/onboarding/page.tsx +++ b/packages/nextjs/app/(app)/onboarding/page.tsx @@ -1,3 +1,4 @@ +// "use client"; import { Metadata } from "next"; import { ClaimRoleCard } from "~~/components/dashboard/ClaimRoleCard"; diff --git a/packages/nextjs/components/dashboard/DataRegistry.tsx b/packages/nextjs/components/dashboard/DataRegistry.tsx index aa5edeb..02ef040 100644 --- a/packages/nextjs/components/dashboard/DataRegistry.tsx +++ b/packages/nextjs/components/dashboard/DataRegistry.tsx @@ -1,9 +1,8 @@ "use client"; -/* eslint-disable prettier/prettier */ -import { useState, useEffect } from "react"; -import { ethers } from "ethers"; +import { useEffect, useState } from "react"; import DataRegistryABI from "../../contracts/DataRegistry.json"; +import { ethers } from "ethers"; type DataRecord = { id: string; @@ -14,20 +13,23 @@ type DataRecord = { export const DataRegistry: React.FC = () => { const [records, setRecords] = useState([]); const [isLoading, setIsLoading] = useState(true); + const [isClient, setIsClient] = useState(false); + + // Set isClient to true after mounting in client + useEffect(() => { + setIsClient(true); + }, []); const fetchDataRecords = async () => { + if (typeof window === "undefined" || !window.ethereum) { + return alert("Please install MetaMask or another EVM-compatible wallet."); + } + setIsLoading(true); try { - // Check if `window` is defined and `ethereum` is available to avoid server-side errors - if (typeof window !== "undefined" && !window.ethereum) { - alert("Please install MetaMask or any other EVM-wallet"); - return; - } - - // If `window` is defined, proceed with accessing `window.ethereum` const provider = new ethers.providers.Web3Provider(window.ethereum); const signer = provider.getSigner(); - const contractAddress = "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"; + const contractAddress = "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"; const contract = new ethers.Contract(contractAddress, DataRegistryABI.abi, signer); const recordsData = await contract.getAllRecords(); @@ -46,24 +48,20 @@ export const DataRegistry: React.FC = () => { } }; + // Trigger data fetch only on client useEffect(() => { - // Ensure fetchDataRecords runs only on the client side - if (typeof window !== "undefined") { - fetchDataRecords(); - } - }, []); + if (isClient) fetchDataRecords(); + }, [isClient]); return (

Data Records

-

- View and manage data entries on the StoneProof platform. -

+

View and manage data entries on the StoneProof platform.

{isLoading ? (

Loading records...

) : (
    - {records.map((record) => ( + {records.map(record => (
  • {record.description}

    Owned by: {record.owner}

    diff --git a/packages/nextjs/components/header.tsx b/packages/nextjs/components/header.tsx index 76e7906..823aa3b 100644 --- a/packages/nextjs/components/header.tsx +++ b/packages/nextjs/components/header.tsx @@ -19,7 +19,7 @@ export const Header: React.FC = () => { if (!inView) { window.scroll({ behavior: "smooth", top: 0 }); } - }, []); + }, [inView]); const toggleMenu = () => { setIsMenuOpen(prev => !prev);