From 6922cb56f4ed7c922753fb02b708f6cb4b57d969 Mon Sep 17 00:00:00 2001 From: Kirill Klimenko Date: Thu, 25 Jan 2024 14:51:05 +0100 Subject: [PATCH] Fix network getting stuck on mainnet --- .../NetworkConfig/NetworkConfigProvider.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/providers/NetworkConfig/NetworkConfigProvider.tsx b/src/providers/NetworkConfig/NetworkConfigProvider.tsx index 2f1b942f7b..27c511c6ee 100644 --- a/src/providers/NetworkConfig/NetworkConfigProvider.tsx +++ b/src/providers/NetworkConfig/NetworkConfigProvider.tsx @@ -18,18 +18,21 @@ export const supportedChains: NetworkConfig[] = isProd() export const disconnectedChain: Chain = supportedChains[0].wagmiChain; const getNetworkConfig = (chainId: number) => { - return supportedChains.find(chain => chain.chainId === chainId) || isProd() - ? mainnetConfig - : goerliConfig; + const foundChain = supportedChains.find(chain => chain.chainId === chainId); + if (foundChain) { + return foundChain; + } else { + if (isProd()) { + return mainnetConfig; + } else { + return goerliConfig; + } + } }; export function NetworkConfigProvider({ children }: { children: ReactNode }) { const provider = useProvider(); - const [config, setConfig] = useState( - getNetworkConfig( - provider.network.chainId || isProd() ? mainnetConfig.chainId : goerliConfig.chainId - ) - ); + const [config, setConfig] = useState(getNetworkConfig(provider.network.chainId)); useEffect(() => { setConfig(getNetworkConfig(provider.network.chainId));