diff --git a/packages/explorer/src/app/(explorer)/api/world-abi/route.ts b/packages/explorer/src/app/(explorer)/api/world-abi/route.ts index c8ff66429a..94bc556207 100644 --- a/packages/explorer/src/app/(explorer)/api/world-abi/route.ts +++ b/packages/explorer/src/app/(explorer)/api/world-abi/route.ts @@ -5,12 +5,12 @@ import { fetchBlockLogs } from "@latticexyz/block-logs-stream"; import { helloStoreEvent } from "@latticexyz/store"; import { getWorldAbi } from "@latticexyz/store-sync/world"; import { helloWorldEvent } from "@latticexyz/world"; -import { chainIdToName, supportedChainId, supportedChains, validateChainId } from "../../../../common"; +import { getChainById, supportedChainId, validateChainId } from "../../../../common"; export const dynamic = "force-dynamic"; async function getClient(chainId: supportedChainId) { - const chain = supportedChains[chainIdToName[chainId]]; // TODO: fix types + const chain = getChainById(chainId); const client = createClient({ chain, transport: http(), @@ -20,7 +20,7 @@ async function getClient(chainId: supportedChainId) { } function getIndexerUrl(chainId: supportedChainId) { - const chain = supportedChains[chainIdToName[chainId]!]; // TODO: fix types + const chain = getChainById(chainId); return "indexerUrl" in chain ? chain.indexerUrl : undefined; } diff --git a/packages/explorer/src/bin/explorer.ts b/packages/explorer/src/bin/explorer.ts index 6ba11ccc58..99a464528a 100755 --- a/packages/explorer/src/bin/explorer.ts +++ b/packages/explorer/src/bin/explorer.ts @@ -125,7 +125,7 @@ async function startStoreIndexer() { await rm(indexerDatabasePath, { recursive: true, force: true }); - console.log("Running SQLite indexer for anvil..."); // TODO: running for custom chain + console.log("Running SQLite indexer..."); // TODO: running for custom chain indexerProcess = spawn("sh", ["node_modules/.bin/sqlite-indexer"], { cwd: packageRoot, stdio: "inherit", diff --git a/packages/explorer/src/common.ts b/packages/explorer/src/common.ts index 080398a769..8a45be4d4a 100644 --- a/packages/explorer/src/common.ts +++ b/packages/explorer/src/common.ts @@ -55,6 +55,16 @@ export const getChain = (chainName: supportedChainName | string) => { return null; }; +export const getChainById = (chainId: supportedChainId | number) => { + if (chainId === customChain?.id) { + return customChain; + } else if (chainId in supportedChains) { + // @ts-expect-error ignore for now TODO: fix types + return supportedChains[chainId]; + } + return null; +}; + export const chainIdToName = Object.fromEntries( Object.entries(supportedChains).map(([chainName, chain]) => [chain.id, chainName]), ) as Record;