From 658829394379c3b1d26aeb6a2ac090d500fa385f Mon Sep 17 00:00:00 2001 From: Evgeny Taktarov Date: Wed, 6 Nov 2024 17:03:28 +0900 Subject: [PATCH] fix: async condition legacy sdk chainId --- modules/web3/web3-provider/lido-sdk.tsx | 2 +- modules/web3/web3-provider/sdk-legacy.tsx | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/modules/web3/web3-provider/lido-sdk.tsx b/modules/web3/web3-provider/lido-sdk.tsx index 87b0795f7..bc459859e 100644 --- a/modules/web3/web3-provider/lido-sdk.tsx +++ b/modules/web3/web3-provider/lido-sdk.tsx @@ -43,7 +43,7 @@ export const useLidoSDK = () => { export const LidoSDKProvider = ({ children }: React.PropsWithChildren) => { const subscribe = useTokenTransferSubscription(); - // will only have + // will only have supported chains from wagmi config const chainId = useChainId(); const { data: walletClient } = useWalletClient({ chainId }); const publicClient = usePublicClient({ chainId }); diff --git a/modules/web3/web3-provider/sdk-legacy.tsx b/modules/web3/web3-provider/sdk-legacy.tsx index 9d050c82f..cb949dd65 100644 --- a/modules/web3/web3-provider/sdk-legacy.tsx +++ b/modules/web3/web3-provider/sdk-legacy.tsx @@ -22,7 +22,7 @@ class EthersToViemProvider extends Web3Provider { export const SDKLegacyProvider = ({ children }: PropsWithChildren) => { const { defaultChain, supportedChains, PROVIDER_POLLING_INTERVAL } = config; - const { address } = useAccount(); + const { address, isConnected } = useAccount(); const { core, isL2, chainId } = useLidoSDK(); const supportedChainIds = useMemo( @@ -44,17 +44,10 @@ export const SDKLegacyProvider = ({ children }: PropsWithChildren) => { return provider; }, [isL2, core, PROVIDER_POLLING_INTERVAL]); - const onlyL1chainId = useMemo(() => { - if (ethersWeb3Provider) { - return chainId; - } - return defaultChain; - }, [chainId, defaultChain, ethersWeb3Provider]); - + const onlyL1chainId = isConnected && !isL2 ? chainId : defaultChain; const onlyL1publicClient = usePublicClient({ chainId: onlyL1chainId }); const publicMainnetClient = usePublicClient({ chainId: 1 }); - // only Web3Provider can accept viem transport const providerRpc = useMemo(() => { return ( onlyL1publicClient &&