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

[WIP] Switch chain button #396

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
26a32c8
feat: l2 fallback banner
solidovic Jun 24, 2024
033503e
feat: unsupported chain button
solidovic Jun 24, 2024
cfa76fa
chore: reef-knot v5
solidovic Jul 1, 2024
5dc988b
feat: add 'useChainIdWithoutAccount' hook
solidovic Jul 1, 2024
f806537
feat: use 'useChainIdWithoutAccount' for get chain id
solidovic Jul 1, 2024
bc4bed0
feat: show account (if connected) for known l2 chains
solidovic Jul 1, 2024
ce37db2
feat: switchChain
solidovic Jul 3, 2024
bf18061
Merge remote-tracking branch 'origin/feature/si-965-update-wagmi-to-l…
solidovic Jul 3, 2024
c9879b4
chore: add @wagmi/core
solidovic Jul 3, 2024
d24d3c9
feat: l2-wallet to wrap/unwrap and wq pages
solidovic Jul 3, 2024
9abf9f6
fix: use chainId for SDK only from supportedChainIds
solidovic Jul 3, 2024
c97c2e5
feat: show account for unsupported chains
solidovic Jul 3, 2024
55e7a67
refactor(rewards top-card): wallet block, unsupported chain block, co…
solidovic Jul 4, 2024
c52e5e3
feat(rewards top-card): connect handler
solidovic Jul 4, 2024
c6bbc01
feat: additional checks
solidovic Jul 4, 2024
2c24e5e
feat(rewards): add addressError to AddressInput
solidovic Jul 4, 2024
c01691d
Merge branch 'develop' into feature/si-1310-unsupported-chain-banner-…
solidovic Jul 4, 2024
4ac6574
feat(l2 chains): only Arbitrum_One
solidovic Jul 4, 2024
b8a085d
fix: l2 logos
solidovic Jul 4, 2024
70434c3
fix(@playwright): tests
solidovic Jul 4, 2024
0616cee
fix(forms): show 'connect button' in forms
solidovic Jul 4, 2024
c44aa92
fix(connect button): fullwidth
solidovic Jul 4, 2024
6b38c51
feat(fallback): remove 'switch to mainnet' button
solidovic Jul 5, 2024
9b53b69
fix(rewards connect): colors
solidovic Jul 5, 2024
10b6636
feat: disabled forms for unsupported chains
solidovic Jul 5, 2024
30f180b
fix: types
solidovic Jul 5, 2024
1572c30
feat: add useIsSupportedChain and useIsConnectedWalletAndSupportedChain
solidovic Jul 9, 2024
f059523
refactor: l2 wallet fallback
solidovic Jul 9, 2024
4a16c6f
refactor: remove chainIdWithoutAccount and useWeb3
solidovic Jul 9, 2024
09abca5
refactor(stake form): disabled MAX button
solidovic Jul 9, 2024
ea342e4
refactor: remove Arbitrum_Nova and Arbitrum_One
solidovic Jul 9, 2024
3da3726
refactor(reward top-card): simplify to read of source code and not us…
solidovic Jul 9, 2024
3c19e24
refactor(stake-submit-button): not use web3-react
solidovic Jul 9, 2024
033fe2b
refactor(header-wallet): not use web3-react
solidovic Jul 9, 2024
e3ab1b1
refactor(header-wallet): not use web3-react
solidovic Jul 9, 2024
16b6d40
refactor: not use web3-react
solidovic Jul 9, 2024
20d1905
refactor(wallet fallback): not use web3-react
solidovic Jul 9, 2024
bccbc4d
fix(header-wallet): chainName
solidovic Jul 9, 2024
ce8b82b
refactor: remove useChainIdWithoutAccount
solidovic Jul 9, 2024
7410fad
Merge branch 'develop' into feature/si-1310-unsupported-chain-banner-…
solidovic Jul 9, 2024
c0809c5
fix: useErrorMessage
solidovic Jul 9, 2024
9539a05
revert: useErrorMessage
solidovic Jul 10, 2024
2f94a7a
refactor(rewards): styles
solidovic Jul 10, 2024
9b5104e
fix: polygon name
solidovic Jul 10, 2024
74f9bb4
fix(header wallet): address badge padding
solidovic Jul 11, 2024
cd572da
feat: add switchChain button
solidovic Jul 11, 2024
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
14 changes: 14 additions & 0 deletions assets/icons/l2/arbitrum.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions assets/icons/l2/base.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions assets/icons/l2/linea.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions assets/icons/l2/mantle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/icons/l2/optimism.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assets/icons/l2/polygon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/icons/l2/zk-sync.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion consts/chains.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
export const enum CHAINS {
export enum CHAINS {
Mainnet = 1,
Goerli = 5,
Holesky = 17000,
}

export enum L2_CHAINS {
zkSync = 324,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverse keys and values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what?

Optimism = 10,
Arbitrum = 42161,
Polygon = 137,
Base = 8453,
Mantle = 5000,
Linea = 59144,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import styled from 'styled-components';
import { Block } from '@lidofinance/lido-ui';

export const InputWrapperStyle = styled(Block)`
background: transparent;
padding-bottom: 24px;
`;
57 changes: 57 additions & 0 deletions features/rewards/features/top-card/connect-wallet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { FC, useCallback } from 'react';
import styled, { css } from 'styled-components';
import { useConnect } from 'reef-knot/core-react';
import { Button } from '@lidofinance/lido-ui';
import { wrapWithEventTrack } from '@lidofinance/analytics-matomo';

import { useUserConfig } from 'config/user-config';
import { MATOMO_CLICK_EVENTS } from 'consts/matomo-click-events';
import { WalletCardStyle } from 'shared/wallet/card/styles';

const ConnectWalletStyle = styled(WalletCardStyle)`
padding: 27px 27px 47px 27px;
text-align: center;

${({ theme }) =>
theme.name === 'dark'
? css`
color: var(--lido-color-text);
background: linear-gradient(48.34deg, #46464f -5.55%, #3b3b47 100%);
`
: css`
color: var(--lido-color-secondary);
background: linear-gradient(48.34deg, #d2ddff -5.55%, #e6e6e6 100%);
`}
`;

const TextStyle = styled.p`
margin-bottom: 12px;
`;

export const ConnectWallet: FC = () => {
const { isWalletConnectionAllowed } = useUserConfig();
const { connect } = useConnect();

const handleClick = wrapWithEventTrack(
MATOMO_CLICK_EVENTS.connectWallet,
useCallback(() => {
if (!isWalletConnectionAllowed) return;
void connect();
}, [isWalletConnectionAllowed, connect]),
);

return (
<ConnectWalletStyle>
<TextStyle>Connect your wallet to view staking stats</TextStyle>
<Button
color={'secondary'}
variant={'outlined'}
size={'sm'}
disabled={!isWalletConnectionAllowed}
onClick={handleClick}
>
Connect wallet
</Button>
</ConnectWalletStyle>
);
};
43 changes: 15 additions & 28 deletions features/rewards/features/top-card/top-card.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,28 @@
import { FC } from 'react';
import { Block, ThemeProvider, themeDark } from '@lidofinance/lido-ui';
import { InputDescription } from 'features/rewards/components/inputDescription';
import { AddressInput } from 'features/rewards/components/addressInput';
import { useAccount } from 'wagmi';

import { StatsWrapper } from 'features/rewards/components/statsWrapper';
import { Stats } from 'features/rewards/components/stats';
import { InputWrapper } from 'features/rewards/components/inputWrapper';
import { useRewardsHistory } from 'features/rewards/hooks';
import { Fallback } from 'shared/wallet';
import { useIsConnectedWalletAndSupportedChain } from 'shared/hooks/use-is-connected-wallet-and-supported-chain';

const INPUT_DESC_TEXT =
'Current balance may differ from last balance in the table due to rounding.';
import { Wallet } from './wallet';
import { ConnectWallet } from './connect-wallet';

export const TopCard: FC = () => {
const {
address,
addressError,
isAddressResolving,
inputValue,
setInputValue,
} = useRewardsHistory();
const { isConnected } = useAccount();
const isActiveWallet = useIsConnectedWalletAndSupportedChain();

return (
<Block color="accent" style={{ padding: 0 }}>
<InputWrapper data-testid="inputSection" color="accent">
<ThemeProvider theme={themeDark}>
<AddressInput
address={address}
addressError={addressError}
inputValue={inputValue}
handleInputChange={setInputValue}
isAddressResolving={isAddressResolving}
/>
<InputDescription>{INPUT_DESC_TEXT}</InputDescription>
</ThemeProvider>
</InputWrapper>
<>
{!isConnected && <ConnectWallet />}

{isConnected && !isActiveWallet && <Fallback />}

{isConnected && isActiveWallet && <Wallet />}
<StatsWrapper>
<Stats />
</StatsWrapper>
</Block>
</>
);
};
50 changes: 50 additions & 0 deletions features/rewards/features/top-card/wallet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { FC } from 'react';
import styled from 'styled-components';
import { ThemeProvider, themeDark } from '@lidofinance/lido-ui';

import { InputDescription } from 'features/rewards/components/inputDescription';
import { AddressInput } from 'features/rewards/components/addressInput';
import { InputWrapper } from 'features/rewards/components/inputWrapper';
import { useRewardsHistory } from 'features/rewards/hooks';

import { WalletCardStyle } from 'shared/wallet/card/styles';

const INPUT_DESC_TEXT =
'Current balance may differ from last balance in the table due to rounding.';

const WalletStyle = styled(WalletCardStyle)`
background: linear-gradient(
52.01deg,
#37394a 0%,
#363749 0.01%,
#40504f 100%
);
padding: 0 0 24px 0;
`;

export const Wallet: FC = () => {
const {
address,
addressError,
isAddressResolving,
inputValue,
setInputValue,
} = useRewardsHistory();

return (
<WalletStyle>
<InputWrapper data-testid="inputSection" color="accent">
<ThemeProvider theme={themeDark}>
<AddressInput
address={address}
addressError={addressError}
inputValue={inputValue}
handleInputChange={setInputValue}
isAddressResolving={isAddressResolving}
/>
<InputDescription>{INPUT_DESC_TEXT}</InputDescription>
</ThemeProvider>
</InputWrapper>
</WalletStyle>
);
};
4 changes: 4 additions & 0 deletions features/stake/stake-form/controls/stake-amount-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { Eth } from '@lidofinance/lido-ui';
import { TokenAmountInputHookForm } from 'shared/hook-form/controls/token-amount-input-hook-form';
import { useStakeFormData } from '../stake-form-context';
import { useStakingLimitWarning } from 'shared/hooks/use-staking-limit-warning';
import { useIsConnectedWalletAndSupportedChain } from 'shared/hooks/use-is-connected-wallet-and-supported-chain';

export const StakeAmountInput = () => {
const isActiveWallet = useIsConnectedWalletAndSupportedChain();
const { maxAmount, stakingLimitInfo } = useStakeFormData();
const { limitWarning, limitError } = useStakingLimitWarning(
stakingLimitInfo?.stakeLimitLevel,
);

return (
<TokenAmountInputHookForm
disabled={!isActiveWallet}
fieldName="amount"
token={'ETH'}
data-testid="stakeInput"
Expand Down
11 changes: 9 additions & 2 deletions features/stake/stake-form/controls/stake-submit-button.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { LIMIT_LEVEL } from 'types';
import { SubmitButtonHookForm } from 'shared/hook-form/controls/submit-button-hook-form';
import { useIsConnectedWalletAndSupportedChain } from 'shared/hooks/use-is-connected-wallet-and-supported-chain';

import { useStakeFormData } from '../stake-form-context';
import { LIMIT_LEVEL } from 'types';

export const StakeSubmitButton = () => {
const isActiveWallet = useIsConnectedWalletAndSupportedChain();
const { stakingLimitInfo } = useStakeFormData();

return (
<SubmitButtonHookForm
disabled={stakingLimitInfo?.stakeLimitLevel === LIMIT_LEVEL.REACHED}
disabled={
!isActiveWallet ||
stakingLimitInfo?.stakeLimitLevel === LIMIT_LEVEL.REACHED
}
data-testid="stakeSubmitBtn"
errorField="amount"
>
Expand Down
Loading
Loading