From f98f4004ee8f8cae4b6f26de5b26132ad0db67b1 Mon Sep 17 00:00:00 2001 From: belopash Date: Fri, 17 May 2024 14:54:26 +0500 Subject: [PATCH] fix: try to fix infinite switch loop --- src/layouts/NetworkLayout/NetworkLayout.tsx | 4 ++-- src/network/useSubsquidNetwork.ts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/layouts/NetworkLayout/NetworkLayout.tsx b/src/layouts/NetworkLayout/NetworkLayout.tsx index 0ce529b..6c3e5a8 100644 --- a/src/layouts/NetworkLayout/NetworkLayout.tsx +++ b/src/layouts/NetworkLayout/NetworkLayout.tsx @@ -267,8 +267,8 @@ export const NetworkLayout = ({ if (chain?.id === getChainId(network)) return; - if (!chain?.unsupported) { - switchAndReset(getNetworkName(chain?.id)); + if (chain && !chain?.unsupported) { + switchAndReset(getNetworkName(chain.id)); return; } diff --git a/src/network/useSubsquidNetwork.ts b/src/network/useSubsquidNetwork.ts index a77bc3a..05c8854 100644 --- a/src/network/useSubsquidNetwork.ts +++ b/src/network/useSubsquidNetwork.ts @@ -24,6 +24,8 @@ export function useSubsquidNetwork() { const queryClient = useQueryClient(); const switchAndReset = (network: NetworkName) => { + if (app == network) return; + changeApp(network); queryClient.clear(); }; @@ -35,6 +37,6 @@ export function getChainId(network: NetworkName) { return network === NetworkName.Mainnet ? arbitrum.id : arbitrumSepolia.id; } -export function getNetworkName(chainId?: number) { +export function getNetworkName(chainId: number) { return chainId === arbitrum.id ? NetworkName.Mainnet : NetworkName.Testnet; }