Skip to content

Commit

Permalink
feat: add network error throw
Browse files Browse the repository at this point in the history
  • Loading branch information
simodrws committed Aug 29, 2023
1 parent 2347b12 commit ac0675f
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/refactor/wallet-client/network/use-network.ts
Expand Up @@ -37,22 +37,30 @@ export const useNetwork = () => {

const switchNetwork = useCallback(
(chainId?: number) => {
setSwitchingToChain(chainId);
if (!chainId) return;
switchNetworkWagmi?.(chainId);
try {
setSwitchingToChain(chainId);
if (!chainId) return;
switchNetworkWagmi?.(chainId);
} catch (error: unknown) {
throw error as Error;
}
},
[switchNetworkWagmi]
);

const switchNetworkByName = useCallback(
(forcedNetworkParam: NetworkName) => {
const networkToSwitchTo = SupportedNetworks[forcedNetworkParam];
setSwitchingToChain(networkToSwitchTo?.chainId);
if (networkToSwitchTo) {
if (networkToSwitchTo.chainId === activeChain?.id) {
return;
try {
const networkToSwitchTo = SupportedNetworks[forcedNetworkParam];
setSwitchingToChain(networkToSwitchTo?.chainId);
if (networkToSwitchTo) {
if (networkToSwitchTo.chainId === activeChain?.id) {
return;
}
switchNetworkWagmi?.(networkToSwitchTo.chainId);
}
switchNetworkWagmi?.(networkToSwitchTo.chainId);
} catch (error: unknown) {
throw error as Error;
}
},
[activeChain?.id, switchNetworkWagmi]
Expand All @@ -74,7 +82,7 @@ export const useNetwork = () => {
}, [activeChain]);

const currentNetworkByChainId = useMemo(() => {
if (!activeChainId) return 0;
if (!activeChainId) return undefined;
return getNetworkNameByChainId(activeChainId);
}, [activeChainId]);

Expand Down

0 comments on commit ac0675f

Please sign in to comment.