From 4f92fe4ca0a6f4aea6af49bfad78178618ffee46 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 21 Aug 2024 13:26:33 +0300 Subject: [PATCH 01/16] feat: return data-testid for reward-address-input wrapper --- features/rewards/features/top-card/wallet.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/rewards/features/top-card/wallet.tsx b/features/rewards/features/top-card/wallet.tsx index f81924e74..7a429f731 100644 --- a/features/rewards/features/top-card/wallet.tsx +++ b/features/rewards/features/top-card/wallet.tsx @@ -17,7 +17,7 @@ export const Wallet: FC = () => { } = useRewardsHistory(); return ( - + Date: Wed, 21 Aug 2024 13:35:27 +0300 Subject: [PATCH 02/16] feat(rewards page): unsupported banner --- features/rewards/features/top-card/top-card.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/features/rewards/features/top-card/top-card.tsx b/features/rewards/features/top-card/top-card.tsx index 9ae2f7ef9..2e44058a5 100644 --- a/features/rewards/features/top-card/top-card.tsx +++ b/features/rewards/features/top-card/top-card.tsx @@ -2,11 +2,14 @@ import { FC, useEffect, useState } from 'react'; import { StatsWrapper } from 'features/rewards/components/statsWrapper'; import { Stats } from 'features/rewards/components/stats'; +import { useDappStatus } from 'shared/hooks/use-dapp-status'; +import { Fallback } from 'shared/wallet'; import { Wallet } from './wallet'; export const TopCard: FC = () => { const [visible, setVisible] = useState(false); + const { isWalletConnected, isSupportedChain } = useDappStatus(); // fix flash after reload page useEffect(() => { @@ -17,7 +20,8 @@ export const TopCard: FC = () => { return ( <> - + {isWalletConnected && !isSupportedChain ? : } + From 0cc9ebe77659b1a3b75802e87a3f3b95a8370a19 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 21 Aug 2024 14:19:33 +0300 Subject: [PATCH 03/16] fix: test attrs --- features/rewards/components/stats/steth-rewarded-block.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/rewards/components/stats/steth-rewarded-block.tsx b/features/rewards/components/stats/steth-rewarded-block.tsx index 583c34e57..5b05e52bc 100644 --- a/features/rewards/components/stats/steth-rewarded-block.tsx +++ b/features/rewards/components/stats/steth-rewarded-block.tsx @@ -31,7 +31,7 @@ export const StEthRewardedBlock: FC = () => { ) } - valueDataTestId="stEthRewardedIn$" + valueDataTestId="stEthRewarded" underValue={ !data?.totals.currencyRewards ? ( '—' @@ -44,7 +44,7 @@ export const StEthRewardedBlock: FC = () => { ) } - underValueDataTestId="stEthBalanceIn$" + underValueDataTestId="stEthRewardedIn$" /> ); }; From ded1375b9b62cee3e11bdf08ec48f2cb84f7cff4 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 21 Aug 2024 14:26:19 +0300 Subject: [PATCH 04/16] feat(reward table): show unsupported text --- .../rewardsListContent/RewardsListContent.tsx | 8 +++++ .../RewardsListsUnsupportedChain.tsx | 31 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx diff --git a/features/rewards/components/rewardsListContent/RewardsListContent.tsx b/features/rewards/components/rewardsListContent/RewardsListContent.tsx index a47f1a6a7..a00908765 100644 --- a/features/rewards/components/rewardsListContent/RewardsListContent.tsx +++ b/features/rewards/components/rewardsListContent/RewardsListContent.tsx @@ -7,9 +7,11 @@ import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { useRewardsHistory } from 'features/rewards/hooks'; import { ErrorBlockNoSteth } from 'features/rewards/components/errorBlocks/ErrorBlockNoSteth'; import { RewardsTable } from 'features/rewards/components/rewardsTable'; +import { useDappStatus } from 'shared/hooks/use-dapp-status'; import { RewardsListsEmpty } from './RewardsListsEmpty'; import { RewardsListErrorMessage } from './RewardsListErrorMessage'; +import { RewardsListsUnsupportedChain } from './RewardsListsUnsupportedChain'; import { LoaderWrapper, TableWrapperStyle, @@ -17,6 +19,7 @@ import { } from './RewardsListContentStyles'; export const RewardsListContent: FC = () => { + const { isWalletConnected, isSupportedChain } = useDappStatus(); const { error, initialLoading, @@ -30,7 +33,11 @@ export const RewardsListContent: FC = () => { useSTETHBalance(STRATEGY_LAZY); const hasSteth = stethBalance?.gt(Zero); + if (isWalletConnected && !isSupportedChain) + return ; + if (!data && !initialLoading && !error) return ; + // showing loading when canceling requests and empty response if ( (!data && !error) || @@ -46,6 +53,7 @@ export const RewardsListContent: FC = () => { ); } + if (error) { return ( diff --git a/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx b/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx new file mode 100644 index 000000000..aba894c54 --- /dev/null +++ b/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx @@ -0,0 +1,31 @@ +import { FC, useMemo } from 'react'; +import { Divider } from '@lidofinance/lido-ui'; + +import { useConfig } from 'config'; +import { CHAINS } from 'consts/chains'; +import { RewardsListEmptyWrapper } from './RewardsListsEmptyStyles'; + +export const RewardsListsUnsupportedChain: FC = () => { + const { + config: { supportedChains }, + } = useConfig(); + + const supportedChainsNames = useMemo(() => { + // 'Chain ID' array to 'Chain name' array exclude unknown chain id + const chains = supportedChains.map((id) => CHAINS[id]).filter(Boolean); + const lastChain = chains.pop(); + return [chains.join(', '), lastChain].filter((chain) => chain).join(' or '); + }, [supportedChains]); + + return ( + <> + + +

+ Please switch to {supportedChainsNames} in your wallet and restart the + page. +

+
+ + ); +}; From 89754f6f19b54f64e55543788f680bf3aa69bac6 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 21 Aug 2024 16:12:20 +0300 Subject: [PATCH 05/16] feat: remove loading from input --- features/rewards/components/address-input/address-input.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/features/rewards/components/address-input/address-input.tsx b/features/rewards/components/address-input/address-input.tsx index a50daf068..7c222de2a 100644 --- a/features/rewards/components/address-input/address-input.tsx +++ b/features/rewards/components/address-input/address-input.tsx @@ -13,7 +13,6 @@ export const AddressInput: FC = (props) => { handleInputChange, address, addressError: invalidENSAddress, - loading, } = props; const invalidEthereumAddress = useMemo( @@ -28,7 +27,7 @@ export const AddressInput: FC = (props) => { onChange={(e) => handleInputChange(e.target.value)} placeholder="Ethereum address" leftDecorator={ - loading || isAddressResolving ? ( + isAddressResolving ? ( ) : invalidEthereumAddress || invalidENSAddress ? ( From f1e5c61ee6d283ae36b60c349c9d53075f6477cc Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 21 Aug 2024 16:12:39 +0300 Subject: [PATCH 06/16] refactor: text --- .../rewardsListContent/RewardsListsUnsupportedChain.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx b/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx index aba894c54..288ef21fa 100644 --- a/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx +++ b/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx @@ -21,10 +21,7 @@ export const RewardsListsUnsupportedChain: FC = () => { <> -

- Please switch to {supportedChainsNames} in your wallet and restart the - page. -

+

Please switch to {supportedChainsNames} in your wallet.

); From 9eb75cc725faad4669e9116fad94e3734ab92472 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 21 Aug 2024 16:13:05 +0300 Subject: [PATCH 07/16] refactor: not show stats for unsupported chain --- .../rewards/components/stats/average-apr-block.tsx | 9 ++++++--- .../rewards/components/stats/steth-balance-block.tsx | 4 ++++ .../rewards/components/stats/steth-price-block.tsx | 10 +++++++--- .../rewards/components/stats/steth-rewarded-block.tsx | 5 ++++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/features/rewards/components/stats/average-apr-block.tsx b/features/rewards/components/stats/average-apr-block.tsx index 5b32ed11e..cea6183ae 100644 --- a/features/rewards/components/stats/average-apr-block.tsx +++ b/features/rewards/components/stats/average-apr-block.tsx @@ -3,11 +3,13 @@ import { Box, Question, Tooltip } from '@lidofinance/lido-ui'; import NumberFormat from 'features/rewards/components/NumberFormat'; import { useRewardsHistory } from 'features/rewards/hooks'; +import { useDappStatus } from 'shared/hooks/use-dapp-status'; import { Item } from './components/item'; import { FlexCenter } from './components/styles'; export const AverageAprBlock: FC = () => { + const { isWalletConnected, isSupportedChain } = useDappStatus(); const { data, initialLoading: loading } = useRewardsHistory(); return ( @@ -26,15 +28,16 @@ export const AverageAprBlock: FC = () => { } value={ <> - {parseFloat(data?.averageApr || '0') ? ( + {(isWalletConnected && !isSupportedChain) || + !parseFloat(data?.averageApr || '0') ? ( + '—' + ) : ( <> % - ) : ( - '—' )} } diff --git a/features/rewards/components/stats/steth-balance-block.tsx b/features/rewards/components/stats/steth-balance-block.tsx index fbff25179..18ccb19a6 100644 --- a/features/rewards/components/stats/steth-balance-block.tsx +++ b/features/rewards/components/stats/steth-balance-block.tsx @@ -4,10 +4,12 @@ import { Box } from '@lidofinance/lido-ui'; import NumberFormat from 'features/rewards/components/NumberFormat'; import { useRewardsHistory } from 'features/rewards/hooks'; import { useRewardsBalanceData } from 'features/rewards/hooks/use-rewards-balance-data'; +import { useDappStatus } from 'shared/hooks/use-dapp-status'; import { Item } from './components/item'; export const StEthBalanceBlock: FC = () => { + const { isWalletConnected, isSupportedChain } = useDappStatus(); const { data: balanceData } = useRewardsBalanceData(); const { currencyObject: currency, loading } = useRewardsHistory(); @@ -17,6 +19,7 @@ export const StEthBalanceBlock: FC = () => { dataTestId="stEthBalanceBlock" title="stETH balance" value={ + (isWalletConnected && !isSupportedChain) || !balanceData?.stEthBalanceParsed ? ( '—' ) : ( @@ -30,6 +33,7 @@ export const StEthBalanceBlock: FC = () => { } valueDataTestId="stEthBalance" underValue={ + (isWalletConnected && !isSupportedChain) || !balanceData?.stEthCurrencyBalance ? ( '—' ) : ( diff --git a/features/rewards/components/stats/steth-price-block.tsx b/features/rewards/components/stats/steth-price-block.tsx index 8a3e90a0e..4169009b2 100644 --- a/features/rewards/components/stats/steth-price-block.tsx +++ b/features/rewards/components/stats/steth-price-block.tsx @@ -4,10 +4,12 @@ import { Box } from '@lidofinance/lido-ui'; import NumberFormat from 'features/rewards/components/NumberFormat'; import { useRewardsHistory } from 'features/rewards/hooks'; import { useStethEthRate } from 'features/rewards/hooks/use-steth-eth-rate'; +import { useDappStatus } from 'shared/hooks/use-dapp-status'; import { Item } from './components/item'; export const StEthPriceBlock: FC = () => { + const { isWalletConnected, isSupportedChain } = useDappStatus(); const { currencyObject: currency, data, @@ -21,6 +23,7 @@ export const StEthPriceBlock: FC = () => { dataTestId="stEthPriceBlock" title="stETH price" value={ + (isWalletConnected && !isSupportedChain) || !data?.stETHCurrencyPrice[currency.id] ? ( '—' ) : ( @@ -35,15 +38,16 @@ export const StEthPriceBlock: FC = () => { valueDataTestId="stEthPrice" underValue={ <> - {data?.stETHCurrencyPrice[currency.id] ? ( + {(isWalletConnected && !isSupportedChain) || + !data?.stETHCurrencyPrice[currency.id] ? ( + '—' + ) : ( <> ETH - ) : ( - '—' )} } diff --git a/features/rewards/components/stats/steth-rewarded-block.tsx b/features/rewards/components/stats/steth-rewarded-block.tsx index 5b05e52bc..90dcae1d3 100644 --- a/features/rewards/components/stats/steth-rewarded-block.tsx +++ b/features/rewards/components/stats/steth-rewarded-block.tsx @@ -3,11 +3,13 @@ import { Box } from '@lidofinance/lido-ui'; import { useRewardsHistory } from 'features/rewards/hooks'; import NumberFormat from 'features/rewards/components/NumberFormat'; +import { useDappStatus } from 'shared/hooks/use-dapp-status'; import { Item } from './components/item'; import { GreenText } from './components/styles'; export const StEthRewardedBlock: FC = () => { + const { isWalletConnected, isSupportedChain } = useDappStatus(); const { currencyObject: currency, data, @@ -20,7 +22,7 @@ export const StEthRewardedBlock: FC = () => { dataTestId="stEthRewardedBlock" title="stETH rewarded" value={ - !data?.totals.ethRewards ? ( + (isWalletConnected && !isSupportedChain) || !data?.totals.ethRewards ? ( '—' ) : ( @@ -33,6 +35,7 @@ export const StEthRewardedBlock: FC = () => { } valueDataTestId="stEthRewarded" underValue={ + (isWalletConnected && !isSupportedChain) || !data?.totals.currencyRewards ? ( '—' ) : ( From 049a730451b4cf0b1efdda4c180ae818e582ec94 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 21 Aug 2024 16:18:09 +0300 Subject: [PATCH 08/16] chore: comments --- .../rewardsListContent/RewardsListsUnsupportedChain.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx b/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx index 288ef21fa..bc90790ad 100644 --- a/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx +++ b/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx @@ -14,6 +14,7 @@ export const RewardsListsUnsupportedChain: FC = () => { // 'Chain ID' array to 'Chain name' array exclude unknown chain id const chains = supportedChains.map((id) => CHAINS[id]).filter(Boolean); const lastChain = chains.pop(); + // to str return [chains.join(', '), lastChain].filter((chain) => chain).join(' or '); }, [supportedChains]); From b286fe166b0ce7d208f67038d29a05e12823a1bb Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 21 Aug 2024 21:45:33 +0300 Subject: [PATCH 09/16] fix(rewards): show filters, currency select and export button for not connected wallets --- .../components/rewardsListHeader/RewardsListHeader.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/features/rewards/components/rewardsListHeader/RewardsListHeader.tsx b/features/rewards/components/rewardsListHeader/RewardsListHeader.tsx index d156454c4..55641c846 100644 --- a/features/rewards/components/rewardsListHeader/RewardsListHeader.tsx +++ b/features/rewards/components/rewardsListHeader/RewardsListHeader.tsx @@ -1,6 +1,5 @@ import { FC } from 'react'; import { useRewardsHistory } from 'features/rewards/hooks'; -import { useDappStatus } from 'shared/hooks/use-dapp-status'; import { LeftOptions } from './LeftOptions'; import { RightOptions } from './RightOptions'; @@ -8,12 +7,12 @@ import { RewardsListHeaderStyle } from './styles'; import { TitleStyle } from './styles'; export const RewardsListHeader: FC = () => { - const { isDappActive } = useDappStatus(); const { error, data } = useRewardsHistory(); + return ( Reward history - {isDappActive && !error && data && data?.events.length > 0 && ( + {!error && data && data?.events.length > 0 && ( <> From f6262285b0d7cbd93ce1191fb165363f5e59f07c Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 21 Aug 2024 23:12:20 +0300 Subject: [PATCH 10/16] fix: condition to showing filters, currency select and export button --- .../rewardsListHeader/RewardsListHeader.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/features/rewards/components/rewardsListHeader/RewardsListHeader.tsx b/features/rewards/components/rewardsListHeader/RewardsListHeader.tsx index 55641c846..a1d4a1587 100644 --- a/features/rewards/components/rewardsListHeader/RewardsListHeader.tsx +++ b/features/rewards/components/rewardsListHeader/RewardsListHeader.tsx @@ -1,5 +1,6 @@ import { FC } from 'react'; import { useRewardsHistory } from 'features/rewards/hooks'; +import { useDappStatus } from 'shared/hooks/use-dapp-status'; import { LeftOptions } from './LeftOptions'; import { RightOptions } from './RightOptions'; @@ -7,17 +8,21 @@ import { RewardsListHeaderStyle } from './styles'; import { TitleStyle } from './styles'; export const RewardsListHeader: FC = () => { + const { isWalletConnected, isSupportedChain } = useDappStatus(); const { error, data } = useRewardsHistory(); return ( Reward history - {!error && data && data?.events.length > 0 && ( - <> - - - - )} + {!error && + data && + data?.events.length > 0 && + (!isWalletConnected || (isWalletConnected && isSupportedChain)) && ( + <> + + + + )} ); }; From 247de1ea65842963e9a03dfa5ffdef2ea433f0f5 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 21 Aug 2024 23:13:20 +0300 Subject: [PATCH 11/16] fix: text --- .../rewardsListContent/RewardsListsUnsupportedChain.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx b/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx index bc90790ad..9f5aaa755 100644 --- a/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx +++ b/features/rewards/components/rewardsListContent/RewardsListsUnsupportedChain.tsx @@ -22,7 +22,10 @@ export const RewardsListsUnsupportedChain: FC = () => { <> -

Please switch to {supportedChainsNames} in your wallet.

+

+ Please switch to {supportedChainsNames} in your wallet to see the + stats. +

); From f16e1447393fb301ade0aa697e5a8ee931e8258c Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 21 Aug 2024 23:20:14 +0300 Subject: [PATCH 12/16] fix: not show stats after disabled wallet (unsupported chain way) --- features/rewards/hooks/useGetCurrentAddress.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/features/rewards/hooks/useGetCurrentAddress.ts b/features/rewards/hooks/useGetCurrentAddress.ts index 3a0e672c1..ebb49bc6d 100644 --- a/features/rewards/hooks/useGetCurrentAddress.ts +++ b/features/rewards/hooks/useGetCurrentAddress.ts @@ -6,6 +6,7 @@ import { useSDK } from '@lido-sdk/react'; import { resolveEns, isValidEns, isValidAddress } from 'features/rewards/utils'; import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc-provider'; +import { useDappStatus } from 'shared/hooks/use-dapp-status'; import { overrideWithQAMockString } from 'utils/qa'; type UseGetCurrentAddress = () => { @@ -28,6 +29,7 @@ export const useGetCurrentAddress: UseGetCurrentAddress = () => { const { account } = useSDK(); const { staticRpcProvider } = useCurrentStaticRpcProvider(); const { isReady, query } = useRouter(); + const { isSupportedChain } = useDappStatus(); const getEnsAddress = useCallback( async (value: string) => { @@ -87,13 +89,13 @@ export const useGetCurrentAddress: UseGetCurrentAddress = () => { return; } // From a connected wallet - if (account) { + if (account && isSupportedChain) { setInputValue( overrideWithQAMockString(account, 'mock-qa-rewards-address'), ); } } - }, [account, query.address, isReady, setInputValue]); + }, [account, query.address, isReady, setInputValue, isSupportedChain]); return { address, From 7c0cbcd243f85139e77ecafa829036bea97644c0 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Thu, 22 Aug 2024 10:49:48 +0300 Subject: [PATCH 13/16] feat: remove the 'mock-qa-rewards-address' --- features/rewards/hooks/useGetCurrentAddress.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/features/rewards/hooks/useGetCurrentAddress.ts b/features/rewards/hooks/useGetCurrentAddress.ts index ebb49bc6d..00fe2257b 100644 --- a/features/rewards/hooks/useGetCurrentAddress.ts +++ b/features/rewards/hooks/useGetCurrentAddress.ts @@ -7,7 +7,6 @@ import { useSDK } from '@lido-sdk/react'; import { resolveEns, isValidEns, isValidAddress } from 'features/rewards/utils'; import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc-provider'; import { useDappStatus } from 'shared/hooks/use-dapp-status'; -import { overrideWithQAMockString } from 'utils/qa'; type UseGetCurrentAddress = () => { address: string; @@ -90,9 +89,7 @@ export const useGetCurrentAddress: UseGetCurrentAddress = () => { } // From a connected wallet if (account && isSupportedChain) { - setInputValue( - overrideWithQAMockString(account, 'mock-qa-rewards-address'), - ); + setInputValue(account); } } }, [account, query.address, isReady, setInputValue, isSupportedChain]); From 1689687c96efb5e1b2eea5083cf1d28ccac058e8 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Thu, 22 Aug 2024 12:59:26 +0300 Subject: [PATCH 14/16] refactor: add isDataAvailable flag to RewardsHistoryProvider --- .../components/stats/average-apr-block.tsx | 45 +++++++++---------- .../components/stats/steth-balance-block.tsx | 22 ++++----- .../components/stats/steth-price-block.tsx | 33 ++++++-------- .../components/stats/steth-rewarded-block.tsx | 16 +++---- providers/rewardsHistory.tsx | 12 ++++- 5 files changed, 64 insertions(+), 64 deletions(-) diff --git a/features/rewards/components/stats/average-apr-block.tsx b/features/rewards/components/stats/average-apr-block.tsx index cea6183ae..55b85b76d 100644 --- a/features/rewards/components/stats/average-apr-block.tsx +++ b/features/rewards/components/stats/average-apr-block.tsx @@ -3,43 +3,40 @@ import { Box, Question, Tooltip } from '@lidofinance/lido-ui'; import NumberFormat from 'features/rewards/components/NumberFormat'; import { useRewardsHistory } from 'features/rewards/hooks'; -import { useDappStatus } from 'shared/hooks/use-dapp-status'; import { Item } from './components/item'; import { FlexCenter } from './components/styles'; export const AverageAprBlock: FC = () => { - const { isWalletConnected, isSupportedChain } = useDappStatus(); - const { data, initialLoading: loading } = useRewardsHistory(); + const { + data, + isDataAvailable, + initialLoading: loading, + } = useRewardsHistory(); return ( - - Average APR - - - - - + + Average APR + + + + } value={ - <> - {(isWalletConnected && !isSupportedChain) || - !parseFloat(data?.averageApr || '0') ? ( - '—' - ) : ( - <> - - - % - - - )} - + parseFloat(data?.averageApr || '0') && isDataAvailable ? ( + <> + + + % + + + ) : ( + '—' + ) } valueDataTestId="averageApr" /> diff --git a/features/rewards/components/stats/steth-balance-block.tsx b/features/rewards/components/stats/steth-balance-block.tsx index 18ccb19a6..df7f76334 100644 --- a/features/rewards/components/stats/steth-balance-block.tsx +++ b/features/rewards/components/stats/steth-balance-block.tsx @@ -4,14 +4,16 @@ import { Box } from '@lidofinance/lido-ui'; import NumberFormat from 'features/rewards/components/NumberFormat'; import { useRewardsHistory } from 'features/rewards/hooks'; import { useRewardsBalanceData } from 'features/rewards/hooks/use-rewards-balance-data'; -import { useDappStatus } from 'shared/hooks/use-dapp-status'; import { Item } from './components/item'; export const StEthBalanceBlock: FC = () => { - const { isWalletConnected, isSupportedChain } = useDappStatus(); const { data: balanceData } = useRewardsBalanceData(); - const { currencyObject: currency, loading } = useRewardsHistory(); + const { + currencyObject: currency, + isDataAvailable, + loading, + } = useRewardsHistory(); return ( { dataTestId="stEthBalanceBlock" title="stETH balance" value={ - (isWalletConnected && !isSupportedChain) || - !balanceData?.stEthBalanceParsed ? ( - '—' - ) : ( + balanceData?.stEthBalanceParsed && isDataAvailable ? ( <> stETH + ) : ( + '—' ) } valueDataTestId="stEthBalance" underValue={ - (isWalletConnected && !isSupportedChain) || - !balanceData?.stEthCurrencyBalance ? ( - '—' - ) : ( + balanceData?.stEthCurrencyBalance && isDataAvailable ? ( <> {currency.symbol} + ) : ( + '—' ) } underValueDataTestId="stEthBalanceIn$" diff --git a/features/rewards/components/stats/steth-price-block.tsx b/features/rewards/components/stats/steth-price-block.tsx index 4169009b2..ee0a49e49 100644 --- a/features/rewards/components/stats/steth-price-block.tsx +++ b/features/rewards/components/stats/steth-price-block.tsx @@ -4,15 +4,14 @@ import { Box } from '@lidofinance/lido-ui'; import NumberFormat from 'features/rewards/components/NumberFormat'; import { useRewardsHistory } from 'features/rewards/hooks'; import { useStethEthRate } from 'features/rewards/hooks/use-steth-eth-rate'; -import { useDappStatus } from 'shared/hooks/use-dapp-status'; import { Item } from './components/item'; export const StEthPriceBlock: FC = () => { - const { isWalletConnected, isSupportedChain } = useDappStatus(); const { currencyObject: currency, data, + isDataAvailable, initialLoading: loading, } = useRewardsHistory(); const stEthEth = useStethEthRate(); @@ -23,33 +22,29 @@ export const StEthPriceBlock: FC = () => { dataTestId="stEthPriceBlock" title="stETH price" value={ - (isWalletConnected && !isSupportedChain) || - !data?.stETHCurrencyPrice[currency.id] ? ( - '—' - ) : ( + data?.stETHCurrencyPrice[currency.id] && isDataAvailable ? ( <> {currency.symbol} + ) : ( + '—' ) } valueDataTestId="stEthPrice" underValue={ - <> - {(isWalletConnected && !isSupportedChain) || - !data?.stETHCurrencyPrice[currency.id] ? ( - '—' - ) : ( - <> - - - ETH - - - )} - + data?.stETHCurrencyPrice[currency.id] && isDataAvailable ? ( + <> + + + ETH + + + ) : ( + '—' + ) } underValueDataTestId="ethRate" /> diff --git a/features/rewards/components/stats/steth-rewarded-block.tsx b/features/rewards/components/stats/steth-rewarded-block.tsx index 90dcae1d3..1c47c4047 100644 --- a/features/rewards/components/stats/steth-rewarded-block.tsx +++ b/features/rewards/components/stats/steth-rewarded-block.tsx @@ -3,16 +3,15 @@ import { Box } from '@lidofinance/lido-ui'; import { useRewardsHistory } from 'features/rewards/hooks'; import NumberFormat from 'features/rewards/components/NumberFormat'; -import { useDappStatus } from 'shared/hooks/use-dapp-status'; import { Item } from './components/item'; import { GreenText } from './components/styles'; export const StEthRewardedBlock: FC = () => { - const { isWalletConnected, isSupportedChain } = useDappStatus(); const { currencyObject: currency, data, + isDataAvailable, initialLoading: loading, } = useRewardsHistory(); @@ -22,29 +21,28 @@ export const StEthRewardedBlock: FC = () => { dataTestId="stEthRewardedBlock" title="stETH rewarded" value={ - (isWalletConnected && !isSupportedChain) || !data?.totals.ethRewards ? ( - '—' - ) : ( + data?.totals.ethRewards && isDataAvailable ? ( stETH + ) : ( + '—' ) } valueDataTestId="stEthRewarded" underValue={ - (isWalletConnected && !isSupportedChain) || - !data?.totals.currencyRewards ? ( - '—' - ) : ( + data?.totals.currencyRewards && isDataAvailable ? ( <> {currency.symbol} + ) : ( + '—' ) } underValueDataTestId="stEthRewardedIn$" diff --git a/providers/rewardsHistory.tsx b/providers/rewardsHistory.tsx index fe25eea3f..38c6ecc22 100644 --- a/providers/rewardsHistory.tsx +++ b/providers/rewardsHistory.tsx @@ -18,11 +18,12 @@ import { useRewardsDataLoad, useGetCurrentAddress, } from 'features/rewards/hooks'; - import { getCurrencyCookie } from 'features/rewards/components/CurrencySelector'; +import { useDappStatus } from 'shared/hooks/use-dapp-status'; export type RewardsHistoryValue = { currencyObject: CurrencyType; + isDataAvailable: boolean; data?: Backend; error?: unknown; initialLoading: boolean; @@ -49,6 +50,8 @@ export const RewardsHistoryContext = createContext({} as RewardsHistoryValue); const RewardsHistoryProvider: FC = (props) => { const { children } = props; + const { isWalletConnected, isSupportedChain } = useDappStatus(); + const [currency, setCurrency] = useState(DEFAULT_CURRENCY.id); useEffect(() => { @@ -88,8 +91,14 @@ const RewardsHistoryProvider: FC = (props) => { const currencyObject = getCurrency(currency); + const isDataNotAvailable = useMemo( + () => !data || (isWalletConnected && !isSupportedChain), + [data, isWalletConnected, isSupportedChain], + ); + const value = useMemo( (): RewardsHistoryValue => ({ + isDataAvailable: !isDataNotAvailable, data, error, loading, @@ -115,6 +124,7 @@ const RewardsHistoryProvider: FC = (props) => { address, addressError, currencyObject, + isDataNotAvailable, data, error, initialLoading, From 0d1befcdc5369786bfab60a8279016a567f6d9ef Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Thu, 22 Aug 2024 13:37:17 +0300 Subject: [PATCH 15/16] fix(rewards table): steth balance for input address --- .../rewardsListContent/RewardsListContent.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/features/rewards/components/rewardsListContent/RewardsListContent.tsx b/features/rewards/components/rewardsListContent/RewardsListContent.tsx index a00908765..e868152ae 100644 --- a/features/rewards/components/rewardsListContent/RewardsListContent.tsx +++ b/features/rewards/components/rewardsListContent/RewardsListContent.tsx @@ -1,6 +1,7 @@ import { FC } from 'react'; import { Loader, Divider } from '@lidofinance/lido-ui'; -import { useSTETHBalance } from '@lido-sdk/react'; +import { useSDK, useTokenBalance } from '@lido-sdk/react'; +import { TOKENS, getTokenAddress } from '@lido-sdk/constants'; import { Zero } from '@ethersproject/constants'; import { STRATEGY_LAZY } from 'consts/swr-strategies'; @@ -21,6 +22,7 @@ import { export const RewardsListContent: FC = () => { const { isWalletConnected, isSupportedChain } = useDappStatus(); const { + address, error, initialLoading, data, @@ -29,8 +31,14 @@ export const RewardsListContent: FC = () => { setPage, isLagging, } = useRewardsHistory(); + // temporarily until we switched to a new SDK + const { chainId } = useSDK(); const { data: stethBalance, initialLoading: isStethBalanceLoading } = - useSTETHBalance(STRATEGY_LAZY); + useTokenBalance( + getTokenAddress(chainId || 1, TOKENS.STETH), + address, + STRATEGY_LAZY, + ); const hasSteth = stethBalance?.gt(Zero); if (isWalletConnected && !isSupportedChain) From d9d098a7c4a5096b6cdaf7caf27f07260b88ee2f Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Thu, 22 Aug 2024 14:25:49 +0300 Subject: [PATCH 16/16] refactor(rewards history): set data to undefined if is data not available --- .../components/stats/average-apr-block.tsx | 8 ++------ .../components/stats/steth-balance-block.tsx | 6 +++--- .../components/stats/steth-price-block.tsx | 5 ++--- .../components/stats/steth-rewarded-block.tsx | 5 ++--- providers/rewardsHistory.tsx | 16 ++++++++-------- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/features/rewards/components/stats/average-apr-block.tsx b/features/rewards/components/stats/average-apr-block.tsx index 55b85b76d..e2e5aefeb 100644 --- a/features/rewards/components/stats/average-apr-block.tsx +++ b/features/rewards/components/stats/average-apr-block.tsx @@ -8,11 +8,7 @@ import { Item } from './components/item'; import { FlexCenter } from './components/styles'; export const AverageAprBlock: FC = () => { - const { - data, - isDataAvailable, - initialLoading: loading, - } = useRewardsHistory(); + const { data, initialLoading: loading } = useRewardsHistory(); return ( { } value={ - parseFloat(data?.averageApr || '0') && isDataAvailable ? ( + parseFloat(data?.averageApr || '0') ? ( <> diff --git a/features/rewards/components/stats/steth-balance-block.tsx b/features/rewards/components/stats/steth-balance-block.tsx index df7f76334..9fb0832ce 100644 --- a/features/rewards/components/stats/steth-balance-block.tsx +++ b/features/rewards/components/stats/steth-balance-block.tsx @@ -10,8 +10,8 @@ import { Item } from './components/item'; export const StEthBalanceBlock: FC = () => { const { data: balanceData } = useRewardsBalanceData(); const { + data: dataRewards, currencyObject: currency, - isDataAvailable, loading, } = useRewardsHistory(); @@ -21,7 +21,7 @@ export const StEthBalanceBlock: FC = () => { dataTestId="stEthBalanceBlock" title="stETH balance" value={ - balanceData?.stEthBalanceParsed && isDataAvailable ? ( + balanceData?.stEthBalanceParsed && dataRewards ? ( <> @@ -34,7 +34,7 @@ export const StEthBalanceBlock: FC = () => { } valueDataTestId="stEthBalance" underValue={ - balanceData?.stEthCurrencyBalance && isDataAvailable ? ( + balanceData?.stEthCurrencyBalance ? ( <> {currency.symbol} diff --git a/features/rewards/components/stats/steth-price-block.tsx b/features/rewards/components/stats/steth-price-block.tsx index ee0a49e49..dcc091cd4 100644 --- a/features/rewards/components/stats/steth-price-block.tsx +++ b/features/rewards/components/stats/steth-price-block.tsx @@ -11,7 +11,6 @@ export const StEthPriceBlock: FC = () => { const { currencyObject: currency, data, - isDataAvailable, initialLoading: loading, } = useRewardsHistory(); const stEthEth = useStethEthRate(); @@ -22,7 +21,7 @@ export const StEthPriceBlock: FC = () => { dataTestId="stEthPriceBlock" title="stETH price" value={ - data?.stETHCurrencyPrice[currency.id] && isDataAvailable ? ( + data?.stETHCurrencyPrice[currency.id] ? ( <> {currency.symbol} @@ -35,7 +34,7 @@ export const StEthPriceBlock: FC = () => { } valueDataTestId="stEthPrice" underValue={ - data?.stETHCurrencyPrice[currency.id] && isDataAvailable ? ( + data?.stETHCurrencyPrice[currency.id] ? ( <> diff --git a/features/rewards/components/stats/steth-rewarded-block.tsx b/features/rewards/components/stats/steth-rewarded-block.tsx index 1c47c4047..2881eca8a 100644 --- a/features/rewards/components/stats/steth-rewarded-block.tsx +++ b/features/rewards/components/stats/steth-rewarded-block.tsx @@ -11,7 +11,6 @@ export const StEthRewardedBlock: FC = () => { const { currencyObject: currency, data, - isDataAvailable, initialLoading: loading, } = useRewardsHistory(); @@ -21,7 +20,7 @@ export const StEthRewardedBlock: FC = () => { dataTestId="stEthRewardedBlock" title="stETH rewarded" value={ - data?.totals.ethRewards && isDataAvailable ? ( + data?.totals.ethRewards ? ( @@ -34,7 +33,7 @@ export const StEthRewardedBlock: FC = () => { } valueDataTestId="stEthRewarded" underValue={ - data?.totals.currencyRewards && isDataAvailable ? ( + data?.totals.currencyRewards ? ( <> {currency.symbol} diff --git a/providers/rewardsHistory.tsx b/providers/rewardsHistory.tsx index 38c6ecc22..fbf354ef9 100644 --- a/providers/rewardsHistory.tsx +++ b/providers/rewardsHistory.tsx @@ -23,7 +23,6 @@ import { useDappStatus } from 'shared/hooks/use-dapp-status'; export type RewardsHistoryValue = { currencyObject: CurrencyType; - isDataAvailable: boolean; data?: Backend; error?: unknown; initialLoading: boolean; @@ -91,15 +90,16 @@ const RewardsHistoryProvider: FC = (props) => { const currencyObject = getCurrency(currency); - const isDataNotAvailable = useMemo( - () => !data || (isWalletConnected && !isSupportedChain), - [data, isWalletConnected, isSupportedChain], - ); + const isDataAvailable = useMemo(() => { + const isDataNotAvailable = + !data || (isWalletConnected && !isSupportedChain); + return !isDataNotAvailable; + }, [data, isWalletConnected, isSupportedChain]); const value = useMemo( (): RewardsHistoryValue => ({ - isDataAvailable: !isDataNotAvailable, - data, + // we want user to not confuse which chain rewards are showing + data: isDataAvailable ? data : undefined, error, loading, initialLoading, @@ -124,7 +124,7 @@ const RewardsHistoryProvider: FC = (props) => { address, addressError, currencyObject, - isDataNotAvailable, + isDataAvailable, data, error, initialLoading,