Skip to content

Commit

Permalink
fix: async condition legacy sdk chainId
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeday committed Nov 6, 2024
1 parent 9b8357d commit 6588293
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
2 changes: 1 addition & 1 deletion modules/web3/web3-provider/lido-sdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
11 changes: 2 additions & 9 deletions modules/web3/web3-provider/sdk-legacy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 &&
Expand Down

0 comments on commit 6588293

Please sign in to comment.