Skip to content

Commit

Permalink
Using switchChain Hook from wagmi
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshpw committed Oct 13, 2024
1 parent 237dffe commit d6fdb5a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/services/wagmi/context.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, createContext, ReactNode, useMemo, useRef, useEffect } from "react"
import { useAccount as useWagmiAccount, useConnect as useWagmiConnect } from "wagmi"
import { disconnect as disconnectEtherlink, switchChain } from "@wagmi/core"
import { useSwitchChain, useAccount as useWagmiAccount, useConnect as useWagmiConnect } from "wagmi"
import { disconnect as disconnectEtherlink } from "@wagmi/core"
import { config as wagmiConfig } from "services/wagmi/config"
import { etherlink, etherlinkTestnet } from "wagmi/chains"
import { useSIWE, useModal, SIWESession } from "connectkit"
Expand All @@ -21,6 +21,7 @@ export const EtherlinkContext = createContext<any | undefined>(undefined)

export const EtherlinkProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
const { setOpen } = useModal()
const { chains, switchChain } = useSwitchChain()
// const { data, isReady, isRejected, isLoading, isSignedIn, signOut, signIn, error } = useSIWE({
// onSignIn: (session?: SIWESession) => {
// console.log("User Signed In", session)
Expand Down Expand Up @@ -68,7 +69,7 @@ export const EtherlinkProvider: React.FC<{ children: ReactNode }> = ({ children
disconnect: () => disconnectEtherlink(wagmiConfig),
switchToNetwork: (network: string) => {
const networkId = network === "etherlink_mainnet" ? etherlink.id : etherlinkTestnet.id
switchChain(wagmiConfig, { chainId: networkId })
switchChain({ chainId: networkId })
}
}}
>
Expand Down

0 comments on commit d6fdb5a

Please sign in to comment.