From c1ee5b6d85c54a7ee735ae2cf887807d7adb5ad5 Mon Sep 17 00:00:00 2001 From: Rinat Date: Sun, 28 Apr 2024 16:08:15 +0200 Subject: [PATCH 1/6] Update useScaffoldEventHistory hook (#827) * refactor: useScaffoldEventHistory * fix: return readEvents useEffect * fix: disabled mode --- .../scaffold-eth/useScaffoldEventHistory.ts | 154 +++++++++--------- 1 file changed, 75 insertions(+), 79 deletions(-) diff --git a/packages/nextjs/hooks/scaffold-eth/useScaffoldEventHistory.ts b/packages/nextjs/hooks/scaffold-eth/useScaffoldEventHistory.ts index 7dc0e3deb..869bb5c11 100644 --- a/packages/nextjs/hooks/scaffold-eth/useScaffoldEventHistory.ts +++ b/packages/nextjs/hooks/scaffold-eth/useScaffoldEventHistory.ts @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useState } from "react"; +import { useCallback, useEffect, useMemo, useState } from "react"; import { useTargetNetwork } from "./useTargetNetwork"; import { Abi, AbiEvent, ExtractAbiEventNames } from "abitype"; import { useInterval } from "usehooks-ts"; @@ -45,7 +45,7 @@ export const useScaffoldEventHistory = < watch, enabled = true, }: UseScaffoldEventHistoryConfig) => { - const [events, setEvents] = useState(); + const [events, setEvents] = useState([]); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(); const [fromBlockUpdated, setFromBlockUpdated] = useState(fromBlock); @@ -56,95 +56,91 @@ export const useScaffoldEventHistory = < chainId: targetNetwork.id, }); - const readEvents = async (fromBlock?: bigint) => { - setIsLoading(true); - try { - if (!deployedContractData) { - throw new Error("Contract not found"); - } + const readEvents = useCallback( + async () => { + setIsLoading(true); + try { + if (!deployedContractData) { + throw new Error("Contract not found"); + } - if (!enabled) { - throw new Error("Hook disabled"); - } + if (!enabled) { + throw new Error("Hook disabled"); + } - if (!publicClient) { - throw new Error("Public client not found"); - } + if (!publicClient) { + throw new Error("Public client not found"); + } + + const event = (deployedContractData.abi as Abi).find( + part => part.type === "event" && part.name === eventName, + ) as AbiEvent; - const event = (deployedContractData.abi as Abi).find( - part => part.type === "event" && part.name === eventName, - ) as AbiEvent; - - const blockNumber = await publicClient.getBlockNumber({ cacheTime: 0 }); - - if ((fromBlock && blockNumber >= fromBlock) || blockNumber >= fromBlockUpdated) { - const logs = await publicClient.getLogs({ - address: deployedContractData?.address, - event, - args: filters as any, - fromBlock: fromBlock || fromBlockUpdated, - toBlock: blockNumber, - }); - setFromBlockUpdated(blockNumber + 1n); - - const newEvents = []; - for (let i = logs.length - 1; i >= 0; i--) { - newEvents.push({ - log: logs[i], - args: logs[i].args, - block: - blockData && logs[i].blockHash === null - ? null - : await publicClient.getBlock({ blockHash: logs[i].blockHash as Hash }), - transaction: - transactionData && logs[i].transactionHash !== null - ? await publicClient.getTransaction({ hash: logs[i].transactionHash as Hash }) - : null, - receipt: - receiptData && logs[i].transactionHash !== null - ? await publicClient.getTransactionReceipt({ hash: logs[i].transactionHash as Hash }) - : null, + const blockNumber = await publicClient.getBlockNumber({ cacheTime: 0 }); + + if (blockNumber >= fromBlockUpdated) { + const logs = await publicClient.getLogs({ + address: deployedContractData?.address, + event, + args: filters as any, + fromBlock: fromBlockUpdated, + toBlock: blockNumber, }); - } - if (events && typeof fromBlock === "undefined") { + setFromBlockUpdated(blockNumber + 1n); + + const newEvents = []; + for (let i = logs.length - 1; i >= 0; i--) { + newEvents.push({ + log: logs[i], + args: logs[i].args, + block: + blockData && logs[i].blockHash === null + ? null + : await publicClient.getBlock({ blockHash: logs[i].blockHash as Hash }), + transaction: + transactionData && logs[i].transactionHash !== null + ? await publicClient.getTransaction({ hash: logs[i].transactionHash as Hash }) + : null, + receipt: + receiptData && logs[i].transactionHash !== null + ? await publicClient.getTransactionReceipt({ hash: logs[i].transactionHash as Hash }) + : null, + }); + } setEvents([...newEvents, ...events]); - } else { - setEvents(newEvents); + setError(undefined); } - setError(undefined); + } catch (e: any) { + if (events.length > 0) { + setEvents([]); + } + setError(e); + console.error(e); + } finally { + setIsLoading(false); } - } catch (e: any) { - console.error(e); - setEvents(undefined); - setError(e); - } finally { - setIsLoading(false); - } - }; - - useEffect(() => { - readEvents(fromBlock); + }, // eslint-disable-next-line react-hooks/exhaustive-deps - }, [fromBlock, enabled]); + [ + blockData, + deployedContractData, + enabled, + eventName, + events, + // eslint-disable-next-line react-hooks/exhaustive-deps + JSON.stringify(filters, replacer), + fromBlockUpdated, + publicClient, + receiptData, + transactionData, + ], + ); useEffect(() => { if (!deployedContractLoading) { readEvents(); } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [ - publicClient, - contractName, - eventName, - deployedContractLoading, - deployedContractData?.address, - deployedContractData, - // eslint-disable-next-line react-hooks/exhaustive-deps - JSON.stringify(filters, replacer), - blockData, - transactionData, - receiptData, - ]); + }, [readEvents, deployedContractLoading]); useEffect(() => { // Reset the internal state when target network or fromBlock changed @@ -159,7 +155,7 @@ export const useScaffoldEventHistory = < readEvents(); } }, - watch ? (targetNetwork.id !== chains.hardhat.id ? scaffoldConfig.pollingInterval : 4_000) : null, + watch && enabled ? (targetNetwork.id !== chains.hardhat.id ? scaffoldConfig.pollingInterval : 4_000) : null, ); const eventHistoryData = useMemo( From 076a9dec379b1095c0223e2a8ffefa09842f3553 Mon Sep 17 00:00:00 2001 From: Rinat Date: Mon, 29 Apr 2024 21:28:09 +0200 Subject: [PATCH 2/6] fix: types typo (#830) --- packages/nextjs/components/SwitchTheme.tsx | 10 ++++------ .../hooks/scaffold-eth/useScaffoldWriteContract.ts | 12 ++++++------ packages/nextjs/utils/scaffold-eth/contract.ts | 4 ++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/nextjs/components/SwitchTheme.tsx b/packages/nextjs/components/SwitchTheme.tsx index 0c2a63819..4dc20af90 100644 --- a/packages/nextjs/components/SwitchTheme.tsx +++ b/packages/nextjs/components/SwitchTheme.tsx @@ -33,12 +33,10 @@ export const SwitchTheme = ({ className }: { className?: string }) => { onChange={handleToggle} checked={isDarkMode} /> - { - - } + ); }; diff --git a/packages/nextjs/hooks/scaffold-eth/useScaffoldWriteContract.ts b/packages/nextjs/hooks/scaffold-eth/useScaffoldWriteContract.ts index f5ff161bf..4bd903f7f 100644 --- a/packages/nextjs/hooks/scaffold-eth/useScaffoldWriteContract.ts +++ b/packages/nextjs/hooks/scaffold-eth/useScaffoldWriteContract.ts @@ -10,8 +10,8 @@ import { notification } from "~~/utils/scaffold-eth"; import { ContractAbi, ContractName, - scaffoldWriteContractOptions, - scaffoldWriteContractVariables, + ScaffoldWriteContractOptions, + ScaffoldWriteContractVariables, } from "~~/utils/scaffold-eth/contract"; /** @@ -36,8 +36,8 @@ export const useScaffoldWriteContract = ( const sendContractWriteAsyncTx = async < TFunctionName extends ExtractAbiFunctionNames, "nonpayable" | "payable">, >( - variables: scaffoldWriteContractVariables, - options?: scaffoldWriteContractOptions, + variables: ScaffoldWriteContractVariables, + options?: ScaffoldWriteContractOptions, ) => { if (!deployedContractData) { notification.error("Target Contract is not deployed, did you forget to run `yarn deploy`?"); @@ -86,8 +86,8 @@ export const useScaffoldWriteContract = ( TContractName extends ContractName, TFunctionName extends ExtractAbiFunctionNames, "nonpayable" | "payable">, >( - variables: scaffoldWriteContractVariables, - options?: Omit, + variables: ScaffoldWriteContractVariables, + options?: Omit, ) => { if (!deployedContractData) { notification.error("Target Contract is not deployed, did you forget to run `yarn deploy`?"); diff --git a/packages/nextjs/utils/scaffold-eth/contract.ts b/packages/nextjs/utils/scaffold-eth/contract.ts index e805c79b5..2c5a3e8a4 100644 --- a/packages/nextjs/utils/scaffold-eth/contract.ts +++ b/packages/nextjs/utils/scaffold-eth/contract.ts @@ -179,7 +179,7 @@ export type UseScaffoldReadConfig< Omit >; -export type scaffoldWriteContractVariables< +export type ScaffoldWriteContractVariables< TContractName extends ContractName, TFunctionName extends ExtractAbiFunctionNames, WriteAbiStateMutability>, > = IsContractDeclarationMissing< @@ -197,7 +197,7 @@ export type TransactorFuncOptions = { blockConfirmations?: number; }; -export type scaffoldWriteContractOptions = MutateOptions< +export type ScaffoldWriteContractOptions = MutateOptions< WriteContractReturnType, WriteContractErrorType, WriteVariables, From 0abf227e0f7faab860c87b9d718ba74e3fed6ea0 Mon Sep 17 00:00:00 2001 From: "Shiv Bhonde | shivbhonde.eth" Date: Wed, 1 May 2024 09:57:47 +0530 Subject: [PATCH 3/6] use burner-connector package (#831) --- packages/nextjs/package.json | 1 + .../web3/wagmi-burner/burnerWalletConfig.ts | 37 ----- .../wagmi-burner/createBurnerConnector.ts | 153 ------------------ .../nextjs/services/web3/wagmiConnectors.tsx | 4 +- yarn.lock | 52 +++--- 5 files changed, 35 insertions(+), 212 deletions(-) delete mode 100644 packages/nextjs/services/web3/wagmi-burner/burnerWalletConfig.ts delete mode 100644 packages/nextjs/services/web3/wagmi-burner/createBurnerConnector.ts diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index a89300994..1b24a1b53 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -20,6 +20,7 @@ "@uniswap/sdk-core": "^4.0.1", "@uniswap/v2-sdk": "^3.0.1", "blo": "^1.0.1", + "burner-connector": "^0.0.3", "daisyui": "4.5.0", "next": "^14.0.4", "next-themes": "^0.2.1", diff --git a/packages/nextjs/services/web3/wagmi-burner/burnerWalletConfig.ts b/packages/nextjs/services/web3/wagmi-burner/burnerWalletConfig.ts deleted file mode 100644 index b00ff7427..000000000 --- a/packages/nextjs/services/web3/wagmi-burner/burnerWalletConfig.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Chain, Wallet } from "@rainbow-me/rainbowkit"; -import { hardhat } from "viem/chains"; -import scaffoldConfig from "~~/scaffold.config"; -import { - burnerWalletId, - burnerWalletName, - createBurnerConnector, -} from "~~/services/web3/wagmi-burner/createBurnerConnector"; -import { getTargetNetworks } from "~~/utils/scaffold-eth"; - -const { onlyLocalBurnerWallet } = scaffoldConfig; -const targetNetworks = getTargetNetworks(); - -export type BurnerWalletOptions = { - chains: Chain[]; -}; - -const burnerWalletIconBase64 = - "data:image/svg+xml;base64,PHN2ZyB3aWR0aD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N0b3Agc3RvcC1jb2xvcj0iI0ZGRjI3OSIvPgo8c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiNGRkQzMzYiLz4KPC9saW5lYXJHcmFkaWVudD4KPHJhZGlhbEdyYWRpZW50IGlkPSJwYWludDFfcmFkaWFsXzNfMTUxIiBjeD0iMCIgY3k9IjAiIHI9IjEiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIiBncmFkaWVudFRyYW5zZm9ybT0idHJhbnNsYXRlKDIxOC4wNDggMjQ5LjM0Nykgcm90YXRlKDEyNC4wMTgpIHNjYWxlKDg5LjI5NTUgMjY0LjgwOSkiPgo8c3RvcCBvZmZzZXQ9IjAuNjQwODUiIHN0b3AtY29sb3I9IiNGRjY2MEEiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjRkZCRTE1Ii8+CjwvcmFkaWFsR3JhZGllbnQ+CjxsaW5lYXJHcmFkaWVudCBpZD0icGFpbnQyX2xpbmVhcl8zXzE1MSIgeDE9IjE3Ni40ODIiIHkxPSI0MC4xODQxIiB4Mj0iMTc2LjQ4MiIgeTI9IjMxNy4yNzgiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIj4KPHN0b3Agb2Zmc2V0PSIwLjMzODU0MiIgc3RvcC1jb2xvcj0iI0ZGOEYzRiIvPgo8c3RvcCBvZmZzZXQ9IjAuNjU2MjUiIHN0b3AtY29sb3I9IiNGRjcwMjAiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjRkYzRDAwIi8+CjwvbGluZWFyR3JhZGllbnQ+CjwvZGVmcz4KPC9zdmc+Cg=="; - -/** - * Wagmi config for burner wallet - */ -export const burnerWalletConfig = (): Wallet => ({ - id: burnerWalletId, - name: burnerWalletName, - iconUrl: burnerWalletIconBase64, - iconBackground: "#ffffff", - hidden: () => { - if (onlyLocalBurnerWallet) { - return targetNetworks.some(({ id }) => id !== hardhat.id); - } - - return false; - }, - createConnector: createBurnerConnector, -}); diff --git a/packages/nextjs/services/web3/wagmi-burner/createBurnerConnector.ts b/packages/nextjs/services/web3/wagmi-burner/createBurnerConnector.ts deleted file mode 100644 index de53737b6..000000000 --- a/packages/nextjs/services/web3/wagmi-burner/createBurnerConnector.ts +++ /dev/null @@ -1,153 +0,0 @@ -import { WalletDetailsParams } from "@rainbow-me/rainbowkit"; -import { createConnector, normalizeChainId } from "@wagmi/core"; -import { - EIP1193RequestFn, - Hex, - RpcRequestError, - SwitchChainError, - Transport, - WalletRpcSchema, - createWalletClient, - custom, - fromHex, - getAddress, - http, -} from "viem"; -import { privateKeyToAccount } from "viem/accounts"; -import { getHttpRpcClient, hexToBigInt, numberToHex } from "viem/utils"; -import { SendTransactionParameters } from "viem/zksync"; -import { BaseError } from "wagmi"; -import { loadBurnerSK } from "~~/hooks/scaffold-eth"; - -export const burnerWalletId = "burnerWallet"; -export const burnerWalletName = "Burner Wallet"; - -export class ConnectorNotConnectedError extends BaseError { - override name = "ConnectorNotConnectedError"; - constructor() { - super("Connector not connected."); - } -} - -export class ChainNotConfiguredError extends BaseError { - override name = "ChainNotConfiguredError"; - constructor() { - super("Chain not configured."); - } -} - -type Provider = ReturnType, EIP1193RequestFn>>; - -export const createBurnerConnector = (walletDetails: WalletDetailsParams) => { - let connected = true; - let connectedChainId: number; - return createConnector(config => ({ - id: burnerWalletId, - name: burnerWalletName, - type: "burnerWallet", - async connect({ chainId } = {}) { - const provider = await this.getProvider(); - const accounts = await provider.request({ - method: "eth_accounts", - }); - let currentChainId = await this.getChainId(); - if (chainId && currentChainId !== chainId && this.switchChain) { - const chain = await this.switchChain({ chainId }); - currentChainId = chain.id; - } - connected = true; - return { accounts, chainId: currentChainId }; - }, - async getProvider({ chainId } = {}) { - const chain = config.chains.find(x => x.id === chainId) ?? config.chains[0]; - - const url = chain.rpcUrls.default.http[0]; - const burnerAccount = privateKeyToAccount(loadBurnerSK()); - const client = createWalletClient({ - chain: chain, - account: burnerAccount, - transport: http(), - }); - - const request: EIP1193RequestFn = async ({ method, params }) => { - if (method === "eth_sendTransaction") { - const actualParams = (params as SendTransactionParameters[])[0]; - const value = actualParams.value ? hexToBigInt(actualParams.value as unknown as Hex) : undefined; - const hash = await client.sendTransaction({ - ...(params as SendTransactionParameters[])[0], - value, - }); - return hash; - } - - if (method === "eth_accounts") { - return [burnerAccount.address]; - } - - if (method === "wallet_switchEthereumChain") { - type Params = [{ chainId: Hex }]; - connectedChainId = fromHex((params as Params)[0].chainId, "number"); - this.onChainChanged(connectedChainId.toString()); - return; - } - - const body = { method, params }; - const httpClient = getHttpRpcClient(url); - const { error, result } = await httpClient.request({ body }); - if (error) throw new RpcRequestError({ body, error, url }); - - return result; - }; - - return custom({ request })({ retryCount: 0 }); - }, - onChainChanged(chain) { - const chainId = normalizeChainId(chain); - config.emitter.emit("change", { chainId }); - }, - async getAccounts() { - if (!connected) throw new ConnectorNotConnectedError(); - const provider = await this.getProvider(); - const accounts = await provider.request({ method: "eth_accounts" }); - return [accounts.map(x => getAddress(x))[0]]; - }, - async onDisconnect() { - config.emitter.emit("disconnect"); - connected = false; - }, - async getChainId() { - const provider = await this.getProvider(); - const hexChainId = await provider.request({ method: "eth_chainId" }); - return fromHex(hexChainId, "number"); - }, - async isAuthorized() { - if (!connected) return false; - const accounts = await this.getAccounts(); - return !!accounts.length; - }, - onAccountsChanged(accounts) { - if (accounts.length === 0) this.onDisconnect(); - else - config.emitter.emit("change", { - accounts: accounts.map(x => getAddress(x)), - }); - }, - async switchChain({ chainId }) { - const provider = await this.getProvider(); - const chain = config.chains.find(x => x.id === chainId); - if (!chain) throw new SwitchChainError(new ChainNotConfiguredError()); - - await provider.request({ - method: "wallet_switchEthereumChain", - params: [{ chainId: numberToHex(chainId) }], - }); - return chain; - }, - disconnect() { - console.log("disconnect from burnerwallet"); - connected = false; - return Promise.resolve(); - }, - ...walletDetails, - })); -}; diff --git a/packages/nextjs/services/web3/wagmiConnectors.tsx b/packages/nextjs/services/web3/wagmiConnectors.tsx index 90d52cabb..816799649 100644 --- a/packages/nextjs/services/web3/wagmiConnectors.tsx +++ b/packages/nextjs/services/web3/wagmiConnectors.tsx @@ -1,4 +1,3 @@ -import { burnerWalletConfig } from "./wagmi-burner/burnerWalletConfig"; import { connectorsForWallets } from "@rainbow-me/rainbowkit"; import { coinbaseWallet, @@ -8,6 +7,7 @@ import { safeWallet, walletConnectWallet, } from "@rainbow-me/rainbowkit/wallets"; +import { rainbowkitBurnerWallet } from "burner-connector"; import * as chains from "viem/chains"; import scaffoldConfig from "~~/scaffold.config"; @@ -21,7 +21,7 @@ const wallets = [ rainbowWallet, safeWallet, ...(!targetNetworks.some(network => network.id !== (chains.hardhat as chains.Chain).id) || !onlyLocalBurnerWallet - ? [burnerWalletConfig] + ? [rainbowkitBurnerWallet] : []), ]; diff --git a/yarn.lock b/yarn.lock index c664a2e64..d0f4d6a04 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2060,7 +2060,7 @@ __metadata: languageName: node linkType: hard -"@rainbow-me/rainbowkit@npm:^2.0.2": +"@rainbow-me/rainbowkit@npm:2.0.2, @rainbow-me/rainbowkit@npm:^2.0.2": version: 2.0.2 resolution: "@rainbow-me/rainbowkit@npm:2.0.2" dependencies: @@ -2260,6 +2260,7 @@ __metadata: abitype: ^1.0.2 autoprefixer: ^10.4.12 blo: ^1.0.1 + burner-connector: ^0.0.3 daisyui: 4.5.0 eslint: ^8.15.0 eslint-config-next: ^14.0.4 @@ -4899,6 +4900,17 @@ __metadata: languageName: node linkType: hard +"burner-connector@npm:^0.0.3": + version: 0.0.3 + resolution: "burner-connector@npm:0.0.3" + dependencies: + "@rainbow-me/rainbowkit": 2.0.2 + "@wagmi/core": 2.6.9 + viem: 2.8.16 + checksum: 6041e4aab56af02a01ab211cf278d8babd047db43f4ab43fdb7b9dfd8704d35cbb7da2af240de8b9c782b805031ef43c5788bd0594191b2508f2679dd3ff5041 + languageName: node + linkType: hard + "busboy@npm:1.6.0, busboy@npm:^1.6.0": version: 1.6.0 resolution: "busboy@npm:1.6.0" @@ -14633,59 +14645,59 @@ __metadata: languageName: node linkType: hard -"viem@npm:^1.0.0": - version: 1.12.2 - resolution: "viem@npm:1.12.2" +"viem@npm:2.8.16, viem@npm:^2.8.16": + version: 2.8.16 + resolution: "viem@npm:2.8.16" dependencies: - "@adraffy/ens-normalize": 1.9.4 + "@adraffy/ens-normalize": 1.10.0 "@noble/curves": 1.2.0 "@noble/hashes": 1.3.2 "@scure/bip32": 1.3.2 "@scure/bip39": 1.2.1 - "@types/ws": ^8.5.5 - abitype: 0.9.8 - isomorphic-ws: 5.0.0 + abitype: 1.0.0 + isows: 1.0.3 ws: 8.13.0 peerDependencies: typescript: ">=5.0.4" peerDependenciesMeta: typescript: optional: true - checksum: 558bc2b46afb177a34356f3cc8e6e444f4a6bf4d8aa15658f95eecc1bb42bbc09f240a1fd8eae98fa4973c3a1dc34f0492034b4b4d182f65b2dadf80167c8cea + checksum: f58029cf1f39d662c51f4ebc9c71dc407522161bac2de1112170061d5bfe90ce1802bde701d567022dc1fd83d22ec4df031bcf55d943481159e50acf984292ae languageName: node linkType: hard -"viem@npm:^1.1.4": - version: 1.21.4 - resolution: "viem@npm:1.21.4" +"viem@npm:^1.0.0": + version: 1.12.2 + resolution: "viem@npm:1.12.2" dependencies: - "@adraffy/ens-normalize": 1.10.0 + "@adraffy/ens-normalize": 1.9.4 "@noble/curves": 1.2.0 "@noble/hashes": 1.3.2 "@scure/bip32": 1.3.2 "@scure/bip39": 1.2.1 + "@types/ws": ^8.5.5 abitype: 0.9.8 - isows: 1.0.3 + isomorphic-ws: 5.0.0 ws: 8.13.0 peerDependencies: typescript: ">=5.0.4" peerDependenciesMeta: typescript: optional: true - checksum: c351fdea2d53d2d781ac73c964348b3b9fc5dd46f9eb53903e867705fc9e30a893cb9f2c8d7a00acdcdeca27d14eeebf976eed9f948c28c47018dc9211369117 + checksum: 558bc2b46afb177a34356f3cc8e6e444f4a6bf4d8aa15658f95eecc1bb42bbc09f240a1fd8eae98fa4973c3a1dc34f0492034b4b4d182f65b2dadf80167c8cea languageName: node linkType: hard -"viem@npm:^2.8.16": - version: 2.8.16 - resolution: "viem@npm:2.8.16" +"viem@npm:^1.1.4": + version: 1.21.4 + resolution: "viem@npm:1.21.4" dependencies: "@adraffy/ens-normalize": 1.10.0 "@noble/curves": 1.2.0 "@noble/hashes": 1.3.2 "@scure/bip32": 1.3.2 "@scure/bip39": 1.2.1 - abitype: 1.0.0 + abitype: 0.9.8 isows: 1.0.3 ws: 8.13.0 peerDependencies: @@ -14693,7 +14705,7 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: f58029cf1f39d662c51f4ebc9c71dc407522161bac2de1112170061d5bfe90ce1802bde701d567022dc1fd83d22ec4df031bcf55d943481159e50acf984292ae + checksum: c351fdea2d53d2d781ac73c964348b3b9fc5dd46f9eb53903e867705fc9e30a893cb9f2c8d7a00acdcdeca27d14eeebf976eed9f948c28c47018dc9211369117 languageName: node linkType: hard From 8d75411b0d53d5877b4c379ce2c664ed39627beb Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Wed, 1 May 2024 10:06:56 +0530 Subject: [PATCH 4/6] add changeset --- .changeset/shiny-bugs-hug.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/shiny-bugs-hug.md diff --git a/.changeset/shiny-bugs-hug.md b/.changeset/shiny-bugs-hug.md new file mode 100644 index 000000000..60feee71b --- /dev/null +++ b/.changeset/shiny-bugs-hug.md @@ -0,0 +1,7 @@ +--- +"create-eth": patch +--- + +- use burner-connector package +- Update useScaffoldEventHistory hook +- fix: types typo From 69fe824fea72ccd748472d32a45e8dab4955dde0 Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Wed, 1 May 2024 13:36:15 +0530 Subject: [PATCH 5/6] use ~ instead of ^ for burner-connector --- templates/base/packages/nextjs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/base/packages/nextjs/package.json b/templates/base/packages/nextjs/package.json index 442d02eb9..3ec055b17 100644 --- a/templates/base/packages/nextjs/package.json +++ b/templates/base/packages/nextjs/package.json @@ -20,7 +20,7 @@ "@uniswap/sdk-core": "~4.0.1", "@uniswap/v2-sdk": "~3.0.1", "blo": "~1.0.1", - "burner-connector": "^0.0.3", + "burner-connector": "~0.0.3", "daisyui": "4.5.0", "next": "~14.0.4", "next-themes": "~0.2.1", From d25d38f0a32c9ab59d2403ff488f1542d8617ca1 Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Wed, 1 May 2024 14:18:14 +0530 Subject: [PATCH 6/6] move TransactionComp inside base --- .../transaction/[txHash]}/_components/TransactionComp.tsx | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {packages/nextjs/app/blockexplorer/transaction => templates/base/packages/nextjs/app/blockexplorer/transaction/[txHash]}/_components/TransactionComp.tsx (100%) diff --git a/packages/nextjs/app/blockexplorer/transaction/_components/TransactionComp.tsx b/templates/base/packages/nextjs/app/blockexplorer/transaction/[txHash]/_components/TransactionComp.tsx similarity index 100% rename from packages/nextjs/app/blockexplorer/transaction/_components/TransactionComp.tsx rename to templates/base/packages/nextjs/app/blockexplorer/transaction/[txHash]/_components/TransactionComp.tsx