Skip to content

Commit

Permalink
fix: united polling interval to transports
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeday committed Aug 2, 2024
1 parent 04bb4b0 commit f592e9b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
6 changes: 3 additions & 3 deletions config/get-config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { getPreConfig, PreConfigType } from './get-preconfig';
import * as cache from './groups/cache';
import * as estimate from './groups/estimate';
import * as ipfs from './groups/ipfs';
import * as locale from './groups/locale';
import * as stake from './groups/stake';
import * as web3 from './groups/web3';
import * as withdrawalQueueEstimate from './groups/withdrawal-queue-estimate';

export type ConfigType = {
isClientSide: boolean;
isServerSide: boolean;
} & typeof cache &
typeof estimate &
typeof ipfs &
typeof web3 &
typeof locale &
typeof stake &
typeof withdrawalQueueEstimate &
Expand All @@ -23,7 +23,7 @@ export const getConfig = (): ConfigType => {
isServerSide: typeof window === 'undefined',

...cache,
...estimate,
...web3,
...ipfs,
...locale,
...stake,
Expand Down
3 changes: 3 additions & 0 deletions config/groups/estimate.ts → config/groups/web3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { parseEther } from '@ethersproject/units';

// interval in ms for RPC event polling for token balance and tx updates
export const PROVIDER_POLLING_INTERVAL = 12_000;

// account for gas estimation
// will always have >=0.001 ether, >=0.001 stETH, >=0.001 wstETH
// on Mainnet, Holesky
Expand Down
14 changes: 6 additions & 8 deletions providers/sdk-legacy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ import { mainnet } from 'wagmi/chains';
import { getStaticRpcBatchProvider } from '@lido-sdk/providers';
import { useReefKnotContext } from 'reef-knot/core-react';

const POLLING_INTERVAL = 12_000;

type SDKLegacyProviderProps = PropsWithChildren<{
defaultChainId: number;
pollingInterval?: number;
pollingInterval: number;
}>;

export const SDKLegacyProvider = ({
children,
defaultChainId,
pollingInterval = POLLING_INTERVAL,
pollingInterval,
}: SDKLegacyProviderProps) => {
const { chainId: web3ChainId = defaultChainId, account, active } = useWeb3();
const { supportedChains } = useSupportedChains();
Expand Down Expand Up @@ -81,8 +79,8 @@ export const SDKLegacyProvider = ({
}, [defaultChainId, supportedChainIds, web3ChainId]);

const providerRpc = useMemo(
() => getStaticRpcBatchProvider(chainId, rpc[chainId], 0, POLLING_INTERVAL),
[rpc, chainId],
() => getStaticRpcBatchProvider(chainId, rpc[chainId], 0, pollingInterval),
[rpc, chainId, pollingInterval],
);

const providerMainnetRpc = useMemo(
Expand All @@ -91,9 +89,9 @@ export const SDKLegacyProvider = ({
mainnet.id,
rpc[mainnet.id],
0,
POLLING_INTERVAL,
pollingInterval,
),
[rpc],
[rpc, pollingInterval],
);

return (
Expand Down
17 changes: 14 additions & 3 deletions providers/web3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from 'reef-knot/core-react';
import { WalletsListEthereum } from 'reef-knot/wallets';

import { config } from 'config';
import { useUserConfig } from 'config/user-config';
import { useGetRpcUrlByChainId } from 'config/rpc';
import { CHAINS } from 'consts/chains';
Expand Down Expand Up @@ -67,11 +68,18 @@ const Web3Provider: FC<PropsWithChildren> = ({ children }) => {
});
}, [backendRPC, defaultChain, walletconnectProjectId]);

const config = useMemo(() => {
const wagmiConfig = useMemo(() => {
return createConfig({
chains: supportedChains,
ssr: true,
batch: {
// eth_call's will be batched via multicall contract every 100ms
multicall: {
wait: 100,
},
},
multiInjectedProviderDiscovery: false,
pollingInterval: config.PROVIDER_POLLING_INTERVAL,
transports: supportedChains.reduce(
(res, curr) => ({
...res,
Expand All @@ -84,15 +92,18 @@ const Web3Provider: FC<PropsWithChildren> = ({ children }) => {

return (
// default wagmi autoConnect, MUST be false in our case, because we use custom autoConnect from Reef Knot
<WagmiProvider config={config} reconnectOnMount={false}>
<WagmiProvider config={wagmiConfig} reconnectOnMount={false}>
<QueryClientProvider client={queryClient}>
<ReefKnot
rpc={backendRPC}
chains={supportedChains}
walletDataList={walletsDataList}
>
{isWalletConnectionAllowed && <AutoConnect autoConnect />}
<SDKLegacyProvider defaultChainId={defaultChain.id}>
<SDKLegacyProvider
defaultChainId={defaultChain.id}
pollingInterval={config.PROVIDER_POLLING_INTERVAL}
>
{children}
<ConnectWalletModal />
</SDKLegacyProvider>
Expand Down
4 changes: 3 additions & 1 deletion shared/hooks/useApprove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ApproveOptions =
| undefined;

export type UseApproveResponse = {
approve: (options?: ApproveOptions) => Promise<void>;
approve: (options?: ApproveOptions) => Promise<string>;
needsApprove: boolean;
initialLoading: boolean;
allowance: BigNumber | undefined;
Expand Down Expand Up @@ -87,6 +87,8 @@ export const useApprove = (
}

await updateAllowance();

return approveTxHash;
},
[
chainId,
Expand Down

0 comments on commit f592e9b

Please sign in to comment.