Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: rainbow kit support #1548

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/common/src/chains/mudFoundry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MUDChain } from "./types";

export const mudFoundry = {
...foundry,
fees: {
defaultPriorityFee: 0n,
},
// fees: {
// defaultPriorityFee: 0n,
// },
Copy link
Member

@holic holic Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you encounter serialization errors with this? I think @yonadaaa saw a similar thing.

If you have the error handy, we can bubble this up to the wagmi repo/team to get it fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea commented out to make things work for now. The error is:

Uncaught (in promise) TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at getWalletConnectConnector (index.js:303:33)
    at createConnector (index.js:544:50)
    at index.js:96:71
    at Array.forEach (<anonymous>)
    at index.js:73:21
    at new Config (chunk-LAFZBYO7.js:398:60)
    at createConfig (chunk-LAFZBYO7.js:636:19)
    at createConfig2 (index.js:37:18)
    at setupNetwork (setupNetwork.ts:63:23)
    ```

} as const satisfies MUDChain;
1 change: 0 additions & 1 deletion packages/common/src/createContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
getAbiItem,
getContract,
getFunctionSelector,
trim,
} from "viem";
import pRetry from "p-retry";
import { AbiFunction } from "abitype";
Expand Down
4 changes: 3 additions & 1 deletion templates/react/packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
"@latticexyz/store-sync": "link:../../../../packages/store-sync",
"@latticexyz/utils": "link:../../../../packages/utils",
"@latticexyz/world": "link:../../../../packages/world",
"@rainbow-me/rainbowkit": "^1.0.11",
"contracts": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rxjs": "7.5.5",
"viem": "1.6.0"
"viem": "1.6.0",
"wagmi": "^1.4.2"
},
"devDependencies": {
"@types/react": "18.2.22",
Expand Down
5 changes: 5 additions & 0 deletions templates/react/packages/client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import "@rainbow-me/rainbowkit/styles.css";
import { ConnectButton } from "@rainbow-me/rainbowkit";
import { useWalletClient } from "wagmi";
import { useComponentValue } from "@latticexyz/react";
import { useMUD } from "./MUDContext";
import { singletonEntity } from "@latticexyz/store-sync/recs";
Expand All @@ -7,6 +10,7 @@ export const App = () => {
components: { Counter },
systemCalls: { increment },
} = useMUD();
const walletClient = useWalletClient();

const counter = useComponentValue(Counter, singletonEntity);

Expand All @@ -24,6 +28,7 @@ export const App = () => {
>
Increment
</button>
<ConnectButton />
</>
);
};
15 changes: 12 additions & 3 deletions templates/react/packages/client/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import ReactDOM from "react-dom/client";
import { RainbowKitProvider } from "@rainbow-me/rainbowkit";
import { WagmiConfig } from "wagmi";
import { App } from "./App";
import { setup } from "./mud/setup";
import { MUDProvider } from "./MUDContext";
Expand All @@ -10,10 +12,17 @@ const root = ReactDOM.createRoot(rootElement);

// TODO: figure out if we actually want this to be async or if we should render something else in the meantime
setup().then(async (result) => {
const {
network: { wagmiConfig, chain },
} = result;
root.render(
<MUDProvider value={result}>
<App />
</MUDProvider>
<WagmiConfig config={wagmiConfig}>
<RainbowKitProvider chains={[chain]}>
<MUDProvider value={result}>
<App />
</MUDProvider>
</RainbowKitProvider>
</WagmiConfig>
);

// https://vitejs.dev/guide/env-and-mode.html
Expand Down
17 changes: 17 additions & 0 deletions templates/react/packages/client/src/mud/setupNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import { createPublicClient, fallback, webSocket, http, createWalletClient, Hex, parseEther, ClientConfig } from "viem";
import { createFaucetService } from "@latticexyz/services/faucet";
import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
import { createConfig } from "wagmi";
import { getDefaultWallets } from "@rainbow-me/rainbowkit";

import { getNetworkConfig } from "./getNetworkConfig";
import { world } from "./world";
import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";

import { createBurnerAccount, createContract, transportObserver, ContractWrite } from "@latticexyz/common";

import { Subject, share } from "rxjs";
Expand Down Expand Up @@ -51,6 +54,18 @@ export async function setupNetwork() {
account: burnerAccount,
});

const { connectors } = getDefaultWallets({
appName: "MUD",
projectId: "MUD",
chains: [networkConfig.chain],
});

const wagmiConfig = createConfig({
autoConnect: true,
connectors,
publicClient,
});

/*
* Create an observable for contract writes that we can
* pass into MUD dev tools for transaction observability.
Expand Down Expand Up @@ -117,6 +132,8 @@ export async function setupNetwork() {
playerEntity: encodeEntity({ address: "address" }, { address: burnerWalletClient.account.address }),
publicClient,
walletClient: burnerWalletClient,
wagmiConfig,
chain: networkConfig.chain,
latestBlock$,
storedBlockLogs$,
waitForTransaction,
Expand Down