From 8bbb51180d3d795721a8cb6cdbc567c948bd580a Mon Sep 17 00:00:00 2001 From: Evgeny Taktarov Date: Mon, 11 Mar 2024 21:11:42 +0700 Subject: [PATCH] fix: disconnect --- .../update-promt-banner/use-version-check.ts | 3 ++ providers/web3.tsx | 3 +- shared/wallet/wallet-modal/wallet-modal.tsx | 28 ++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/features/ipfs/update-promt-banner/use-version-check.ts b/features/ipfs/update-promt-banner/use-version-check.ts index 1ed8db08e..6508b8505 100644 --- a/features/ipfs/update-promt-banner/use-version-check.ts +++ b/features/ipfs/update-promt-banner/use-version-check.ts @@ -9,6 +9,7 @@ import { STRATEGY_IMMUTABLE, STRATEGY_LAZY } from 'utils/swrStrategies'; import buildInfo from 'build-info.json'; import { useClientConfig } from 'providers/client-config'; +import { useWeb3 } from 'reef-knot/web3-react'; export const NO_SAFE_VERSION = 'NONE_AVAILABLE'; @@ -59,6 +60,7 @@ const isVersionLess = (versionA: string, versionB: string): boolean => { }; export const useVersionCheck = () => { + const { active } = useWeb3(); const { setIsWalletConnectionAllowed } = useClientConfig(); const { forceDisconnect } = useForceDisconnect(); const [areConditionsAccepted, setConditionsAccepted] = useState(false); @@ -143,6 +145,7 @@ export const useVersionCheck = () => { forceDisconnect(); } }, [ + active, forceDisconnect, isNotVerifiable, isVersionUnsafe, diff --git a/providers/web3.tsx b/providers/web3.tsx index dd7a27208..2cbcb5dd6 100644 --- a/providers/web3.tsx +++ b/providers/web3.tsx @@ -81,11 +81,12 @@ const Web3Provider: FC = ({ children }) => { return createClient({ connectors, - autoConnect: true, + autoConnect: isWalletConnectionAllowed, provider, webSocketProvider, }); }, [ + isWalletConnectionAllowed, supportedChains, defaultChain, backendRPC, diff --git a/shared/wallet/wallet-modal/wallet-modal.tsx b/shared/wallet/wallet-modal/wallet-modal.tsx index 08c54b9d6..33361423b 100644 --- a/shared/wallet/wallet-modal/wallet-modal.tsx +++ b/shared/wallet/wallet-modal/wallet-modal.tsx @@ -1,3 +1,4 @@ +import { useCallback } from 'react'; import { ButtonIcon, Modal, @@ -6,12 +7,12 @@ import { Copy, Address, } from '@lidofinance/lido-ui'; +import { useEtherscanOpen } from '@lido-sdk/react'; +import { useConnectorInfo, useDisconnect } from 'reef-knot/core-react'; +import { useWeb3 } from 'reef-knot/web3-react'; + import type { ModalComponentType } from 'providers/modal-provider'; -import { useEtherscanOpen, useSDK } from '@lido-sdk/react'; -import { useConnectorInfo, useDisconnect } from 'reef-knot/web3-react'; import { useCopyToClipboard } from 'shared/hooks'; -import { useCallback } from 'react'; -import { useDisconnect as useDisconnectWagmi } from 'wagmi'; import { WalletModalContentStyle, WalletModalConnectedStyle, @@ -22,31 +23,26 @@ import { WalletModalActionsStyle, } from './styles'; -export const WalletModal: ModalComponentType = (props) => { - const { onClose } = props; - const { account } = useSDK(); - const { providerName } = useConnectorInfo(); +export const WalletModal: ModalComponentType = ({ onClose, ...props }) => { + const { account } = useWeb3(); + const { connectorName } = useConnectorInfo(); const { disconnect } = useDisconnect(); - const { disconnect: wagmiDisconnect } = useDisconnectWagmi(); const handleDisconnect = useCallback(() => { - // disconnect wallets connected through web3-react connectors disconnect?.(); - // disconnect wallets connected through wagmi connectors - wagmiDisconnect(); onClose?.(); - }, [disconnect, onClose, wagmiDisconnect]); + }, [disconnect, onClose]); const handleCopy = useCopyToClipboard(account ?? ''); const handleEtherscan = useEtherscanOpen(account ?? '', 'address'); return ( - + - {providerName && ( + {connectorName && ( - Connected with {providerName} + Connected with {connectorName} )}