Skip to content

Commit f899200

Browse files
committed
fix: should switch network when connect wallet
1 parent 3a9283e commit f899200

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

pages/_app.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ function App({Component, pageProps}) {
6969

7070
const connectWallet = useCallback(async function () {
7171
const provider = await createProvider(undefined, (id) => dispatch({type: "SET_CHAIN_ID", chainId: id}))
72+
if (provider.chainId !== '0x13881') {
73+
await switchNetwork(provider)
74+
}
7275
if (!provider) return
7376
dispatch({type: 'SET_WEB3_PROVIDER', provider})
7477

web3/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ export const createProvider = async (network?: string, onChainChange?: (chainId:
1111
const provider = await web3Modal.connect()
1212
if (!provider) return null
1313
onChainChange((new BigNumber(provider.chainId)).toNumber())
14-
if (provider.chainId !== (network ?? '0x13881')) {
15-
await switchNetwork(provider)
16-
}
1714
if (onChainChange) {
1815
provider.on('chainChanged', (id) => {
1916
onChainChange((new BigNumber(id)).toNumber())

0 commit comments

Comments
 (0)