-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
401 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { type ReactNode } from "react"; | ||
import { type Network } from "./setupNetwork"; | ||
import { NetworkProvider } from "./NetworkContext"; | ||
import { StoreSync } from "./StoreSync"; | ||
import { WalletManager } from "./wallet/WalletManager"; | ||
import { DevTools } from "./DevTools"; | ||
|
||
type Props = { | ||
network: Network; | ||
children: ReactNode; | ||
}; | ||
|
||
// A React component that encapsulates MUD-related components. | ||
export function MUD({ network, children }: Props) { | ||
return ( | ||
<NetworkProvider network={network}> | ||
<StoreSync> | ||
<WalletManager> | ||
{children} | ||
{/* Mounts dev-tools when in development mode. https://vitejs.dev/guide/env-and-mode.html */} | ||
{import.meta.env.DEV && <DevTools />} | ||
</WalletManager> | ||
</StoreSync> | ||
</NetworkProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
/* | ||
* This file sets up all the definitions required for a MUD client. | ||
*/ | ||
|
||
import { createConfig } from "wagmi"; | ||
import { setupNetwork } from "./setupNetwork"; | ||
|
||
export type SetupResult = Awaited<ReturnType<typeof setup>>; | ||
|
||
export async function setup() { | ||
const network = await setupNetwork(); | ||
|
||
// Create a Wagmi config for an external wallet connection. | ||
// https://wagmi.sh/react/api/createConfig | ||
const wagmiConfig = createConfig({ | ||
chains: [network.publicClient.chain], | ||
client: () => network.publicClient, | ||
}); | ||
|
||
return { network, wagmiConfig }; | ||
return { | ||
network, | ||
wagmiConfig, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
templates/react/packages/client/src/mud/wallet/BurnerAddress.tsx
This file was deleted.
Oops, something went wrong.
13 changes: 10 additions & 3 deletions
13
templates/react/packages/client/src/mud/wallet/BurnerContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import { createContext, useContext, type ReactNode } from "react"; | ||
import { type Burner } from "./burner"; | ||
import { type Burner } from "./createBurner"; | ||
|
||
// A React context that holds the result of `createBurner()` (e.g., Wallet Client, World contract). | ||
const BurnerContext = createContext<Burner | null>(null); | ||
|
||
export function BurnerProvider(props: { burner: Burner | null; children: ReactNode }) { | ||
type Props = { | ||
burner: Burner | null; | ||
children: ReactNode; | ||
}; | ||
|
||
export function BurnerProvider({ burner, children }: Props) { | ||
if (useContext(BurnerContext)) throw new Error("BurnerProvider can only be used once"); | ||
return <BurnerContext.Provider value={props.burner}>{props.children}</BurnerContext.Provider>; | ||
return <BurnerContext.Provider value={burner}>{children}</BurnerContext.Provider>; | ||
} | ||
|
||
export function useBurner() { | ||
// This can be null. | ||
return useContext(BurnerContext); | ||
} |
Oops, something went wrong.