Skip to content

Commit

Permalink
Merge pull request #1341 from decent-dao/fix/fix-network-getting-stuck
Browse files Browse the repository at this point in the history
Fix network getting stuck on mainnet
  • Loading branch information
mudrila authored Jan 25, 2024
2 parents 8e32a3c + 6922cb5 commit 8683b76
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 8683b76

Please sign in to comment.