diff --git a/src/hooks/useIndexer.tsx b/src/hooks/useIndexer.tsx index 531a1cc..6c3d0d0 100644 --- a/src/hooks/useIndexer.tsx +++ b/src/hooks/useIndexer.tsx @@ -22,7 +22,7 @@ const useIndexer = () => { // check if the indexer has not been initialized const indexer = new CookieJarIndexer( storageEntities, - publicClient, + "https://rpc.ankr.com/gnosis", handleEvent ); await indexer.init(); diff --git a/src/utils/CookieJarIndexer.ts b/src/utils/CookieJarIndexer.ts index 2f56cea..51ddb4e 100644 --- a/src/utils/CookieJarIndexer.ts +++ b/src/utils/CookieJarIndexer.ts @@ -1,13 +1,12 @@ import { createIndexer, IdbStorage } from "chainsauce-web"; import type { EventHandler, Indexer } from "chainsauce-web"; import { Abi, PublicClient } from "viem"; -import { Contract, providers, utils } from "ethers"; -import { useEthersProvider } from "./ethersAdapters"; +import { Contract, utils, providers } from "ethers"; import { JsonFragment } from "@daohaus/utils"; interface CookieJarIndexerInterface { storage: IdbStorage; - publicClient: PublicClient; + rpc: string; eventHandler: EventHandler; indexer?: Indexer; init: () => Promise; @@ -21,24 +20,24 @@ interface CookieJarIndexerInterface { class CookieJarIndexer implements CookieJarIndexerInterface { storage: IdbStorage; - publicClient: PublicClient; + rpc: string; eventHandler: EventHandler; indexer?: Indexer; constructor( storageEntities: string[], - publicClient: PublicClient, + rpc: string, eventHandler: EventHandler ) { this.storage = new IdbStorage(storageEntities); - this.publicClient = publicClient; + this.rpc = rpc; this.eventHandler = eventHandler; } init = async () => { - const provider = useEthersProvider({ chainId: 100 }); + const provider = new providers.JsonRpcProvider(this.rpc, 100); this.indexer = await createIndexer( - provider as providers.JsonRpcProvider, + provider, this.storage, this.eventHandler ); diff --git a/src/utils/ethersAdapters.ts b/src/utils/ethersAdapters.ts index ec1d50d..6ad28a6 100644 --- a/src/utils/ethersAdapters.ts +++ b/src/utils/ethersAdapters.ts @@ -1,7 +1,5 @@ -import * as React from "react"; -import { type PublicClient, usePublicClient } from "wagmi"; +import { type PublicClient, getPublicClient } from "@wagmi/core"; import { providers } from "ethers"; -import { type HttpTransport } from "viem"; export function publicClientToProvider(publicClient: PublicClient) { const { chain, transport } = publicClient; @@ -10,20 +8,11 @@ export function publicClientToProvider(publicClient: PublicClient) { name: chain.name, ensAddress: chain.contracts?.ensRegistry?.address, }; - if (transport.type === "fallback") - return new providers.FallbackProvider( - (transport.transports as ReturnType[]).map( - ({ value }) => new providers.JsonRpcProvider(value?.url, network) - ) - ); return new providers.JsonRpcProvider(transport.url, network); } -/** Hook to convert a viem Public Client to an ethers.js Provider. */ -export function useEthersProvider({ chainId }: { chainId?: number } = {}) { - const publicClient = usePublicClient({ chainId }); - return React.useMemo( - () => publicClientToProvider(publicClient), - [publicClient] - ); +/** Action to convert a viem Public Client to an ethers.js Provider. */ +export function getEthersProvider({ chainId }: { chainId?: number } = {}) { + const publicClient = getPublicClient({ chainId }); + return publicClientToProvider(publicClient); }