From b7dacbde51b338800c8ae467a7e4c4971b1cd884 Mon Sep 17 00:00:00 2001 From: Evgeny Taktarov Date: Wed, 6 Mar 2024 13:42:24 +0700 Subject: [PATCH] fix: switch to force disconnect --- .../update-promt-banner/use-version-check.ts | 23 ++++++++++++------- providers/client-config.tsx | 8 ++++++- shared/wallet/connect/connect.tsx | 9 +++++++- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/features/ipfs/update-promt-banner/use-version-check.ts b/features/ipfs/update-promt-banner/use-version-check.ts index 108005229..6c6f353fd 100644 --- a/features/ipfs/update-promt-banner/use-version-check.ts +++ b/features/ipfs/update-promt-banner/use-version-check.ts @@ -1,7 +1,6 @@ import { useEffect, useState } from 'react'; import { useLidoSWR } from '@lido-sdk/react'; -import { useDisconnect } from 'reef-knot/web3-react'; -import { useDisconnect as useDisconnectWagmi } from 'wagmi'; +import { useForceDisconnect } from 'reef-knot/web3-react'; import { BASE_PATH_ASSET, dynamics } from 'config'; import { useMainnetStaticRpcProvider } from 'shared/hooks/use-mainnet-static-rpc-provider'; @@ -9,6 +8,7 @@ import { standardFetcher } from 'utils/standardFetcher'; import { STRATEGY_IMMUTABLE, STRATEGY_LAZY } from 'utils/swrStrategies'; import buildInfo from 'build-info.json'; +import { useClientConfig } from 'providers/client-config'; type EnsHashCheckReturn = { cid: string; @@ -57,8 +57,8 @@ const isVersionLess = (versionA: string, versionB: string): boolean => { }; export const useVersionCheck = () => { - const { disconnect } = useDisconnect(); - const { disconnect: wagmiDisconnect } = useDisconnectWagmi(); + const { setIsWalletConnectionAllowed } = useClientConfig(); + const { disconnect } = useForceDisconnect(); const [areConditionsAccepted, setConditionsAccepted] = useState(false); const provider = useMainnetStaticRpcProvider(); @@ -132,13 +132,20 @@ export const useVersionCheck = () => { const isNotVerifiable = !!remoteVersionSWR.error; - // disconnect wallet + // disconnect wallet and disallow connection for unsafe versions useEffect(() => { if (isVersionUnsafe) { - disconnect?.(); - wagmiDisconnect(); + setIsWalletConnectionAllowed(false); } - }, [disconnect, isVersionUnsafe, wagmiDisconnect]); + if (isVersionUnsafe || (dynamics.ipfsMode && isNotVerifiable)) { + disconnect(); + } + }, [ + disconnect, + isNotVerifiable, + isVersionUnsafe, + setIsWalletConnectionAllowed, + ]); return { setConditionsAccepted, diff --git a/providers/client-config.tsx b/providers/client-config.tsx index f5e40f737..fb1f5119d 100644 --- a/providers/client-config.tsx +++ b/providers/client-config.tsx @@ -23,6 +23,8 @@ type SavedClientConfig = { type ClientConfigContext = EnvConfigParsed & { savedClientConfig: SavedClientConfig; setSavedClientConfig: (config: SavedClientConfig) => void; + isWalletConnectionAllowed: boolean; + setIsWalletConnectionAllowed: (isAllowed: boolean) => void; }; export const ClientConfigContext = createContext( @@ -44,6 +46,8 @@ export const ClientConfigProvider = ({ children }: PropsWithChildren) => { STORAGE_CLIENT_CONFIG, DEFAULT_STATE, ); + const [isWalletConnectionAllowed, setIsWalletConnectionAllowed] = + useState(true); const [savedClientConfig, setSavedClientConfig] = useState(restoredSettings); @@ -63,8 +67,10 @@ export const ClientConfigProvider = ({ children }: PropsWithChildren) => { ...envConfig, savedClientConfig, setSavedClientConfig: setSavedConfigAndRemember, + isWalletConnectionAllowed, + setIsWalletConnectionAllowed, }; - }, [savedClientConfig, setSavedConfigAndRemember]); + }, [isWalletConnectionAllowed, savedClientConfig, setSavedConfigAndRemember]); return ( diff --git a/shared/wallet/connect/connect.tsx b/shared/wallet/connect/connect.tsx index f7276520d..509033270 100644 --- a/shared/wallet/connect/connect.tsx +++ b/shared/wallet/connect/connect.tsx @@ -4,8 +4,10 @@ import { wrapWithEventTrack } from '@lidofinance/analytics-matomo'; import { useModal } from 'shared/hooks'; import { MODAL } from 'providers'; import { MATOMO_CLICK_EVENTS } from 'config'; +import { useClientConfig } from 'providers/client-config'; export const Connect: FC = (props) => { + const { isWalletConnectionAllowed } = useClientConfig(); const { onClick, ...rest } = props; const { openModal } = useModal(MODAL.connect); @@ -15,7 +17,12 @@ export const Connect: FC = (props) => { ); return ( - );