Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: future setup for support other l2 #533

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/rewards/components/IndexerLink.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, External as ExternalLinkIcon } from '@lidofinance/lido-ui';
import { getEtherscanTxLink } from 'utils/get-etherscan-tx-link';
import { getEtherscanTxLink } from 'utils/etherscan';

import { config } from 'config';

Expand Down
9 changes: 4 additions & 5 deletions features/stake/lido-stats/lido-stats.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { FC, memo, useMemo } from 'react';

import { getEtherscanTokenLink } from '@lido-sdk/helpers';
import { useSDK } from '@lido-sdk/react';
import { getTokenAddress, TOKENS } from '@lido-sdk/constants';
import { Block, DataTable, Question, Tooltip } from '@lidofinance/lido-ui';

import { Section, MatomoLink } from 'shared/components';
import { useLidoApr, useLidoStats } from 'shared/hooks';

import { config } from 'config';

import { LIDO_APR_TOOLTIP_TEXT, DATA_UNAVAILABLE } from 'consts/text';
import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events';
import { getEtherscanTokenLink } from 'utils/etherscan';

import { Section, MatomoLink } from 'shared/components';
import { useLidoApr, useLidoStats } from 'shared/hooks';

import { FlexCenterVertical } from './styles';
import { LidoStatsItem } from './lido-stats-item';
Expand Down
21 changes: 21 additions & 0 deletions features/wsteth/shared/wrap-faq/ethereum-faq/faq.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
WhatIsWsteth,
HowCanIGetWsteth,
HowCanIUseWsteth,
DoIGetMyStakingRewards,
DoINeedToClaimMyStakingRewards,
HowCouldIUnwrapWstethToSteth,
DoINeedToUnwrapMyWsteth,
} from './list';

export const EthereumFAQ = () => (
<>
<WhatIsWsteth />
<HowCanIGetWsteth />
<HowCanIUseWsteth />
<DoIGetMyStakingRewards />
<DoINeedToClaimMyStakingRewards />
<HowCouldIUnwrapWstethToSteth />
<DoINeedToUnwrapMyWsteth />
</>
);
23 changes: 23 additions & 0 deletions features/wsteth/shared/wrap-faq/optimism-faq/faq.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
WhatIsWstethOnOptimism,
HowCanIGetWstethOnOptimism,
HowCanIUseWstethOnOptimism,
CanIStakeMyETHDirectlyOnOptimism,
DoIStillGetStakingRewardsWithStETHOrWstETHOnOptimism,
DoINeedToClaimMyStakingRewardsIfIWrapStETHToWstETHOnOptimism,
HowCouldIUnwrapWstETHBackToStETHOnOptimism,
WhatHappensIfIWantToUnstakeETHOnEthereumCanIDoThatFromOptimism,
} from './list';

export const OptimismFAQ = () => (
<>
<WhatIsWstethOnOptimism />
<HowCanIGetWstethOnOptimism />
<HowCanIUseWstethOnOptimism />
<CanIStakeMyETHDirectlyOnOptimism />
<DoIStillGetStakingRewardsWithStETHOrWstETHOnOptimism />
<DoINeedToClaimMyStakingRewardsIfIWrapStETHToWstETHOnOptimism />
<HowCouldIUnwrapWstETHBackToStETHOnOptimism />
<WhatHappensIfIWantToUnstakeETHOnEthereumCanIDoThatFromOptimism />
</>
);
52 changes: 12 additions & 40 deletions features/wsteth/shared/wrap-faq/wrap-faq.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,28 @@
import React from 'react';
import { Section } from 'shared/components';
import { useMatomoEventHandle } from 'shared/hooks';
import { useDappStatus, DAPP_CHAIN_TYPE } from 'modules/web3';

import {
WhatIsWsteth,
HowCanIGetWsteth,
HowCanIUseWsteth,
DoIGetMyStakingRewards,
DoINeedToClaimMyStakingRewards,
HowCouldIUnwrapWstethToSteth,
DoINeedToUnwrapMyWsteth,
} from './list';
import { EthereumFAQ } from './ethereum-faq/faq';
import { OptimismFAQ } from './optimism-faq/faq';

import {
WhatIsWstethOnOptimism,
HowCanIGetWstethOnOptimism,
HowCanIUseWstethOnOptimism,
CanIStakeMyETHDirectlyOnOptimism,
DoIStillGetStakingRewardsWithStETHOrWstETHOnOptimism,
DoINeedToClaimMyStakingRewardsIfIWrapStETHToWstETHOnOptimism,
HowCouldIUnwrapWstETHBackToStETHOnOptimism,
WhatHappensIfIWantToUnstakeETHOnEthereumCanIDoThatFromOptimism,
} from './optimism-list';
export const faqComponentsMap = new Map([
[DAPP_CHAIN_TYPE.Ethereum, EthereumFAQ],
[DAPP_CHAIN_TYPE.Optimism, OptimismFAQ],
// FAQ for other networks
]);

export const WrapFaq = () => {
const { isWalletConnected, chainType } = useDappStatus();
const onClickHandler = useMatomoEventHandle();

if (isWalletConnected && chainType === DAPP_CHAIN_TYPE.Optimism) {
return (
<Section title="FAQ" onClick={onClickHandler}>
<WhatIsWstethOnOptimism />
<HowCanIGetWstethOnOptimism />
<HowCanIUseWstethOnOptimism />
<CanIStakeMyETHDirectlyOnOptimism />
<DoIStillGetStakingRewardsWithStETHOrWstETHOnOptimism />
<DoINeedToClaimMyStakingRewardsIfIWrapStETHToWstETHOnOptimism />
<HowCouldIUnwrapWstETHBackToStETHOnOptimism />
<WhatHappensIfIWantToUnstakeETHOnEthereumCanIDoThatFromOptimism />
</Section>
);
}
const FAQ = !isWalletConnected
? EthereumFAQ
: faqComponentsMap.get(chainType) || EthereumFAQ;

return (
<Section title="FAQ" onClick={onClickHandler}>
<WhatIsWsteth />
<HowCanIGetWsteth />
<HowCanIUseWsteth />
<DoIGetMyStakingRewards />
<DoINeedToClaimMyStakingRewards />
<HowCouldIUnwrapWstethToSteth />
<DoINeedToUnwrapMyWsteth />
<FAQ />
</Section>
);
};
8 changes: 4 additions & 4 deletions shared/components/tx-link-etherscan/tx-link-etherscan.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Link } from '@lidofinance/lido-ui';

import { CHAINS } from 'consts/chains';
import { getEtherscanTxLink } from 'utils/get-etherscan-tx-link';
import { config } from 'config';
import { getEtherscanTxLink } from 'utils/etherscan';
import { useDappStatus } from 'modules/web3';

type TxLinkEtherscanProps = {
Expand All @@ -12,14 +12,14 @@ type TxLinkEtherscanProps = {

export const TxLinkEtherscan = (props: TxLinkEtherscanProps) => {
const { txHash, text = 'View on Etherscan', onClick } = props;
const { chainId } = useDappStatus();
const { walletChainId } = useDappStatus();
Jeday marked this conversation as resolved.
Show resolved Hide resolved

if (!txHash) return null;

return (
<Link
onClick={onClick}
href={getEtherscanTxLink(chainId as CHAINS, txHash)}
href={getEtherscanTxLink(walletChainId ?? config.defaultChain, txHash)}
>
{text}
</Link>
Expand Down
12 changes: 8 additions & 4 deletions shared/wallet/wallet-modal/wallet-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import {
import { openWindow } from '@lido-sdk/helpers';
import { useConnectorInfo, useDisconnect } from 'reef-knot/core-react';

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

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

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

const handleCopy = useCopyToClipboard(address ?? '');
const handleEtherscan = useCallback(() => {
const link = getEtherscanAddressLink(chainId, address ?? '', chainId);
const link = getEtherscanAddressLink(
walletChainId ?? config.defaultChain,
address ?? '',
);
openWindow(link);
}, [address, chainId]);
}, [address, walletChainId]);

useEffect(() => {
// Close the modal if a wallet was somehow disconnected while the modal was open
Expand Down
36 changes: 36 additions & 0 deletions utils/etherscan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import invariant from 'tiny-invariant';
import { wagmiChainMap } from 'modules/web3/web3-provider/web3-provider';

export enum ETHERSCAN_ENTITIES {
TX = 'tx',
TOKEN = 'token',
ADDRESS = 'address',
}

export const getEtherscanLink = (
chainId: number,
hash: string,
entity: ETHERSCAN_ENTITIES,
): string => {
const wagmiChain = wagmiChainMap[chainId];
invariant(wagmiChain, `chainId ${chainId} is unknown by wagmiChainMap`);
return `${wagmiChain?.blockExplorers?.default?.url}/${entity}/${hash}`;
};

export const getEtherscanTxLink = (chainId: number, hash: string): string => {
return getEtherscanLink(chainId, hash, ETHERSCAN_ENTITIES.TX);
};

export const getEtherscanTokenLink = (
chainId: number,
hash: string,
): string => {
return getEtherscanLink(chainId, hash, ETHERSCAN_ENTITIES.TOKEN);
};

export const getEtherscanAddressLink = (
chainId: number,
hash: string,
): string => {
return getEtherscanLink(chainId, hash, ETHERSCAN_ENTITIES.ADDRESS);
};
26 changes: 0 additions & 26 deletions utils/get-etherscan-address-link.ts

This file was deleted.

18 changes: 0 additions & 18 deletions utils/get-etherscan-tx-link.ts

This file was deleted.

Loading