Skip to content

Commit

Permalink
refactor: update useWalletClient to use isFetchedAfterMount for chain…
Browse files Browse the repository at this point in the history
… switching logic
  • Loading branch information
Da-Colon committed Dec 17, 2024
1 parent 3a6d01e commit 63c1575
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/hooks/utils/useAutomaticSwitchChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const useAutomaticSwitchChain = ({
urlAddressPrefix: string | undefined;
}) => {
const { setCurrentConfig, getConfigByChainId, addressPrefix } = useNetworkConfigStore();
const { isFetched } = useWalletClient();
const { isFetchedAfterMount } = useWalletClient();
const { switchChain } = useSwitchChain({
mutation: {
onError: () => {
Expand All @@ -26,7 +26,11 @@ export const useAutomaticSwitchChain = ({
return;
}
const chainId = getChainIdFromPrefix(urlAddressPrefix);
if (addressPrefix !== urlAddressPrefix && urlAddressPrefix !== undefined && isFetched) {
if (
addressPrefix !== urlAddressPrefix &&
urlAddressPrefix !== undefined &&
isFetchedAfterMount
) {
switchChain({ chainId });
}
setTimeout(() => setCurrentConfig(getConfigByChainId(chainId)), 300);
Expand All @@ -36,6 +40,6 @@ export const useAutomaticSwitchChain = ({
getConfigByChainId,
urlAddressPrefix,
switchChain,
isFetched,
isFetchedAfterMount,
]);
};

0 comments on commit 63c1575

Please sign in to comment.