From 2bbb74548a290480c6b3001e7e4a8b2eff9032e0 Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Fri, 22 Dec 2023 16:28:12 +0600 Subject: [PATCH] fix(wallets): send request to switch network (#3551) --- libs/wallet/src/web3-react/connection/injected.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/wallet/src/web3-react/connection/injected.tsx b/libs/wallet/src/web3-react/connection/injected.tsx index 873bb88042..212f79ae25 100644 --- a/libs/wallet/src/web3-react/connection/injected.tsx +++ b/libs/wallet/src/web3-react/connection/injected.tsx @@ -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 { - return super.activate() + activate(chain: number | AddEthereumChainParameter): Promise { + return super.activate(typeof chain === 'number' ? undefined : chain) } }