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: add the 'chain id toggler' instead of the 'chain type toggler' #571

Open
wants to merge 38 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8518b14
feat: add the 'chain id toggler' instead of the 'chain type toggler'
solidovic Dec 24, 2024
7bd5d75
feat: remove explicit call the setChainIdInternal
solidovic Jan 9, 2025
17085ec
fix: a flushing when changing the chain id
solidovic Jan 10, 2025
390e46c
feat: use the mutation of useSwitchChain
solidovic Jan 13, 2025
9cda0f1
feat: remove a style fix
solidovic Jan 13, 2025
6be5b82
feat: add abstract logic for SupportL1Chains and SupportL2Chains prov…
solidovic Jan 13, 2025
20546bf
feat(ChainSwitcher): init a iconsMap by useDappStatus().supportedChai…
solidovic Jan 13, 2025
a97965f
feat(useAppChainManager): add useMemo
solidovic Jan 13, 2025
646779e
feat(useAppChainManager): add router.events to fix a flushing
solidovic Jan 18, 2025
885b47c
feat(wallet card error): fix a flushing
solidovic Jan 19, 2025
f80623e
refactor: simplify and comments
solidovic Jan 19, 2025
ad510e8
refactor: naming
solidovic Jan 19, 2025
42b605d
Merge branch 'develop' into feature/si-1638-NEW_chain-toggle-changes-…
solidovic Jan 19, 2025
6369274
revert: remove router.events
solidovic Jan 20, 2025
51d3e13
feat: add 'Switch to <chain>' button to fallback banner
solidovic Jan 20, 2025
109beb3
Merge remote-tracking branch 'origin/feature/si-1638-NEW_chain-toggle…
solidovic Jan 20, 2025
158e087
fix: fix LH and LL checks
solidovic Jan 21, 2025
a85b15c
refactor(add): add comments, use isPending from the useSwitchChain, r…
solidovic Jan 21, 2025
129a83c
fix: isTestnet property
solidovic Jan 21, 2025
c719c77
refactor(wallet): not use Optimism hardcode
solidovic Jan 21, 2025
7ef2e15
feat: add typing to the DappChainContext
solidovic Jan 21, 2025
4e759e1
fix(wallet): not use Optimism hardcode
solidovic Jan 21, 2025
f2ad005
feat(header): not use Optimism hardcode
solidovic Jan 21, 2025
34b1873
feat(icons): not use Optimism hardcode
solidovic Jan 21, 2025
0213838
fix(chain switcher): width for OP Mainnet
solidovic Jan 21, 2025
b82b755
refactor(useAppChainManager): remove the dappChainId state
solidovic Jan 21, 2025
93f17c6
fix: banners, naming, remove not actual comments
solidovic Jan 21, 2025
e70b11b
refactor: move 'reset internal wagmi state' to the useAppChainManager…
solidovic Jan 22, 2025
0094181
revert: removed isSwitchChainPending
solidovic Jan 22, 2025
957e4f6
fix: isSupportedChain
solidovic Jan 22, 2025
6efe73d
feat(switchChainId): catch and show error
solidovic Jan 22, 2025
dad1c5c
Merge branch 'develop' into feature/si-1638-NEW_chain-toggle-changes-…
solidovic Jan 22, 2025
702e516
refactor: use a console.warn instead of ToastError
solidovic Jan 23, 2025
4d16064
refactor: pass wagmiChain and wagmiDefaultChain
solidovic Jan 23, 2025
2bc3453
Merge branch 'develop' into feature/si-1638-NEW_chain-toggle-changes-…
solidovic Jan 23, 2025
a0d3ee6
Merge branch 'develop' into feature/si-1638-NEW_chain-toggle-changes-…
solidovic Jan 30, 2025
cbddde5
chore: update packages
solidovic Jan 31, 2025
6eaa200
fix: fix the balance loader in the header
solidovic Jan 31, 2025
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
18 changes: 8 additions & 10 deletions features/wsteth/shared/wallet/wallet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { useConnectorInfo } from 'reef-knot/core-react';
import { Divider, Text } from '@lidofinance/lido-ui';

import { useConfig } from 'config';

import { FormatToken } from 'shared/formatters';
import { TokenToWallet } from 'shared/components';
import {
Expand All @@ -8,15 +11,12 @@ import {
useStethBalance,
useWstethBalance,
useWstethBySteth,
DAPP_CHAIN_TYPE,
useStETHByWstETH,
} from 'modules/web3';
import { useIsLedgerLive } from 'shared/hooks/useIsLedgerLive';
import { CardBalance, CardRow, CardAccount, Fallback } from 'shared/wallet';

import { StyledCard } from './styles';
import { useIsLedgerLive } from 'shared/hooks/useIsLedgerLive';
import { useConfig } from 'config';
import { useConnectorInfo } from 'reef-knot/core-react';

const WalletComponent = () => {
const { isDappActiveOnL2 } = useDappStatus();
Expand Down Expand Up @@ -110,14 +110,12 @@ export const Wallet = ({ isUnwrapMode }: WrapWalletProps) => {
const isLedgerLive = useIsLedgerLive();
const { isLedger: isLedgerHardware } = useConnectorInfo();
const { featureFlags } = useConfig().externalConfig;
const { chainType } = useDappStatus();
const { isChainIdOnL2 } = useDappStatus();

const isLedgerLiveOptimism =
!featureFlags.ledgerLiveL2 &&
isLedgerLive &&
chainType === DAPP_CHAIN_TYPE.Optimism;
const isLedgerHardwareOptimism =
isLedgerHardware && chainType === DAPP_CHAIN_TYPE.Optimism;
!featureFlags.ledgerLiveL2 && isLedgerLive && isChainIdOnL2;

const isLedgerHardwareOptimism = isLedgerHardware && isChainIdOnL2;

if (isLedgerLiveOptimism || isLedgerHardwareOptimism) {
const error = `Optimism is currently not supported in ${isLedgerLiveOptimism ? 'Ledger Live' : 'Ledger Hardware'}.`;
Expand Down
16 changes: 10 additions & 6 deletions features/wsteth/shared/wrap-faq/wrap-faq.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import React from 'react';

import { CHAINS } from 'consts/chains';
import { useDappStatus } from 'modules/web3';
import { Section } from 'shared/components';
import { useMatomoEventHandle } from 'shared/hooks';
import { useDappStatus, DAPP_CHAIN_TYPE } from 'modules/web3';

import { EthereumFAQ } from './ethereum-faq/faq';
import { OptimismFAQ } from './optimism-faq/faq';

export const faqComponentsMap = new Map([
[DAPP_CHAIN_TYPE.Ethereum, EthereumFAQ],
[DAPP_CHAIN_TYPE.Optimism, OptimismFAQ],
// FAQ for other networks
[CHAINS.Mainnet, EthereumFAQ],
Jeday marked this conversation as resolved.
Show resolved Hide resolved
[CHAINS.Sepolia, EthereumFAQ],
[CHAINS.Holesky, EthereumFAQ],
[CHAINS.Optimism, OptimismFAQ],
[CHAINS.OptimismSepolia, OptimismFAQ],
]);

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

const FAQ = !isWalletConnected
? EthereumFAQ
: faqComponentsMap.get(chainType) || EthereumFAQ;
: faqComponentsMap.get(chainId) || EthereumFAQ;

return (
<Section title="FAQ" onClick={onClickHandler}>
Expand Down
8 changes: 4 additions & 4 deletions features/wsteth/unwrap/hooks/use-unwrap-tx-on-l2-approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type UseUnwrapTxApproveArgs = {
};

export const useUnwrapTxOnL2Approve = ({ amount }: UseUnwrapTxApproveArgs) => {
const { isDappActiveOnL2, isChainTypeOnL2, address } = useDappStatus();
const { isDappActiveOnL2, isChainIdOnL2, address } = useDappStatus();
const { l2, core } = useLidoSDKL2();
const { txModalStages } = useTxModalWrap();

Expand Down Expand Up @@ -77,8 +77,8 @@ export const useUnwrapTxOnL2Approve = ({ amount }: UseUnwrapTxApproveArgs) => {
isAllowanceLoading,
// There are 2 cases when we show the allowance on the unwrap page:
// 1. wallet chain is any Optimism supported chain and chain switcher is Optimism (isDappActiveOnL2)
// 2. or wallet chain is any ETH supported chain, but chain switcher is Optimism (isChainTypeOnL2)
isShowAllowance: isDappActiveOnL2 || isChainTypeOnL2,
// 2. or wallet chain is any ETH supported chain, but chain switcher is Optimism (isChainIdOnL2)
isShowAllowance: isDappActiveOnL2 || isChainIdOnL2,
}),
[
processApproveTx,
Expand All @@ -87,7 +87,7 @@ export const useUnwrapTxOnL2Approve = ({ amount }: UseUnwrapTxApproveArgs) => {
isApprovalNeededBeforeUnwrap,
isAllowanceLoading,
isDappActiveOnL2,
isChainTypeOnL2,
isChainIdOnL2,
],
);
};
12 changes: 6 additions & 6 deletions features/wsteth/unwrap/unwrap-form/unwrap-stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ import { useUnwrapFormData, UnwrapFormInputType } from '../unwrap-form-context';
import { TOKENS_TO_WRAP } from '../../shared/types';

export const UnwrapStats = () => {
const { isDappActiveOnL2, chainTypeChainId } = useDappStatus();
const { isDappActiveOnL2, chainId } = useDappStatus();
const { allowance, isAllowanceLoading, isShowAllowance } =
useUnwrapFormData();
const amount = useWatch<UnwrapFormInputType, 'amount'>({ name: 'amount' });

const unwrapGasLimit = useUnwrapGasLimit();
// The 'unwrapGasLimit' difference between the networks is insignificant
// and can be neglected in the '!isChainTypeMatched' case
// and can be neglected in the '!isChainIdMatched' case
//
// Using the chainTypeChainId (chainId from the chain switcher) for TX calculation (and below for 'approveTxCostInUsd'),
// Using the chainId (chainId from the chain switcher) for TX calculation (and below for 'approveTxCostInUsd'),
// because the statistics here are shown for the chain from the chain switcher
const { txCostUsd: unwrapTxCostInUsd, isLoading: isUnwrapTxCostLoading } =
useTxCostInUsd(unwrapGasLimit, chainTypeChainId);
useTxCostInUsd(unwrapGasLimit, chainId);

const approveGasLimit = useApproveGasLimit();
// The 'approveGasLimit' difference between the networks is insignificant
// and can be neglected in the '!isChainTypeMatched' case
// and can be neglected in the '!isChainIdMatched' case
const { txCostUsd: approveTxCostInUsd, isLoading: isApproveCostLoading } =
useTxCostInUsd(approveGasLimit, chainTypeChainId);
useTxCostInUsd(approveGasLimit, chainId);

const { data: willReceiveStETH, isLoading: isWillReceiveStETHLoading } =
useDebouncedStethByWsteth(amount);
Expand Down
9 changes: 4 additions & 5 deletions features/wsteth/wrap/hooks/use-wrap-tx-on-l1-approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useWrapTxOnL1Approve = ({
amount,
token,
}: UseWrapTxApproveArgs) => {
const { address, isWalletConnected, isDappActiveOnL1, isChainTypeOnL2 } =
const { address, isWalletConnected, isDappActiveOnL1, isChainIdOnL2 } =
useDappStatus();
const { wrap } = useLidoSDK();
const { txModalStages } = useTxModalWrap();
Expand Down Expand Up @@ -90,9 +90,8 @@ export const useWrapTxOnL1Approve = ({
// There are 3 cases when we show the allowance on the wrap page:
// 1. is wallet not connected (!isWalletConnected)
// 2. or wallet chain is any ETH supported chain and chain switcher is ETH (isDappActiveOnL1)
// 3. or wallet chain is any Optimism supported chain, but chain switcher is ETH (!isChainTypeOnL2)
isShowAllowance:
!isWalletConnected || isDappActiveOnL1 || !isChainTypeOnL2,
// 3. or wallet chain is any Optimism supported chain, but chain switcher is ETH (!isChainIdOnL2)
isShowAllowance: !isWalletConnected || isDappActiveOnL1 || !isChainIdOnL2,
}),
[
processApproveTx,
Expand All @@ -103,7 +102,7 @@ export const useWrapTxOnL1Approve = ({
refetchAllowance,
isWalletConnected,
isDappActiveOnL1,
isChainTypeOnL2,
isChainIdOnL2,
],
);
};
12 changes: 6 additions & 6 deletions features/wsteth/wrap/wrap-form/wrap-stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useApproveGasLimit } from '../hooks/use-approve-gas-limit';
import { useWrapFormData, WrapFormInputType } from '../wrap-form-context';

export const WrapFormStats = () => {
const { isDappActive, chainTypeChainId } = useDappStatus();
const { isDappActive, chainId } = useDappStatus();
const { allowance, isShowAllowance, wrapGasLimit, isAllowanceLoading } =
useWrapFormData();

Expand All @@ -32,18 +32,18 @@ export const WrapFormStats = () => {
useWstethBySteth(ONE_stETH);

// The 'approveGasLimit' difference between the networks is insignificant
// and can be neglected in the '!isChainTypeMatched' case
// and can be neglected in the '!isChainIdMatched' case
//
// Using the chainTypeChainId (chainId from the chain switcher) for TX calculation (and below for 'wrapTxCostInUsd'),
// Using the chainId (chainId from the chain switcher) for TX calculation (and below for 'wrapTxCostInUsd'),
// because the statistics here are shown for the chain from the chain switcher
const approveGasLimit = useApproveGasLimit();
const { txCostUsd: approveTxCostInUsd, isLoading: isApproveCostLoading } =
useTxCostInUsd(approveGasLimit, chainTypeChainId);
useTxCostInUsd(approveGasLimit, chainId);

// The 'wrapGasLimit' difference between the networks is insignificant
// and can be neglected in the '!isChainTypeMatched' case
// and can be neglected in the '!isChainIdMatched' case
const { txCostUsd: wrapTxCostInUsd, isLoading: isWrapCostLoading } =
useTxCostInUsd(wrapGasLimit, chainTypeChainId);
useTxCostInUsd(wrapGasLimit, chainId);

return (
<DataTable data-testid="wrapStats">
Expand Down
43 changes: 43 additions & 0 deletions modules/web3/consts/chains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ReactComponent as OptimismLogo } from 'assets/icons/chain-toggler/optimism.svg';
import { ReactComponent as EthereumMainnetLogo } from 'assets/icons/chain-toggler/mainnet.svg';

import { CHAINS } from 'consts/chains';

export enum DAPP_CHAIN_TYPE {
Ethereum = 'Ethereum',
Optimism = 'Optimism',
}

export type SupportedChainLabels = {
[key in DAPP_CHAIN_TYPE]: string;
};

export const ETHEREUM_CHAINS = new Set([
CHAINS.Mainnet,
CHAINS.Holesky,
CHAINS.Sepolia,
]);

export const OPTIMISM_CHAINS = new Set([
CHAINS.Optimism,
CHAINS.OptimismSepolia,
]);

export const getChainTypeByChainId = (
chainId: number,
): DAPP_CHAIN_TYPE | null => {
Jeday marked this conversation as resolved.
Show resolved Hide resolved
if (ETHEREUM_CHAINS.has(chainId)) {
return DAPP_CHAIN_TYPE.Ethereum;
} else if (OPTIMISM_CHAINS.has(chainId)) {
return DAPP_CHAIN_TYPE.Optimism;
}
return null;
};

export const CHAIN_ICONS_MAP = new Map([
[CHAINS.Mainnet, EthereumMainnetLogo],
[CHAINS.Holesky, EthereumMainnetLogo],
[CHAINS.Sepolia, EthereumMainnetLogo],
[CHAINS.Optimism, OptimismLogo],
[CHAINS.OptimismSepolia, OptimismLogo],
]);
1 change: 1 addition & 0 deletions modules/web3/consts/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './chains';
export * from './symbols';
export * from './tx';
export * from './units';
6 changes: 4 additions & 2 deletions modules/web3/hooks/use-dapp-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ export const useDappStatus = () => {
// this can change between pages based on their dapp-chain context(or lack of)
const dappChain = useDappChain();

const { isSupportedChain, isChainTypeMatched } = dappChain;
const { isSupportedChain, isChainIdMatched, isSwitchChainWait } = dappChain;

const isAccountActive = walletChainId
? isWalletConnected && isSupportedChain
: false;

const isL2 = isSDKSupportedL2Chain(walletChainId);

const isDappActive = isAccountActive && isChainTypeMatched;
const isDappActive =
isAccountActive && isChainIdMatched && !isSwitchChainWait;

const isDappActiveOnL1 = isDappActive && !isL2;

Expand All @@ -36,6 +37,7 @@ export const useDappStatus = () => {
isDappActiveOnL2,
isDappActiveOnL1,
isWalletConnected,
isSwitchChainWait,
walletChainId,
address,
};
Expand Down
1 change: 0 additions & 1 deletion modules/web3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export {
useLidoSDK,
useLidoSDKL2,
SupportL2Chains,
DAPP_CHAIN_TYPE,
} from './web3-provider';
Loading
Loading