create-mud 2.2.17-d5f4e1e44bbc260ff21dacdfab0e0f8389e9f304 → 2.2.17-e45e3751c0ea10c7b1f0088d674121419b0d0acb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/templates/react/mprocs.yaml +1 -9
- package/templates/react/packages/client/index.html +2 -2
- package/templates/react/packages/client/package.json +9 -17
- package/templates/react/packages/client/src/App.tsx +100 -41
- package/templates/react/packages/client/src/MUDContext.tsx +21 -0
- package/templates/react/packages/client/src/index.tsx +32 -17
- package/templates/react/packages/client/src/mud/createSystemCalls.ts +56 -0
- package/templates/react/packages/client/src/mud/getNetworkConfig.ts +76 -0
- package/templates/react/packages/client/src/mud/setup.ts +18 -0
- package/templates/react/packages/client/src/mud/setupNetwork.ts +101 -0
- package/templates/react/packages/client/src/mud/supportedChains.ts +20 -0
- package/templates/react/packages/client/tsconfig.json +1 -1
- package/templates/react/packages/client/vite.config.ts +7 -2
- package/templates/react/packages/contracts/mud.config.ts +8 -13
- package/templates/react/packages/contracts/package.json +0 -1
- package/templates/react/packages/contracts/script/PostDeploy.s.sol +9 -1
- package/templates/react/packages/contracts/src/codegen/index.sol +1 -1
- package/templates/react/packages/contracts/src/codegen/tables/Tasks.sol +522 -0
- package/templates/react/packages/contracts/src/codegen/world/{IMoveSystem.sol → ITasksSystem.sol} +9 -5
- package/templates/react/packages/contracts/src/codegen/world/IWorld.sol +2 -2
- package/templates/react/packages/contracts/src/systems/TasksSystem.sol +24 -0
- package/templates/react/packages/contracts/test/TasksTest.t.sol +30 -0
- package/templates/react/packages/contracts/worlds.json +1 -1
- package/templates/react/packages/client/postcss.config.cjs +0 -6
- package/templates/react/packages/client/src/Providers.tsx +0 -35
- package/templates/react/packages/client/src/common.ts +0 -26
- package/templates/react/packages/client/src/game/GameMap.tsx +0 -102
- package/templates/react/packages/client/src/game/useKeyboardMovement.ts +0 -26
- package/templates/react/packages/client/src/mud/Explorer.tsx +0 -32
- package/templates/react/packages/client/src/mud/Synced.tsx +0 -14
- package/templates/react/packages/client/src/mud/stash.ts +0 -4
- package/templates/react/packages/client/src/mud/useSyncStatus.ts +0 -21
- package/templates/react/packages/client/src/mud/useWorldContract.ts +0 -44
- package/templates/react/packages/client/src/ui/AsyncButton.tsx +0 -41
- package/templates/react/packages/client/src/ui/ErrorFallback.tsx +0 -58
- package/templates/react/packages/client/src/ui/icons/ArrowDownIcon.tsx +0 -22
- package/templates/react/packages/client/src/ui/icons/MUDIcon.tsx +0 -25
- package/templates/react/packages/client/src/wagmiConfig.ts +0 -49
- package/templates/react/packages/client/tailwind.config.ts +0 -10
- package/templates/react/packages/contracts/out/IWorld.sol/IWorld.abi.json +0 -2021
- package/templates/react/packages/contracts/src/MoveSystem.sol +0 -26
- package/templates/react/packages/contracts/src/codegen/common.sol +0 -11
- package/templates/react/packages/contracts/src/codegen/tables/Position.sol +0 -318
- package/templates/react/packages/contracts/test/MoveTest.t.sol +0 -27
- package/templates/react/packages/contracts/test/WorldTest.t.sol +0 -21
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.24;
|
|
3
|
+
|
|
4
|
+
import "forge-std/Test.sol";
|
|
5
|
+
import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
|
|
6
|
+
|
|
7
|
+
import { IWorld } from "../src/codegen/world/IWorld.sol";
|
|
8
|
+
import { Tasks, TasksData } from "../src/codegen/index.sol";
|
|
9
|
+
|
|
10
|
+
contract TasksTest is MudTest {
|
|
11
|
+
function testWorldExists() public {
|
|
12
|
+
uint256 codeSize;
|
|
13
|
+
address addr = worldAddress;
|
|
14
|
+
assembly {
|
|
15
|
+
codeSize := extcodesize(addr)
|
|
16
|
+
}
|
|
17
|
+
assertTrue(codeSize > 0);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function testTasks() public {
|
|
21
|
+
// Expect task to exist that we created during PostDeploy script
|
|
22
|
+
TasksData memory task = Tasks.get("1");
|
|
23
|
+
assertEq(task.description, "Walk the dog");
|
|
24
|
+
assertEq(task.completedAt, 0);
|
|
25
|
+
|
|
26
|
+
// Expect the task to be completed after calling completeTask from our TasksSystem
|
|
27
|
+
IWorld(worldAddress).app__completeTask("1");
|
|
28
|
+
assertEq(Tasks.getCompletedAt("1"), block.timestamp);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { WagmiProvider } from "wagmi";
|
|
2
|
-
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
|
|
3
|
-
import { ReactNode } from "react";
|
|
4
|
-
import { createSyncAdapter } from "@latticexyz/store-sync/internal";
|
|
5
|
-
import { SyncProvider } from "@latticexyz/store-sync/react";
|
|
6
|
-
import { stash } from "./mud/stash";
|
|
7
|
-
import { defineConfig, EntryKitProvider } from "@latticexyz/entrykit/internal";
|
|
8
|
-
import { wagmiConfig } from "./wagmiConfig";
|
|
9
|
-
import { chainId, getWorldAddress, startBlock } from "./common";
|
|
10
|
-
|
|
11
|
-
const queryClient = new QueryClient();
|
|
12
|
-
|
|
13
|
-
export type Props = {
|
|
14
|
-
children: ReactNode;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export function Providers({ children }: Props) {
|
|
18
|
-
const worldAddress = getWorldAddress();
|
|
19
|
-
return (
|
|
20
|
-
<WagmiProvider config={wagmiConfig}>
|
|
21
|
-
<QueryClientProvider client={queryClient}>
|
|
22
|
-
<EntryKitProvider config={defineConfig({ chainId, worldAddress })}>
|
|
23
|
-
<SyncProvider
|
|
24
|
-
chainId={chainId}
|
|
25
|
-
address={worldAddress}
|
|
26
|
-
startBlock={startBlock}
|
|
27
|
-
adapter={createSyncAdapter({ stash })}
|
|
28
|
-
>
|
|
29
|
-
{children}
|
|
30
|
-
</SyncProvider>
|
|
31
|
-
</EntryKitProvider>
|
|
32
|
-
</QueryClientProvider>
|
|
33
|
-
</WagmiProvider>
|
|
34
|
-
);
|
|
35
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import mudConfig from "contracts/mud.config";
|
|
2
|
-
import { chains } from "./wagmiConfig";
|
|
3
|
-
import { Chain } from "viem";
|
|
4
|
-
|
|
5
|
-
export const chainId = import.meta.env.CHAIN_ID;
|
|
6
|
-
export const worldAddress = import.meta.env.WORLD_ADDRESS;
|
|
7
|
-
export const startBlock = import.meta.env.START_BLOCK;
|
|
8
|
-
|
|
9
|
-
export const url = new URL(window.location.href);
|
|
10
|
-
|
|
11
|
-
export type Direction = (typeof mudConfig.enums.Direction)[number];
|
|
12
|
-
|
|
13
|
-
export function getWorldAddress() {
|
|
14
|
-
if (!worldAddress) {
|
|
15
|
-
throw new Error("No world address configured. Is the world still deploying?");
|
|
16
|
-
}
|
|
17
|
-
return worldAddress;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function getChain(): Chain {
|
|
21
|
-
const chain = chains.find((c) => c.id === chainId);
|
|
22
|
-
if (!chain) {
|
|
23
|
-
throw new Error(`No chain configured for chain ID ${chainId}.`);
|
|
24
|
-
}
|
|
25
|
-
return chain;
|
|
26
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { serialize, useAccount } from "wagmi";
|
|
2
|
-
import { useKeyboardMovement } from "./useKeyboardMovement";
|
|
3
|
-
import { Address, Hex, hexToBigInt, keccak256 } from "viem";
|
|
4
|
-
import { ArrowDownIcon } from "../ui/icons/ArrowDownIcon";
|
|
5
|
-
import { twMerge } from "tailwind-merge";
|
|
6
|
-
import { Direction } from "../common";
|
|
7
|
-
import mudConfig from "contracts/mud.config";
|
|
8
|
-
import { AsyncButton } from "../ui/AsyncButton";
|
|
9
|
-
import { useAccountModal } from "@latticexyz/entrykit/internal";
|
|
10
|
-
|
|
11
|
-
export type Props = {
|
|
12
|
-
readonly players?: readonly {
|
|
13
|
-
readonly player: Address;
|
|
14
|
-
readonly x: number;
|
|
15
|
-
readonly y: number;
|
|
16
|
-
}[];
|
|
17
|
-
|
|
18
|
-
readonly onMove?: (direction: Direction) => Promise<void>;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const size = 40;
|
|
22
|
-
const scale = 100 / size;
|
|
23
|
-
|
|
24
|
-
function getColorAngle(seed: Hex) {
|
|
25
|
-
return Number(hexToBigInt(keccak256(seed)) % 360n);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const rotateClassName = {
|
|
29
|
-
North: "rotate-0",
|
|
30
|
-
East: "rotate-90",
|
|
31
|
-
South: "rotate-180",
|
|
32
|
-
West: "-rotate-90",
|
|
33
|
-
} as const satisfies Record<Direction, `${"" | "-"}rotate-${number}`>;
|
|
34
|
-
|
|
35
|
-
export function GameMap({ players = [], onMove }: Props) {
|
|
36
|
-
const { openAccountModal } = useAccountModal();
|
|
37
|
-
const { address: userAddress } = useAccount();
|
|
38
|
-
const currentPlayer = players.find((player) => player.player.toLowerCase() === userAddress?.toLowerCase());
|
|
39
|
-
useKeyboardMovement(onMove);
|
|
40
|
-
return (
|
|
41
|
-
<div className="aspect-square w-full max-w-[40rem]">
|
|
42
|
-
<div className="relative w-full h-full border-8 border-black/10">
|
|
43
|
-
{onMove
|
|
44
|
-
? mudConfig.enums.Direction.map((direction) => (
|
|
45
|
-
<button
|
|
46
|
-
key={direction}
|
|
47
|
-
title={`Move ${direction.toLowerCase()}`}
|
|
48
|
-
className={twMerge(
|
|
49
|
-
"outline-0 absolute inset-0 cursor-pointer grid p-4",
|
|
50
|
-
rotateClassName[direction],
|
|
51
|
-
"transition bg-gradient-to-t from-transparent via-transparent to-blue-50 text-blue-400 opacity-0 hover:opacity-40 active:opacity-100",
|
|
52
|
-
)}
|
|
53
|
-
style={{ clipPath: "polygon(0% 0%, 100% 0%, 50% 50%)" }}
|
|
54
|
-
onClick={() => onMove(direction)}
|
|
55
|
-
>
|
|
56
|
-
<ArrowDownIcon className="rotate-180 text-4xl self-start justify-self-center" />
|
|
57
|
-
</button>
|
|
58
|
-
))
|
|
59
|
-
: null}
|
|
60
|
-
|
|
61
|
-
{players.map((player) => (
|
|
62
|
-
<div
|
|
63
|
-
key={player.player}
|
|
64
|
-
className="absolute bg-current"
|
|
65
|
-
style={{
|
|
66
|
-
color: `hwb(${getColorAngle(player.player)} 40% 20%)`,
|
|
67
|
-
width: `${scale}%`,
|
|
68
|
-
height: `${scale}%`,
|
|
69
|
-
left: `${((((player.x + size / 2) % size) + size) % size) * scale}%`,
|
|
70
|
-
top: `${((size - ((player.y + size / 2) % size)) % size) * scale}%`,
|
|
71
|
-
}}
|
|
72
|
-
title={serialize(player, null, 2)}
|
|
73
|
-
>
|
|
74
|
-
{player === currentPlayer ? <div className="w-full h-full bg-current animate-ping opacity-50" /> : null}
|
|
75
|
-
</div>
|
|
76
|
-
))}
|
|
77
|
-
|
|
78
|
-
{!currentPlayer ? (
|
|
79
|
-
onMove ? (
|
|
80
|
-
<div className="absolute inset-0 grid place-items-center">
|
|
81
|
-
<AsyncButton
|
|
82
|
-
className="group outline-0 p-4 border-4 border-green-400 transition ring-green-300 hover:ring-4 active:scale-95 rounded-lg text-lg font-medium aria-busy:pointer-events-none aria-busy:animate-pulse"
|
|
83
|
-
onClick={() => onMove("North")}
|
|
84
|
-
>
|
|
85
|
-
Spawn<span className="hidden group-aria-busy:inline">ing…</span>
|
|
86
|
-
</AsyncButton>
|
|
87
|
-
</div>
|
|
88
|
-
) : (
|
|
89
|
-
<div className="absolute inset-0 grid place-items-center">
|
|
90
|
-
<button
|
|
91
|
-
className="group outline-0 p-4 border-4 border-green-400 transition ring-green-300 hover:ring-4 active:scale-95 rounded-lg text-lg font-medium aria-busy:pointer-events-none aria-busy:animate-pulse"
|
|
92
|
-
onClick={openAccountModal}
|
|
93
|
-
>
|
|
94
|
-
Sign in to play
|
|
95
|
-
</button>
|
|
96
|
-
</div>
|
|
97
|
-
)
|
|
98
|
-
) : null}
|
|
99
|
-
</div>
|
|
100
|
-
</div>
|
|
101
|
-
);
|
|
102
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
import { Direction } from "../common";
|
|
3
|
-
|
|
4
|
-
const keys = new Map<KeyboardEvent["key"], Direction>([
|
|
5
|
-
["ArrowUp", "North"],
|
|
6
|
-
["ArrowRight", "East"],
|
|
7
|
-
["ArrowDown", "South"],
|
|
8
|
-
["ArrowLeft", "West"],
|
|
9
|
-
]);
|
|
10
|
-
|
|
11
|
-
export const useKeyboardMovement = (move: undefined | ((direction: Direction) => void)) => {
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
if (!move) return;
|
|
14
|
-
|
|
15
|
-
const listener = (event: KeyboardEvent) => {
|
|
16
|
-
const direction = keys.get(event.key);
|
|
17
|
-
if (direction == null) return;
|
|
18
|
-
|
|
19
|
-
event.preventDefault();
|
|
20
|
-
move(direction);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
window.addEventListener("keydown", listener);
|
|
24
|
-
return () => window.removeEventListener("keydown", listener);
|
|
25
|
-
}, [move]);
|
|
26
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
2
|
-
import { getChain, getWorldAddress } from "../common";
|
|
3
|
-
import { MUDIcon } from "../ui/icons/MUDIcon";
|
|
4
|
-
|
|
5
|
-
export function Explorer() {
|
|
6
|
-
const [open, setOpen] = useState(false);
|
|
7
|
-
|
|
8
|
-
const chain = getChain();
|
|
9
|
-
const worldAddress = getWorldAddress();
|
|
10
|
-
|
|
11
|
-
const explorerUrl = chain.blockExplorers?.worldsExplorer?.url;
|
|
12
|
-
if (!explorerUrl) return null;
|
|
13
|
-
|
|
14
|
-
return (
|
|
15
|
-
<div className="fixed bottom-0 inset-x-0 flex flex-col opacity-80 transition hover:opacity-100">
|
|
16
|
-
<button
|
|
17
|
-
type="button"
|
|
18
|
-
onClick={() => setOpen(!open)}
|
|
19
|
-
className="outline-none flex justify-end gap-2 p-2 font-medium leading-none text-black"
|
|
20
|
-
>
|
|
21
|
-
{open ? (
|
|
22
|
-
<>Close</>
|
|
23
|
-
) : (
|
|
24
|
-
<>
|
|
25
|
-
Explore <MUDIcon className="text-orange-500" />
|
|
26
|
-
</>
|
|
27
|
-
)}
|
|
28
|
-
</button>
|
|
29
|
-
{open ? <iframe src={`${explorerUrl}/${worldAddress}`} className="bg-black h-[50vh]" /> : null}
|
|
30
|
-
</div>
|
|
31
|
-
);
|
|
32
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
import { useSyncStatus } from "./useSyncStatus";
|
|
3
|
-
import { TableRecord } from "@latticexyz/stash/internal";
|
|
4
|
-
import { SyncProgress } from "@latticexyz/store-sync/stash/common";
|
|
5
|
-
|
|
6
|
-
export type Props = {
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
fallback?: (props: TableRecord<typeof SyncProgress>) => ReactNode;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export function Synced({ children, fallback }: Props) {
|
|
12
|
-
const status = useSyncStatus();
|
|
13
|
-
return status.isLive ? children : fallback?.(status);
|
|
14
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { stash } from "./stash";
|
|
2
|
-
import { initialProgress, SyncProgress } from "@latticexyz/store-sync/internal";
|
|
3
|
-
import { SyncStep } from "@latticexyz/store-sync";
|
|
4
|
-
import { useMemo } from "react";
|
|
5
|
-
import { useRecord } from "@latticexyz/stash/react";
|
|
6
|
-
|
|
7
|
-
export function useSyncStatus() {
|
|
8
|
-
const progress = useRecord({
|
|
9
|
-
stash,
|
|
10
|
-
table: SyncProgress,
|
|
11
|
-
key: {},
|
|
12
|
-
defaultValue: initialProgress,
|
|
13
|
-
});
|
|
14
|
-
return useMemo(
|
|
15
|
-
() => ({
|
|
16
|
-
...progress,
|
|
17
|
-
isLive: progress.step === SyncStep.LIVE,
|
|
18
|
-
}),
|
|
19
|
-
[progress],
|
|
20
|
-
);
|
|
21
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { useClient } from "wagmi";
|
|
2
|
-
import { chainId, getWorldAddress } from "../common";
|
|
3
|
-
import { Account, Chain, Client, GetContractReturnType, Transport, getContract } from "viem";
|
|
4
|
-
import { useQuery } from "@tanstack/react-query";
|
|
5
|
-
import { useSessionClient } from "@latticexyz/entrykit/internal";
|
|
6
|
-
import { observer } from "@latticexyz/explorer/observer";
|
|
7
|
-
import worldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
|
|
8
|
-
|
|
9
|
-
export function useWorldContract():
|
|
10
|
-
| GetContractReturnType<
|
|
11
|
-
typeof worldAbi,
|
|
12
|
-
{
|
|
13
|
-
public: Client<Transport, Chain>;
|
|
14
|
-
wallet: Client<Transport, Chain, Account>;
|
|
15
|
-
}
|
|
16
|
-
>
|
|
17
|
-
| undefined {
|
|
18
|
-
const client = useClient({ chainId });
|
|
19
|
-
const { data: sessionClient } = useSessionClient();
|
|
20
|
-
|
|
21
|
-
const { data: worldContract } = useQuery({
|
|
22
|
-
queryKey: ["worldContract", client?.uid, sessionClient?.uid],
|
|
23
|
-
queryFn: () => {
|
|
24
|
-
if (!client || !sessionClient) {
|
|
25
|
-
throw new Error("Not connected.");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return getContract({
|
|
29
|
-
abi: worldAbi,
|
|
30
|
-
address: getWorldAddress(),
|
|
31
|
-
client: {
|
|
32
|
-
public: client,
|
|
33
|
-
wallet: sessionClient.extend(observer()),
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
staleTime: Infinity,
|
|
38
|
-
refetchOnMount: false,
|
|
39
|
-
refetchOnReconnect: false,
|
|
40
|
-
refetchOnWindowFocus: false,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return worldContract;
|
|
44
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { DetailedHTMLProps, ButtonHTMLAttributes, useState, useRef, useCallback, MouseEventHandler } from "react";
|
|
2
|
-
|
|
3
|
-
export type AsyncButtonProps = {
|
|
4
|
-
pending?: boolean;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export type Props = AsyncButtonProps & DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;
|
|
8
|
-
|
|
9
|
-
export const AsyncButton = ({ pending, type, disabled, onClick, ...props }: Props) => {
|
|
10
|
-
// TODO: move all this logic into a hook so we can wrap other event handlers
|
|
11
|
-
|
|
12
|
-
const promiseRef = useRef<Promise<unknown>>();
|
|
13
|
-
const [promisePending, setPromisePending] = useState<true | undefined>(undefined);
|
|
14
|
-
|
|
15
|
-
const asyncOnClick = useCallback<MouseEventHandler<HTMLButtonElement>>(
|
|
16
|
-
(...args) => {
|
|
17
|
-
if (!onClick) return;
|
|
18
|
-
const result = onClick(...args);
|
|
19
|
-
const promise = Promise.resolve(result);
|
|
20
|
-
promiseRef.current = promise;
|
|
21
|
-
setPromisePending(true);
|
|
22
|
-
promise.finally(() => {
|
|
23
|
-
if (promiseRef.current === promise) {
|
|
24
|
-
setPromisePending(undefined);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
},
|
|
28
|
-
[onClick],
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<button
|
|
33
|
-
type={type || "button"}
|
|
34
|
-
aria-busy={pending || promisePending}
|
|
35
|
-
aria-disabled={disabled}
|
|
36
|
-
disabled={disabled || pending || promisePending}
|
|
37
|
-
onClick={onClick ? asyncOnClick : undefined}
|
|
38
|
-
{...props}
|
|
39
|
-
/>
|
|
40
|
-
);
|
|
41
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { wait } from "@latticexyz/common/utils";
|
|
2
|
-
import { useEffect, useRef, useState } from "react";
|
|
3
|
-
import { FallbackProps } from "react-error-boundary";
|
|
4
|
-
|
|
5
|
-
export function ErrorFallback({ error, resetErrorBoundary }: FallbackProps) {
|
|
6
|
-
const when = new Date();
|
|
7
|
-
const isMounted = useRef(false);
|
|
8
|
-
const [retries, setRetries] = useState(1);
|
|
9
|
-
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
isMounted.current = true;
|
|
12
|
-
return () => {
|
|
13
|
-
isMounted.current = false;
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<div className="fixed inset-0 overflow-auto bg-red-50">
|
|
19
|
-
<div className="w-full max-w-screen-md mx-auto py-16 px-8 space-y-12">
|
|
20
|
-
<h1 className="text-4xl font-black text-red-500">Oops! It broke :(</h1>
|
|
21
|
-
<div className="space-y-6">
|
|
22
|
-
<div className="relative">
|
|
23
|
-
<div className="p-6 bg-red-100 border-l-8 -ml-[8px] border-red-500 font-semibold whitespace-pre-wrap">
|
|
24
|
-
{error instanceof Error ? error.message : String(error)}
|
|
25
|
-
</div>
|
|
26
|
-
{error instanceof Error && error.stack ? (
|
|
27
|
-
<div className="p-6 bg-white font-mono text-sm overflow-auto whitespace-pre">{error.stack}</div>
|
|
28
|
-
) : null}
|
|
29
|
-
<div className="absolute top-full right-0 text-sm text-stone-400" title={when.toISOString()}>
|
|
30
|
-
{when.toLocaleString()}
|
|
31
|
-
</div>
|
|
32
|
-
</div>
|
|
33
|
-
|
|
34
|
-
{retries > 0 ? (
|
|
35
|
-
<button
|
|
36
|
-
type="button"
|
|
37
|
-
className="group bg-red-500 text-white px-4 py-2 rounded-md hover:bg-red-600 active:bg-red-700 transition aria-busy:pointer-events-none aria-busy:animate-pulse"
|
|
38
|
-
onClick={async (event) => {
|
|
39
|
-
// if we retry and the same error occurs, it'll look like the button click did nothing
|
|
40
|
-
// so we'll fake a pending state here to give users an indication something is happening
|
|
41
|
-
event.currentTarget.ariaBusy = "true";
|
|
42
|
-
await wait(1000);
|
|
43
|
-
resetErrorBoundary();
|
|
44
|
-
if (isMounted.current) {
|
|
45
|
-
setRetries((value) => value - 1);
|
|
46
|
-
event.currentTarget.ariaBusy = null;
|
|
47
|
-
}
|
|
48
|
-
}}
|
|
49
|
-
>
|
|
50
|
-
<span className="group-aria-busy:hidden">Retry?</span>
|
|
51
|
-
<span className="hidden group-aria-busy:inline">Retrying…</span>
|
|
52
|
-
</button>
|
|
53
|
-
) : null}
|
|
54
|
-
</div>
|
|
55
|
-
</div>
|
|
56
|
-
</div>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { DetailedHTMLProps, SVGAttributes } from "react";
|
|
2
|
-
import { twMerge } from "tailwind-merge";
|
|
3
|
-
|
|
4
|
-
export type Props = DetailedHTMLProps<SVGAttributes<SVGSVGElement>, SVGSVGElement>;
|
|
5
|
-
|
|
6
|
-
export function ArrowDownIcon({ className, ...props }: Props) {
|
|
7
|
-
return (
|
|
8
|
-
<svg
|
|
9
|
-
className={twMerge("h-[1em] w-[1em]", className)}
|
|
10
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
11
|
-
viewBox="0 0 16 16"
|
|
12
|
-
fill="currentColor"
|
|
13
|
-
{...props}
|
|
14
|
-
>
|
|
15
|
-
<path
|
|
16
|
-
fillRule="evenodd"
|
|
17
|
-
d="M8 2a.75.75 0 0 1 .75.75v8.69l3.22-3.22a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 0 1 1.06-1.06l3.22 3.22V2.75A.75.75 0 0 1 8 2Z"
|
|
18
|
-
clipRule="evenodd"
|
|
19
|
-
/>
|
|
20
|
-
</svg>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { DetailedHTMLProps, SVGAttributes } from "react";
|
|
2
|
-
import { twMerge } from "tailwind-merge";
|
|
3
|
-
|
|
4
|
-
export type Props = DetailedHTMLProps<SVGAttributes<SVGSVGElement>, SVGSVGElement>;
|
|
5
|
-
|
|
6
|
-
export function MUDIcon({ className, ...props }: Props) {
|
|
7
|
-
return (
|
|
8
|
-
<svg
|
|
9
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
10
|
-
viewBox="0 0 8 8"
|
|
11
|
-
fill="currentColor"
|
|
12
|
-
shapeRendering="crispEdges"
|
|
13
|
-
className={twMerge("-my-[0.125em] h-[1.25em] w-[1.25em]", className)}
|
|
14
|
-
{...props}
|
|
15
|
-
>
|
|
16
|
-
{/* eslint-disable-next-line max-len */}
|
|
17
|
-
<path d="M0 0h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm0 1h1v1H0zm1 0h1v1H1zm1 0h1v1H2zm1 0h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm2-1h1v1H7zm0 1h1v1H7zM6 7h1v1H6zm1-2h1v1H7zm0-1h1v1H7zm0-1h1v1H7z" />
|
|
18
|
-
<path
|
|
19
|
-
d="M2 2h1v1H2zm0 1h1v1H2zm0 1h1v1H2zm0 1h1v1H2zm1-3h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm0 1h1v1H5zm0 1h1v1H5zm0 1h1v1H5zM4 5h1v1H4zM3 5h1v1H3z"
|
|
20
|
-
opacity=".5"
|
|
21
|
-
/>
|
|
22
|
-
<path d="M7 2h1v1H7zm0-1h1v1H7zM1 0h1v1H1zm1 0h1v1H2zm1 0h1v1H3zm1 0h1v1H4zm1 0h1v1H5zm1 0h1v1H6zm1 0h1v1H7z" />
|
|
23
|
-
</svg>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Chain, http, webSocket } from "viem";
|
|
2
|
-
import { anvil } from "viem/chains";
|
|
3
|
-
import { createWagmiConfig } from "@latticexyz/entrykit/internal";
|
|
4
|
-
import { rhodolite, garnet, redstone } from "@latticexyz/common/chains";
|
|
5
|
-
import { chainId } from "./common";
|
|
6
|
-
|
|
7
|
-
export const chains = [
|
|
8
|
-
redstone,
|
|
9
|
-
garnet,
|
|
10
|
-
rhodolite,
|
|
11
|
-
{
|
|
12
|
-
...anvil,
|
|
13
|
-
contracts: {
|
|
14
|
-
...anvil.contracts,
|
|
15
|
-
paymaster: {
|
|
16
|
-
address: "0xf03E61E7421c43D9068Ca562882E98d1be0a6b6e",
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
blockExplorers: {
|
|
20
|
-
default: {} as never,
|
|
21
|
-
worldsExplorer: {
|
|
22
|
-
name: "MUD Worlds Explorer",
|
|
23
|
-
url: "http://localhost:13690/anvil/worlds",
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
] as const satisfies Chain[];
|
|
28
|
-
|
|
29
|
-
export const transports = {
|
|
30
|
-
[anvil.id]: webSocket(),
|
|
31
|
-
[garnet.id]: http(),
|
|
32
|
-
[rhodolite.id]: http(),
|
|
33
|
-
[redstone.id]: http(),
|
|
34
|
-
} as const;
|
|
35
|
-
|
|
36
|
-
export const wagmiConfig = createWagmiConfig({
|
|
37
|
-
chainId,
|
|
38
|
-
// TODO: swap this with another default project ID or leave empty
|
|
39
|
-
walletConnectProjectId: "14ce88fdbc0f9c294e26ec9b4d848e44",
|
|
40
|
-
appName: document.title,
|
|
41
|
-
chains,
|
|
42
|
-
transports,
|
|
43
|
-
pollingInterval: {
|
|
44
|
-
[anvil.id]: 2000,
|
|
45
|
-
[garnet.id]: 2000,
|
|
46
|
-
[rhodolite.id]: 2000,
|
|
47
|
-
[redstone.id]: 2000,
|
|
48
|
-
},
|
|
49
|
-
});
|