Skip to content

Commit

Permalink
Merge pull request #535 from lidofinance/feature/si-1641-refactoring-…
Browse files Browse the repository at this point in the history
…single-source-of-truth-for-chainid-and-rpc

fix: fallback for testnets
  • Loading branch information
itaven authored Nov 5, 2024
2 parents 41cb95d + 9b8357d commit 31ff128
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 161 deletions.
13 changes: 8 additions & 5 deletions modules/web3/web3-provider/sdk-legacy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ProviderSDK } from '@lido-sdk/react';
import { useLidoSDK } from './lido-sdk';
import { config } from 'config';
import { isSDKSupportedL2Chain } from 'consts/chains';
import { useMainnetStaticRpcProvider } from 'shared/hooks/use-mainnet-static-rpc-provider';

// Stabilizes network detection to prevent repeated chainId calls
class EthersToViemProvider extends Web3Provider {
Expand Down Expand Up @@ -61,12 +62,14 @@ export const SDKLegacyProvider = ({ children }: PropsWithChildren) => {
);
}, [onlyL1chainId, onlyL1publicClient]);

// Fallback for when mainnet is not present in supported chains
const staticMainnetProvider = useMainnetStaticRpcProvider();

const providerMainnetRpc = useMemo(() => {
return (
publicMainnetClient &&
new EthersToViemProvider(publicMainnetClient.transport, 1)
);
}, [publicMainnetClient]);
return publicMainnetClient
? new EthersToViemProvider(publicMainnetClient.transport, 1)
: staticMainnetProvider;
}, [publicMainnetClient, staticMainnetProvider]);

return (
// @ts-expect-error Property children does not exist on type
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@
"react-hook-form": "^7.45.2",
"react-is": "^18.2.0",
"react-transition-group": "^4.4.2",
"reef-knot": "5.7.4",
"reef-knot": "5.7.5",
"styled-components": "^5.3.5",
"swr": "^1.3.0",
"tiny-async-pool": "^1.2.0",
"tiny-invariant": "^1.1.0",
"uuid": "^8.3.2",
"viem": "2.21.25",
"wagmi": "2.12.17"
"viem": "2.21.40",
"wagmi": "2.12.25"
},
"devDependencies": {
"@commitlint/cli": "^17.4.4",
Expand Down
Loading

0 comments on commit 31ff128

Please sign in to comment.