diff --git a/packages/nextjs/app/_components/BuildersCheckInCount.tsx b/packages/nextjs/app/_components/BuildersCheckInCount.tsx index ba5cfcb..b971df9 100644 --- a/packages/nextjs/app/_components/BuildersCheckInCount.tsx +++ b/packages/nextjs/app/_components/BuildersCheckInCount.tsx @@ -1,24 +1,41 @@ -"use client"; - -import React from "react"; import { CounterDisplay } from "./CounterDisplay"; -import { useScaffoldReadContract } from "~~/hooks/scaffold-eth"; +import { createPublicClient, getContract, http } from "viem"; +import { optimism } from "viem/chains"; -const CONTRACT_NAME = "BatchRegistry"; +const CONTRACT_ADR = "0x72ccAbE6620fa94eC69569d17f18a3914BEFBFD6"; const FUNCTION_NAME = "checkedInCounter"; -function BuildersCheckInCount() { - // Get the result of the target function call from the deployed contract - const { - data: counter, - isLoading, - error, - } = useScaffoldReadContract({ - contractName: CONTRACT_NAME, - functionName: FUNCTION_NAME, - }); +// Defining the ABI for just the function we need +const BatchRegistryABI = [ + { + name: FUNCTION_NAME, + type: "function", + stateMutability: "view", + inputs: [], + outputs: [{ type: "uint256" }], + }, +] as const; + +async function BuildersCheckInCount() { + try { + // A Client in the context of viem is similar to an Ethers.js Provider. + const publicClient = createPublicClient({ + chain: optimism, + transport: http(), + }); + + const contract = getContract({ + address: CONTRACT_ADR, + abi: BatchRegistryABI, + client: publicClient, + }); + + const counter = await contract.read.checkedInCounter(); - return ; + return ; + } catch (error) { + return ; + } } export default BuildersCheckInCount; diff --git a/packages/nextjs/app/_components/CounterDisplay.tsx b/packages/nextjs/app/_components/CounterDisplay.tsx index f0a8b44..2d5c84a 100644 --- a/packages/nextjs/app/_components/CounterDisplay.tsx +++ b/packages/nextjs/app/_components/CounterDisplay.tsx @@ -1,25 +1,11 @@ -import { displayTxResult } from "../debug/_components/contract"; -import { ArrowPathIcon } from "@heroicons/react/16/solid"; - -export async function CounterDisplay({ - data: counter, - isLoading, - error, -}: { - data?: bigint; - isLoading: boolean; - error: Error | null; -}) { +export async function CounterDisplay({ data: counter, error }: { data?: bigint; error: Error | null }) { return (
Checked in builders count: - {isLoading || (!error && !counter) ? ( - - ) : error ? ( - Error! - ) : ( - {displayTxResult(counter)} - )} + + {error && Error!} + + {counter && {counter.toString()}}
); } diff --git a/packages/nextjs/app/page.tsx b/packages/nextjs/app/page.tsx index c50f6ab..0ea8fcb 100644 --- a/packages/nextjs/app/page.tsx +++ b/packages/nextjs/app/page.tsx @@ -1,8 +1,7 @@ -import { Suspense } from "react"; import Link from "next/link"; import BuildersCheckInCount from "./_components/BuildersCheckInCount"; import type { NextPage } from "next"; -import { ArrowPathIcon, BugAntIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; +import { BugAntIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; const Home: NextPage = () => { return ( @@ -14,9 +13,7 @@ const Home: NextPage = () => { Batch 12

Get started by taking a look at your batch GitHub repository.

- }> - - +
@@ -49,11 +46,3 @@ const Home: NextPage = () => { }; export default Home; -function LoadingCounter() { - return ( -
- Checked in builders count: - -
- ); -}