Skip to content

Commit

Permalink
Fix network getting stuck on mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrila committed Jan 25, 2024
1 parent 8e32a3c commit 6922cb5
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/providers/NetworkConfig/NetworkConfigProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<NetworkConfig>(
getNetworkConfig(
provider.network.chainId || isProd() ? mainnetConfig.chainId : goerliConfig.chainId
)
);
const [config, setConfig] = useState<NetworkConfig>(getNetworkConfig(provider.network.chainId));

useEffect(() => {
setConfig(getNetworkConfig(provider.network.chainId));
Expand Down

0 comments on commit 6922cb5

Please sign in to comment.