File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
examples/nextjs-shadcn/src/app Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
1818 sendTransaction ,
1919 switchNetwork ,
2020 waitForTransaction ,
21+ getNetwork ,
2122} from "@wagmi/core" ;
2223import { useMemo } from "react" ;
2324import { useAccount } from "wagmi" ;
@@ -41,7 +42,10 @@ export function Embeds(props: { embeds: Array<Embed> }) {
4142 const parsedChainId = parseInt ( chainId ) ;
4243
4344 // Switch chains if the user is not on the right one
44- await switchNetwork ( { chainId : parsedChainId } ) ;
45+ // Note: silently fails if switching to the same chain
46+ const network = getNetwork ( ) ;
47+ if ( network . chain . id !== parsedChainId )
48+ await switchNetwork ( { chainId : parsedChainId } ) ;
4549
4650 // Send the transaction
4751 const { hash } = await sendTransaction ( {
@@ -58,6 +62,7 @@ export function Embeds(props: { embeds: Array<Embed> }) {
5862
5963 onConfirmed ( hash , status === "success" ) ;
6064 } catch ( e ) {
65+ console . error ( e ) ;
6166 onError ( e ) ;
6267 }
6368 } ,
You can’t perform that action at this time.
0 commit comments