Skip to content

Commit

Permalink
fix: disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeday committed Mar 11, 2024
1 parent 410a98a commit 8bbb511
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
3 changes: 3 additions & 0 deletions features/ipfs/update-promt-banner/use-version-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -143,6 +145,7 @@ export const useVersionCheck = () => {
forceDisconnect();
}
}, [
active,
forceDisconnect,
isNotVerifiable,
isVersionUnsafe,
Expand Down
3 changes: 2 additions & 1 deletion providers/web3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ const Web3Provider: FC<PropsWithChildren> = ({ children }) => {

return createClient({
connectors,
autoConnect: true,
autoConnect: isWalletConnectionAllowed,
provider,
webSocketProvider,
});
}, [
isWalletConnectionAllowed,
supportedChains,
defaultChain,
backendRPC,
Expand Down
28 changes: 12 additions & 16 deletions shared/wallet/wallet-modal/wallet-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useCallback } from 'react';
import {
ButtonIcon,
Modal,
Expand All @@ -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,
Expand All @@ -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 (
<Modal title="Account" {...props}>
<Modal title="Account" onClose={onClose} {...props}>
<WalletModalContentStyle>
<WalletModalConnectedStyle>
{providerName && (
{connectorName && (
<WalletModalConnectorStyle data-testid="providerName">
Connected with {providerName}
Connected with {connectorName}
</WalletModalConnectorStyle>
)}

Expand Down

0 comments on commit 8bbb511

Please sign in to comment.