From d79850d0e41ea0e050674c69bcbcf091d0ab8015 Mon Sep 17 00:00:00 2001 From: Bayological <6872903+bayological@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:20:39 -0500 Subject: [PATCH] fix: wallet connect stale storage issue (#151) --- src/components/nav/ConnectButton.tsx | 8 +++++++- src/components/nav/NetworkModal.tsx | 30 +++++++++++++++------------- src/config/wallets.ts | 28 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/components/nav/ConnectButton.tsx b/src/components/nav/ConnectButton.tsx index 1f813eb..934dd4b 100644 --- a/src/components/nav/ConnectButton.tsx +++ b/src/components/nav/ConnectButton.tsx @@ -6,6 +6,7 @@ import { Identicon } from 'src/components/Identicon' import { SolidButton } from 'src/components/buttons/SolidButton' import { BalancesSummary } from 'src/components/nav/BalancesSummary' import { NetworkModal } from 'src/components/nav/NetworkModal' +import { cleanupStaleWalletSessions } from 'src/config/wallets' import ClipboardDark from 'src/images/icons/clipboard-plus-dark.svg' import Clipboard from 'src/images/icons/clipboard-plus.svg' import CubeDark from 'src/images/icons/cube-dark.svg' @@ -24,6 +25,11 @@ export function ConnectButton() { const { openConnectModal } = useConnectModal() const { disconnect } = useDisconnect() + const onClickConnect = () => { + cleanupStaleWalletSessions() + openConnectModal?.() + } + const onClickCopy = async () => { if (!address) return await tryClipboardSet(address) @@ -91,7 +97,7 @@ export function ConnectButton() { styles="sm:mr-3" /> } - onClick={openConnectModal} + onClick={onClickConnect} >
Connect
diff --git a/src/components/nav/NetworkModal.tsx b/src/components/nav/NetworkModal.tsx index b4f9ae3..daf45c3 100644 --- a/src/components/nav/NetworkModal.tsx +++ b/src/components/nav/NetworkModal.tsx @@ -1,5 +1,6 @@ import { toast } from 'react-toastify' import { ChainMetadata, allChains, chainIdToChain } from 'src/config/chains' +import { cleanupStaleWalletSessions } from 'src/config/wallets' import { reset as accountReset } from 'src/features/accounts/accountSlice' import { reset as blockReset } from 'src/features/blocks/blockSlice' import { resetTokenPrices } from 'src/features/chart/tokenPriceSlice' @@ -25,6 +26,7 @@ export function NetworkModal({ isOpen, close }: Props) { try { if (!switchNetworkAsync) throw new Error('switchNetworkAsync undefined') logger.debug('Resetting and switching to network', c.name) + cleanupStaleWalletSessions() await switchNetworkAsync(c.chainId) dispatch(blockReset()) dispatch(accountReset()) @@ -38,9 +40,9 @@ export function NetworkModal({ isOpen, close }: Props) { return ( -
-
-
+
+
+
Connected to:
@@ -49,7 +51,7 @@ export function NetworkModal({ isOpen, close }: Props) {
-
+
Block Number:
@@ -58,7 +60,7 @@ export function NetworkModal({ isOpen, close }: Props) {
-
+
Node Rpc Url:
@@ -69,7 +71,7 @@ export function NetworkModal({ isOpen, close }: Props) {
-
+
{allChains.map((c) => (