Skip to content

Commit d45c7e0

Browse files
committed
feat: implement chain switching in ConnectButton and set defaultChain in PrivyContextProvider
1 parent b660e9e commit d45c7e0

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

components/global/connect-button.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { useWeb3Modal } from "@web3modal/wagmi/react";
33

44
import { Button } from "@/components/ui/button";
5+
import { DEFAULT_CHAIN_ID } from "@/config/constants";
56
import { useLogin, useLogout, useWallets } from "@privy-io/react-auth";
67
import { useSetActiveWallet } from "@privy-io/wagmi";
78
import { UserPlus } from "lucide-react";
@@ -31,6 +32,10 @@ const ConnectButton = () => {
3132
);
3233
if (newActiveWallet) {
3334
await setActiveWallet(newActiveWallet);
35+
const chainId = newActiveWallet.chainId;
36+
if (chainId !== DEFAULT_CHAIN_ID.toString()) {
37+
await newActiveWallet.switchChain(DEFAULT_CHAIN_ID);
38+
}
3439
}
3540
}
3641
setIsLogin(true);

contexts/privy.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export function PrivyContextProvider({ children }: { children: ReactNode }) {
1414

1515
config={{
1616
loginMethods: ["email","wallet"],
17-
supportedChains:[optimism],
17+
18+
1819
defaultChain:optimism,
1920
appearance:{
2021
showWalletLoginFirst:true,

0 commit comments

Comments
 (0)