Skip to content

Commit

Permalink
Merge pull request #540 from lidofinance/fix/chain-id-in-scan-links
Browse files Browse the repository at this point in the history
fix: chain id in scan links
  • Loading branch information
itaven authored Nov 11, 2024
2 parents 4f02cb2 + ca1d9ee commit 03b5812
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
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

0 comments on commit 03b5812

Please sign in to comment.