Skip to content

Commit

Permalink
refactor(rewards history): set data to undefined if is data not avail…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
solidovic committed Aug 22, 2024
1 parent 0d1befc commit d9d098a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
8 changes: 2 additions & 6 deletions features/rewards/components/stats/average-apr-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Item
Expand All @@ -27,7 +23,7 @@ export const AverageAprBlock: FC = () => {
</FlexCenter>
}
value={
parseFloat(data?.averageApr || '0') && isDataAvailable ? (
parseFloat(data?.averageApr || '0') ? (
<>
<NumberFormat number={data?.averageApr} percent />
<Box display="inline-block" pl="3px">
Expand Down
6 changes: 3 additions & 3 deletions features/rewards/components/stats/steth-balance-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -21,7 +21,7 @@ export const StEthBalanceBlock: FC = () => {
dataTestId="stEthBalanceBlock"
title="stETH balance"
value={
balanceData?.stEthBalanceParsed && isDataAvailable ? (
balanceData?.stEthBalanceParsed && dataRewards ? (
<>
<NumberFormat number={balanceData?.stEthBalanceParsed} />
<Box display="inline-block" pl={'3px'}>
Expand All @@ -34,7 +34,7 @@ export const StEthBalanceBlock: FC = () => {
}
valueDataTestId="stEthBalance"
underValue={
balanceData?.stEthCurrencyBalance && isDataAvailable ? (
balanceData?.stEthCurrencyBalance ? (
<>
<Box display="inline-block" pr={'3px'}>
{currency.symbol}
Expand Down
5 changes: 2 additions & 3 deletions features/rewards/components/stats/steth-price-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const StEthPriceBlock: FC = () => {
const {
currencyObject: currency,
data,
isDataAvailable,
initialLoading: loading,
} = useRewardsHistory();
const stEthEth = useStethEthRate();
Expand All @@ -22,7 +21,7 @@ export const StEthPriceBlock: FC = () => {
dataTestId="stEthPriceBlock"
title="stETH price"
value={
data?.stETHCurrencyPrice[currency.id] && isDataAvailable ? (
data?.stETHCurrencyPrice[currency.id] ? (
<>
<Box display="inline-block" pr="3px">
{currency.symbol}
Expand All @@ -35,7 +34,7 @@ export const StEthPriceBlock: FC = () => {
}
valueDataTestId="stEthPrice"
underValue={
data?.stETHCurrencyPrice[currency.id] && isDataAvailable ? (
data?.stETHCurrencyPrice[currency.id] ? (
<>
<NumberFormat number={stEthEth?.toString()} StEthEth />
<Box display="inline-block" pl={'3px'}>
Expand Down
5 changes: 2 additions & 3 deletions features/rewards/components/stats/steth-rewarded-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const StEthRewardedBlock: FC = () => {
const {
currencyObject: currency,
data,
isDataAvailable,
initialLoading: loading,
} = useRewardsHistory();

Expand All @@ -21,7 +20,7 @@ export const StEthRewardedBlock: FC = () => {
dataTestId="stEthRewardedBlock"
title="stETH rewarded"
value={
data?.totals.ethRewards && isDataAvailable ? (
data?.totals.ethRewards ? (
<GreenText>
<NumberFormat number={data?.totals.ethRewards} />
<Box display="inline-block" pl={'3px'}>
Expand All @@ -34,7 +33,7 @@ export const StEthRewardedBlock: FC = () => {
}
valueDataTestId="stEthRewarded"
underValue={
data?.totals.currencyRewards && isDataAvailable ? (
data?.totals.currencyRewards ? (
<>
<Box display="inline-block" pr={'3px'}>
{currency.symbol}
Expand Down
16 changes: 8 additions & 8 deletions providers/rewardsHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,15 +90,16 @@ const RewardsHistoryProvider: FC<PropsWithChildren> = (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,
Expand All @@ -124,7 +124,7 @@ const RewardsHistoryProvider: FC<PropsWithChildren> = (props) => {
address,
addressError,
currencyObject,
isDataNotAvailable,
isDataAvailable,
data,
error,
initialLoading,
Expand Down

0 comments on commit d9d098a

Please sign in to comment.