Skip to content

Commit

Permalink
fix(wallets): send request to switch network (#3551)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 authored Dec 22, 2023
1 parent a6eaaf0 commit 2bbb745
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions libs/wallet/src/web3-react/connection/injected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ import { ConnectionOptionProps, Web3ReactConnection } from '../types'

import { onError } from './onError'
import { useIsActiveConnection } from '../hooks/useIsActiveConnection'
import { AddEthereumChainParameter } from '@web3-react/types'

class MetaMaskEnhanced extends MetaMask {
/**
* The trick is to override the activate method in order to call it without parameters
* Because if we call it as activate(chainId)
* It will request network change if the wallet is connected to a different chain
*
* @param chain when number, it means the initial request to connect, otherwise it's a request to change network
*/
activate(): Promise<void> {
return super.activate()
activate(chain: number | AddEthereumChainParameter): Promise<void> {
return super.activate(typeof chain === 'number' ? undefined : chain)
}
}

Expand Down

0 comments on commit 2bbb745

Please sign in to comment.