Skip to content

Commit

Permalink
Fix #5 - checked in counter (#25)
Browse files Browse the repository at this point in the history
* replace img with nextjs Image component

* Hotfix: fix linting issue

* add CheckInCounter component to read contract variable checkedInCounter

* fix: add dependencies to useEffect to avoid infinite chain of updates
  • Loading branch information
RafaelCaso authored and benhur committed Aug 22, 2024
1 parent b246d7e commit 3bc413d
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)));
}
}, [checkInError, checkInLoading, checkedIn]);

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

export default CheckInCount;

0 comments on commit 3bc413d

Please sign in to comment.