diff --git a/README.md b/README.md index ee13dd5..ca3aba9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Fullstack Web3 Template v2.2.1 +# Fullstack Web3 Template v2.3.0 ## QuickStart diff --git a/ui/app/debug/_components/DebugContracts.tsx b/ui/app/debug/_components/DebugContracts.tsx index 5d16676..d2d5cba 100644 --- a/ui/app/debug/_components/DebugContracts.tsx +++ b/ui/app/debug/_components/DebugContracts.tsx @@ -6,6 +6,8 @@ import { BarsArrowUpIcon } from "@heroicons/react/20/solid"; import { ContractUI } from "~~/app/debug/_components/contract"; import { ContractName, GenericContract } from "~~/utils/fwt/contract"; import { useAllContracts } from "~~/utils/fwt/contractsData"; +import { useScaffoldWatchContractEvent } from "~~/hooks/scaffold-eth/useScaffoldWatchContractEvent"; +import { notification } from "~~/utils/fwt/notification"; const selectedContractStorageKey = "scaffoldEth2.selectedContract"; @@ -13,6 +15,34 @@ export function DebugContracts() { const contractsData = useAllContracts(); const contractNames = useMemo(() => Object.keys(contractsData) as ContractName[], [contractsData]); + contractNames.forEach(contractName => { + const contract = contractsData[contractName]; + if (contract && contract.abi) { + contract.abi.forEach(item => { + if (item.type === "event") { + useScaffoldWatchContractEvent({ + contractName: contractName, + eventName: item.name, + onLogs: logs => { + logs.forEach(log => { + const args = Object.entries(log.args) + .filter(([key]) => isNaN(Number(key))) + .map(([key, value]) => `${key}: ${value}`) + .join("\n"); + + notification.info( + `Event "${item.name}" triggered on ${contractName}: + ${args}`, + { duration: 6000 }, + ); + }); + }, + }); + } + }); + } + }); + const [selectedContract, setSelectedContract] = useLocalStorage( selectedContractStorageKey, contractNames[0], diff --git a/ui/app/debug/page.tsx b/ui/app/debug/page.tsx index 2a6f054..64837aa 100644 --- a/ui/app/debug/page.tsx +++ b/ui/app/debug/page.tsx @@ -2,25 +2,8 @@ import { DebugContracts } from "./_components/DebugContracts"; import type { NextPage } from "next"; -import { useScaffoldWatchContractEvent } from "~~/hooks/scaffold-eth/useScaffoldWatchContractEvent"; -import { notification } from "~~/utils/fwt/notification"; const Debug: NextPage = () => { - useScaffoldWatchContractEvent({ - contractName: "Counter", - eventName: "YouCall", - onLogs: logs => { - logs.forEach(log => { - notification.info( - `Event YouCall triggered: - Caller: ${log.args.caller} - Amount: ${log.args.amount} wei`, - { duration: 6000 } - ); - }); - }, - }); - return ( <> diff --git a/ui/contracts/deployedContracts.ts b/ui/contracts/deployedContracts.ts index 0283369..a1adc48 100644 --- a/ui/contracts/deployedContracts.ts +++ b/ui/contracts/deployedContracts.ts @@ -2,7 +2,7 @@ import { GenericContractsDeclaration } from "~~/utils/fwt/contract"; const deployedContracts = { - 31337: {"Counter": {"address": "0x610178da211fef7d417bc0e6fed39f05609ad788", "abi": [{"type": "function", "name": "getError", "inputs": [], "outputs": [], "stateMutability": "pure"}, {"type": "function", "name": "increment", "inputs": [], "outputs": [], "stateMutability": "nonpayable"}, {"type": "function", "name": "number", "inputs": [], "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}], "stateMutability": "view"}, {"type": "function", "name": "setNumber", "inputs": [{"name": "newNumber", "type": "uint256", "internalType": "uint256"}], "outputs": [], "stateMutability": "nonpayable"}, {"type": "function", "name": "withdraw", "inputs": [{"name": "amount", "type": "uint256", "internalType": "uint256"}], "outputs": [], "stateMutability": "pure"}, {"type": "error", "name": "CustomError", "inputs": [{"name": "message", "type": "string", "internalType": "string"}]}, {"type": "error", "name": "InsufficientBalance", "inputs": [{"name": "available", "type": "uint256", "internalType": "uint256"}, {"name": "required", "type": "uint256", "internalType": "uint256"}]}]}} + 31337: {"Counter": {"address": "0x9e545e3c0baab3e08cdfd552c960a1050f373042", "abi": [{"type": "function", "name": "getError", "inputs": [{"name": "yourAmount", "type": "uint256", "internalType": "uint256"}], "outputs": [{"name": "", "type": "string", "internalType": "string"}], "stateMutability": "pure"}, {"type": "function", "name": "increment", "inputs": [], "outputs": [], "stateMutability": "nonpayable"}, {"type": "function", "name": "launchEvent", "inputs": [], "outputs": [], "stateMutability": "payable"}, {"type": "function", "name": "number", "inputs": [], "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}], "stateMutability": "view"}, {"type": "function", "name": "setNumber", "inputs": [{"name": "newNumber", "type": "uint256", "internalType": "uint256"}], "outputs": [], "stateMutability": "nonpayable"}, {"type": "function", "name": "youETHBalance", "inputs": [], "outputs": [], "stateMutability": "nonpayable"}, {"type": "event", "name": "YouCall", "inputs": [{"name": "caller", "type": "address", "indexed": false, "internalType": "address"}, {"name": "amount", "type": "uint256", "indexed": false, "internalType": "uint256"}], "anonymous": false}, {"type": "event", "name": "YourBalance", "inputs": [{"name": "caller", "type": "address", "indexed": false, "internalType": "address"}, {"name": "amount", "type": "uint256", "indexed": false, "internalType": "uint256"}], "anonymous": false}, {"type": "error", "name": "CustomError", "inputs": [{"name": "message", "type": "string", "internalType": "string"}, {"name": "yourAmount", "type": "uint256", "internalType": "uint256"}]}]}} } as const; export default deployedContracts satisfies GenericContractsDeclaration;