Skip to content

Commit

Permalink
Match specific headless client 🐼
Browse files Browse the repository at this point in the history
  • Loading branch information
Kooshaba committed Feb 22, 2024
1 parent 6bebd4b commit 6d3dfea
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
3 changes: 1 addition & 2 deletions packages/client/src/mud/getBrowserNetworkConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getBurnerWallet } from "../getBurnerWallet";
import { Wallet } from "ethers";
import { getChain, getWorldFromChainId } from "./utils";
import { Hex } from "viem";
import { Entity } from "@latticexyz/recs";
import { redstoneHolesky } from "./supportedChains";

Expand All @@ -26,7 +25,7 @@ export async function getNetworkConfig() {

// TODO: validate match entity param is hex and the shape of hex we expect
const matchParam = params.get("match");
const matchEntity = matchParam != null ? (matchParam as Entity & Hex) : null;
const matchEntity = matchParam != null ? (matchParam as Entity) : null;

return {
clock: {
Expand Down
14 changes: 12 additions & 2 deletions packages/headless-client/src/createNetworkConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { NetworkConfig, getChain, getWorldFromChainId } from "client/src/mud/utils";
import { env } from "./createSkyStrife";
import { Entity } from "@latticexyz/recs";

export function createNetworkConfig(chainId: number, disableIndexer?: boolean): NetworkConfig {
export function createNetworkConfig(
chainId: number,
{
disableIndexer,
matchEntity,
}: {
disableIndexer?: boolean;
matchEntity?: Entity;
} = {}
): NetworkConfig {
const chain = getChain(chainId);
const world = getWorldFromChainId(chain.id);
const worldAddress = world?.address;
Expand Down Expand Up @@ -31,7 +41,7 @@ export function createNetworkConfig(chainId: number, disableIndexer?: boolean):
worldAddress,
initialBlockNumber,
disableCache: true,
matchEntity: null,
matchEntity: matchEntity ?? null,
chain,
indexerUrl,
useBurner: false,
Expand Down
11 changes: 10 additions & 1 deletion packages/headless-client/src/createSkyStrife.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from "viem";
import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
import { HeadlessLayer, createHeadlessLayer } from "client/src/layers/Headless";
import { Entity } from "@latticexyz/recs";

export const env = z
.object({
Expand All @@ -39,6 +40,7 @@ export const env = z
.optional()
.transform((val) => (val ? val === "true" : undefined)),
LEVEL_ID: z.string().optional(),
MATCH_ENTITY: z.string().optional(),
})
.parse(process.env, {
errorMap: (issue) => ({
Expand All @@ -63,9 +65,16 @@ export async function createSkyStrife(): Promise<{
entity: Hex;
};
}> {
const networkConfig = createNetworkConfig(env.CHAIN_ID, env.DISABLE_INDEXER);
const networkConfig = createNetworkConfig(env.CHAIN_ID, {
disableIndexer: env.DISABLE_INDEXER,
matchEntity: env.MATCH_ENTITY as Entity | undefined,
});

console.log(`Connecting to ${networkConfig.chain.name}...`);
if (env.MATCH_ENTITY) {
console.log(`Loading Match: ${env.MATCH_ENTITY}`);
}

const networkLayer = await createNetworkLayer(networkConfig);
const headlessLayer = await createHeadlessLayer(networkLayer);

Expand Down

0 comments on commit 6d3dfea

Please sign in to comment.