-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
b246d7e
commit 3bc413d
Showing
2 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |