Skip to content

Commit

Permalink
Merge branch 'develop' into feature/si-1588-rework-reef-knot-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
manneredboor authored Nov 19, 2024
2 parents d8856ca + 03b5812 commit d8b8e96
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { BigNumber } from 'ethers';
import { useSDK } from '@lido-sdk/react';
import { Link, Loader } from '@lidofinance/lido-ui';

import { config } from 'config';
import { WITHDRAWALS_CLAIM_PATH } from 'consts/urls';
import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events';
import { trackMatomoEvent } from 'utils/track-matomo-event';
import { useIsMetamask } from 'modules/web3';

import { useNftDataByTxHash } from 'features/withdrawals/hooks/useNftDataByTxHash';
import { useTransactionModal } from 'shared/transaction-modal/transaction-modal';
Expand Down Expand Up @@ -37,10 +37,10 @@ export const TxRequestStageSuccess = ({
amount,
}: TxRequestStageSuccessProps) => {
const amountEl = <TxAmount amount={amount} symbol={tokenName} />;
const { providerWeb3 } = useSDK();
const showAddGuideLink = useIsMetamask();

const { data: nftData, initialLoading: nftLoading } =
useNftDataByTxHash(txHash);
const showAddGuideLink = !!providerWeb3?.provider.isMetaMask;
const { closeModal } = useTransactionModal();

const successDescription = (
Expand Down
1 change: 1 addition & 0 deletions modules/web3/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './use-is-multisig';
export * from './use-stETH-by-wstETH-on-l2';
export * from './use-wstETH-by-stETH-on-l2';
export * from './use-staking-limit-warning';
export * from './use-is-metamask';
9 changes: 8 additions & 1 deletion modules/web3/hooks/use-allowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { BigNumber } from 'ethers';
import { Address, WatchContractEventOnLogsFn } from 'viem';
import { useReadContract, useWatchContractEvent } from 'wagmi';

import { config } from 'config';

import { useDappStatus } from './use-dapp-status';

const nativeToBN = (data: bigint) => BigNumber.from(data.toString());
Expand Down Expand Up @@ -86,6 +88,11 @@ export const useAllowance = ({
query: {
enabled,
select: nativeToBN,
// because we update on events we can have high staleTime
// this prevents loader when changing pages
// but safes us from laggy user RPCs
staleTime: config.PROVIDER_POLLING_INTERVAL * 2,
refetchInterval: config.PROVIDER_POLLING_INTERVAL * 2,
},
});

Expand All @@ -100,7 +107,7 @@ export const useAllowance = ({
},
// queryKey is unstable
// eslint-disable-next-line react-hooks/exhaustive-deps
[account, spender, token],
[chainId, account, spender, token],
);

useWatchContractEvent({
Expand Down
4 changes: 3 additions & 1 deletion modules/web3/hooks/use-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ const useTokenBalance = (
select: nativeToBN,
// because we update on events we can have high staleTime
// this prevents loader when changing pages
staleTime: 30_000,
// but safes us from laggy user RPCs
staleTime: config.PROVIDER_POLLING_INTERVAL * 2,
refetchInterval: config.PROVIDER_POLLING_INTERVAL * 2,
},
});

Expand Down
13 changes: 13 additions & 0 deletions modules/web3/hooks/use-is-metamask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useConnections } from 'wagmi';
import { injected } from 'wagmi/connectors';

export const useIsMetamask = () => {
const connector = useConnections()[0]?.connector;
if (!connector) return false;
// eip6963
if (connector.rdns === 'io.metamask') return true;
// legacy
return !!(
connector.type === injected.type && (window?.ethereum as any)?.isMetaMask
);
};
2 changes: 1 addition & 1 deletion modules/web3/web3-provider/dapp-chain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const SupportL2Chains: React.FC<React.PropsWithChildren> = ({
);

useEffect(() => {
if (!walletChainId) {
if (!walletChainId || !config.supportedChains.includes(walletChainId)) {
// This code resets 'chainType' to ETH when the wallet is disconnected.
// It also works on the first rendering, but we don't care, because the 'chainType' by default is ETH.
// Don't use it if you need to do something strictly, only when the wallet is disconnected.
Expand Down
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
"tiny-async-pool": "^1.2.0",
"tiny-invariant": "^1.1.0",
"uuid": "^8.3.2",
"viem": "2.21.40",
"wagmi": "2.12.25"
"viem": "2.21.42",
"wagmi": "2.12.27"
},
"devDependencies": {
"@commitlint/cli": "^17.4.4",
Expand Down
7 changes: 5 additions & 2 deletions shared/components/tx-link-etherscan/tx-link-etherscan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ type TxLinkEtherscanProps = {

export const TxLinkEtherscan = (props: TxLinkEtherscanProps) => {
const { txHash, text = 'View on Etherscan', onClick } = props;
const { chainId } = useDappStatus();
const { walletChainId } = useDappStatus();

if (!txHash) return null;

// This component is used in TransactionModal, which is wrapped by SupportL1Chains,
// but not wrapped by SupportL2Chains (the chainId will never be a L2 network).
// This is currently the fastest solution.
return (
<Link
onClick={onClick}
href={getEtherscanTxLink(chainId as CHAINS, txHash)}
href={getEtherscanTxLink(walletChainId as CHAINS, txHash)}
>
{text}
</Link>
Expand Down
14 changes: 11 additions & 3 deletions shared/wallet/wallet-modal/wallet-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { openWindow } from '@lido-sdk/helpers';
import { useConnectorInfo, useDisconnect } from 'reef-knot/core-react';

import { CHAINS } from 'consts/chains';
import type { ModalComponentType } from 'providers/modal-provider';
import { useCopyToClipboard } from 'shared/hooks';
import { getEtherscanAddressLink } from 'utils/get-etherscan-address-link';
Expand All @@ -25,7 +26,7 @@ import {
import { useDappStatus } from 'modules/web3';

export const WalletModal: ModalComponentType = ({ onClose, ...props }) => {
const { address, chainId } = useDappStatus();
const { address, chainId, walletChainId } = useDappStatus();
const { connectorName } = useConnectorInfo();
const { disconnect } = useDisconnect();

Expand All @@ -36,9 +37,16 @@ export const WalletModal: ModalComponentType = ({ onClose, ...props }) => {

const handleCopy = useCopyToClipboard(address ?? '');
const handleEtherscan = useCallback(() => {
const link = getEtherscanAddressLink(chainId, address ?? '', chainId);
// This component is wrapped by SupportL1Chains,
// but not wrapped by SupportL2Chains (the chainId will never be a L2 network).
// This is currently the fastest solution.
const link = getEtherscanAddressLink(
walletChainId as CHAINS,
address ?? '',
chainId,
);
openWindow(link);
}, [address, chainId]);
}, [address, chainId, walletChainId]);

useEffect(() => {
// Close the modal if a wallet was somehow disconnected while the modal was open
Expand Down
36 changes: 18 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3994,10 +3994,10 @@
resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.2.0.tgz#756641adb587851b5ccb3e095daf27ae581c8406"
integrity sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==

"@wagmi/[email protected].3":
version "5.3.3"
resolved "https://registry.yarnpkg.com/@wagmi/connectors/-/connectors-5.3.3.tgz#ef823eeebeaa72852c0e5176bc5308f5cb8699ec"
integrity sha512-RUgwgqX7H+qg1lXBhLqcG0D5xb8USlAv4MVai4r5YpRw6lxpDvELFXxHN4ldZuUARKhH7Q3ZpfvdWyEXY+wn9w==
"@wagmi/[email protected].5":
version "5.3.5"
resolved "https://registry.yarnpkg.com/@wagmi/connectors/-/connectors-5.3.5.tgz#79a15011c0fcd24e40e1dd1631d1744e8b09cc82"
integrity sha512-M6JTaRFN7Q50no9Rpth2azUQn1ZwiFz0NrDEumpJWqdKh6Yz0zNhqFIcalJ/8PigCHnGXXw5cVY9CtN93nQ4uQ==
dependencies:
"@coinbase/wallet-sdk" "4.1.0"
"@metamask/sdk" "0.30.1"
Expand All @@ -4006,10 +4006,10 @@
"@walletconnect/ethereum-provider" "2.17.0"
cbw-sdk "npm:@coinbase/[email protected]"

"@wagmi/[email protected].1":
version "2.14.1"
resolved "https://registry.yarnpkg.com/@wagmi/core/-/core-2.14.1.tgz#e6adb8a350cfd7be4ea9c5581768f951c60127de"
integrity sha512-Vl7VK5XdKxPfnYlp3E7U7AJSweBdfh+cd953hgAU2H+uNrekS9Nmt89l1b6WkwkYyqvccRDjsCtlcKRwvPtNAQ==
"@wagmi/[email protected].3":
version "2.14.3"
resolved "https://registry.yarnpkg.com/@wagmi/core/-/core-2.14.3.tgz#030d3f8775e7d9855f639de8eb242669b1975cfb"
integrity sha512-KpbejlQcXa5w6G9c0cXMspZJ/+ni3HzhybhoBCk9lWbQgGkI5o27Ay+FVR7TI6sMG8V5sG/XE51Rscyqg8xiNg==
dependencies:
eventemitter3 "5.0.1"
mipd "0.0.7"
Expand Down Expand Up @@ -10952,10 +10952,10 @@ vary@^1:
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==

[email protected].40:
version "2.21.40"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.21.40.tgz#d73a515e3eaf2a7ec2394d1de3d8409bf4bd2e21"
integrity sha512-no/mE3l7B0mdUTtvO7z/cTLENttQ/M7+ombqFGXJqsQrxv9wrYsTIGpS3za+FA5a447hY+x9D8Wxny84q1zAaA==
[email protected].42:
version "2.21.42"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.21.42.tgz#c7d64b7ba3fa548d258384d0838eca7215fa9a8c"
integrity sha512-PWBb3iaVFAzLWUaNrYLweOGwHPTQid5J4HfERh/WjJgixbAFwb4ZEc1leRfygvgJPtqUGdYNapvw9b2k2FoCAg==
dependencies:
"@adraffy/ens-normalize" "1.11.0"
"@noble/curves" "1.6.0"
Expand All @@ -10981,13 +10981,13 @@ viem@^2.1.1:
isows "1.0.4"
ws "8.17.1"

[email protected].25:
version "2.12.25"
resolved "https://registry.yarnpkg.com/wagmi/-/wagmi-2.12.25.tgz#0e4f23a96e021143f202c250ec0af3a5ea0cca08"
integrity sha512-RdQCDbTv1+b7fWCAoLEYX0loymqLnhmNrMZq1gfPEs6cOhEHYOQeZtJWnyaXOD5+3xIFw+xoA0xDNvAHVbtbKw==
[email protected].27:
version "2.12.27"
resolved "https://registry.yarnpkg.com/wagmi/-/wagmi-2.12.27.tgz#f2647e3fe8b88f142b388777a5c84e32bd57fd7d"
integrity sha512-vyPZ6mAHTabQYuMwD/LPm5aQfihtHdSE1K99lMkR8vuYFE20xxtyOYoIkpa4XbA9p0WaGBH8VoB/PBCRIB1I3w==
dependencies:
"@wagmi/connectors" "5.3.3"
"@wagmi/core" "2.14.1"
"@wagmi/connectors" "5.3.5"
"@wagmi/core" "2.14.3"
use-sync-external-store "1.2.0"

walker@^1.0.8:
Expand Down

0 comments on commit d8b8e96

Please sign in to comment.