Skip to content

Commit

Permalink
fix: switch to force disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeday committed Mar 6, 2024
1 parent 1d6c4c1 commit b7dacbd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
23 changes: 15 additions & 8 deletions features/ipfs/update-promt-banner/use-version-check.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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';
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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion providers/client-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClientConfigContext | null>(
Expand All @@ -44,6 +46,8 @@ export const ClientConfigProvider = ({ children }: PropsWithChildren) => {
STORAGE_CLIENT_CONFIG,
DEFAULT_STATE,
);
const [isWalletConnectionAllowed, setIsWalletConnectionAllowed] =
useState(true);

const [savedClientConfig, setSavedClientConfig] =
useState<SavedClientConfig>(restoredSettings);
Expand All @@ -63,8 +67,10 @@ export const ClientConfigProvider = ({ children }: PropsWithChildren) => {
...envConfig,
savedClientConfig,
setSavedClientConfig: setSavedConfigAndRemember,
isWalletConnectionAllowed,
setIsWalletConnectionAllowed,
};
}, [savedClientConfig, setSavedConfigAndRemember]);
}, [isWalletConnectionAllowed, savedClientConfig, setSavedConfigAndRemember]);

return (
<ClientConfigContext.Provider value={contextValue}>
Expand Down
9 changes: 8 additions & 1 deletion shared/wallet/connect/connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ButtonProps> = (props) => {
const { isWalletConnectionAllowed } = useClientConfig();
const { onClick, ...rest } = props;
const { openModal } = useModal(MODAL.connect);

Expand All @@ -15,7 +17,12 @@ export const Connect: FC<ButtonProps> = (props) => {
);

return (
<Button onClick={handleClick} data-testid="connectBtn" {...rest}>
<Button
disabled={!isWalletConnectionAllowed}
onClick={handleClick}
data-testid="connectBtn"
{...rest}
>
Connect wallet
</Button>
);
Expand Down

0 comments on commit b7dacbd

Please sign in to comment.