Skip to content

Commit

Permalink
use sepolia chainId (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
aashutoshrathi authored Aug 5, 2024
1 parent 0a40dc8 commit ab421b9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
15 changes: 2 additions & 13 deletions game/src/app/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,12 @@ import { sepolia } from "viem/chains";
import { createConfig, http } from "wagmi";
import { injected } from "wagmi/connectors";

export const stackrDevnet = {
...sepolia,
name: "Stackr Devnet",
rpcUrls: {
default: {
http: ["https://devnet.stf.xyz"],
},
},
id: 69420,
};

export function getConfig() {
return createConfig({
chains: [stackrDevnet],
chains: [sepolia],
connectors: [injected({ shimDisconnect: true })],
transports: {
[stackrDevnet.id]: http(),
[sepolia.id]: http(),
},
});
}
10 changes: 5 additions & 5 deletions game/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"use client";
import { PastGames } from "@/components/past-games/past-games";
import { Button } from "@/components/button";
import { Game } from "@/components/game";
import { PastGames } from "@/components/past-games/past-games";
import { fetchLeaderboard, fetchMruInfo } from "@/rpc/api";
import { useEffect, useState } from "react";
import { createWalletClient, custom } from "viem";
import { addChain } from "viem/actions";
import { sepolia } from "viem/chains";
import { useAccount, useConnect } from "wagmi";
import { stackrDevnet } from "./config";

export default function Main() {
const { isConnected, isConnecting } = useAccount();
Expand All @@ -32,12 +32,12 @@ export default function Main() {
const walletClient = createWalletClient({
transport: custom(window.ethereum),
});
if (chainId !== stackrDevnet.id) {
if (chainId !== sepolia.id) {
try {
await walletClient.switchChain({ id: stackrDevnet.id });
await walletClient.switchChain({ id: sepolia.id });
} catch (e) {
console.log(e);
await addChain(walletClient, { chain: stackrDevnet });
await addChain(walletClient, { chain: sepolia });
}
}
connect({ connector });
Expand Down
4 changes: 2 additions & 2 deletions game/src/components/navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import { stackrDevnet } from "@/app/config";
import { formatAddress } from "@/core/highScoreMode";
import { useEffect } from "react";
import { sepolia } from "viem/chains";
import { useAccount, useDisconnect } from "wagmi";
import { Button } from "./button";

Expand All @@ -10,7 +10,7 @@ export const Navbar = () => {
const { disconnect } = useDisconnect();

useEffect(() => {
if (chainId !== stackrDevnet.id) {
if (chainId !== sepolia.id) {
disconnect();
}
}, [chainId]);
Expand Down

0 comments on commit ab421b9

Please sign in to comment.