Skip to content

Commit

Permalink
add CheckInCounter component to read contract variable checkedInCounter
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelCaso committed Aug 19, 2024
1 parent 4be1a51 commit 70c060b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import Link from "next/link";
import CheckedInCounter from "../components/CheckedInCounter";
import type { NextPage } from "next";
import { BugAntIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline";

Expand All @@ -15,8 +16,7 @@ const Home: NextPage = () => {
</h1>
<p className="text-center text-lg">Get started by taking a look at your batch GitHub repository.</p>
<p className="text-lg flex gap-2 justify-center">
<span className="font-bold">Checked in builders count:</span>
<span>To Be Implemented</span>
<CheckedInCounter />
</p>
</div>

Expand Down
34 changes: 34 additions & 0 deletions packages/nextjs/components/CheckedInCounter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useEffect, useState } from "react";
import { useScaffoldReadContract } from "~~/hooks/scaffold-eth";

const CheckInCount = () => {
const [feedback, setFeedback] = useState<string>("");
const [result, setResult] = useState<string>();

const {
data: checkedIn,
isLoading: checkInLoading,
error: checkInError,
} = useScaffoldReadContract({
contractName: "BatchRegistry",
functionName: "checkedInCounter",
});

useEffect(() => {
if (checkInError) {
setFeedback("Something went wrong");
console.error(checkInError);
} else {
setResult(checkInLoading ? "..." : String(Number(checkedIn)));
}
});

return (
<>
<span className="font-bold">Checked in builders count: {result}</span>
{feedback && <p>{feedback}</p>}
</>
);
};

export default CheckInCount;

0 comments on commit 70c060b

Please sign in to comment.