Skip to content

Commit

Permalink
Merge pull request #438 from lidofinance/feature/si-1557-rewards-hist…
Browse files Browse the repository at this point in the history
…ory-with-address-input-back

feat: rewards history with address input back
  • Loading branch information
itaven authored Aug 20, 2024
2 parents 33f9b8f + b6cc5bd commit 84a98b2
Show file tree
Hide file tree
Showing 24 changed files with 409 additions and 282 deletions.
3 changes: 3 additions & 0 deletions assets/icons/error-triangle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions features/rewards/components/address-input/address-input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { FC, useMemo } from 'react';
import { Input, Loader, Identicon } from '@lidofinance/lido-ui';
import CopyAddressUrl from 'features/rewards/components/CopyAddressUrl';
import { isValidAnyAddress } from 'features/rewards/utils';
import { ReactComponent as ErrorTriangle } from 'assets/icons/error-triangle.svg';

import { AddressInputProps } from './types';

export const AddressInput: FC<AddressInputProps> = (props) => {
const {
inputValue,
isAddressResolving,
handleInputChange,
address,
addressError: invalidENSAddress,
loading,
} = props;

const invalidEthereumAddress = useMemo(
() => inputValue.length > 0 && !isValidAnyAddress(inputValue),
[inputValue],
);

return (
<Input
fullwidth
value={inputValue}
onChange={(e) => handleInputChange(e.target.value)}
placeholder="Ethereum address"
leftDecorator={
loading || isAddressResolving ? (
<Loader size="small" />
) : invalidEthereumAddress || invalidENSAddress ? (
<ErrorTriangle />
) : address ? (
<Identicon data-testid="addressIcon" address={address} />
) : null
}
rightDecorator={address ? <CopyAddressUrl address={inputValue} /> : null}
spellCheck="false"
error={
invalidEthereumAddress
? 'Invalid ethereum address'
: invalidENSAddress
? invalidENSAddress
: null
}
/>
);
};
1 change: 1 addition & 0 deletions features/rewards/components/address-input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './address-input';
8 changes: 8 additions & 0 deletions features/rewards/components/address-input/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type AddressInputProps = {
inputValue: string;
isAddressResolving: boolean;
handleInputChange: (value: string) => void;
address: string;
addressError: string;
loading: boolean;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { ErrorBlockBase } from './ErrorBlockBase';
export const ErrorBlockServer = () => (
<ErrorBlockBase
textProps={{ color: 'error' }}
text="Subgraph returned a fatal error. Lido contributors were alerted and are working on a fix. Please repeat the request in a while."
text="Failed to fetch data from the Subgraph. Maintainers are notified and working on a fix."
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ 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';
Expand All @@ -18,7 +17,6 @@ import {
} from './RewardsListContentStyles';

export const RewardsListContent: FC = () => {
const { isDappActive } = useDappStatus();
const {
error,
initialLoading,
Expand All @@ -32,8 +30,7 @@ export const RewardsListContent: FC = () => {
useSTETHBalance(STRATEGY_LAZY);
const hasSteth = stethBalance?.gt(Zero);

if (!isDappActive || (!data && !initialLoading && !error))
return <RewardsListsEmpty />;
if (!data && !initialLoading && !error) return <RewardsListsEmpty />;
// showing loading when canceling requests and empty response
if (
(!data && !error) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ export const RewardsListErrorMessage: React.FC<Props> = ({ error }) => {
return <ErrorUnprocessable />;
}

return <ErrorBlockBase text={errorMessage} />;
return <ErrorBlockBase textProps={{ color: 'error' }} text={errorMessage} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export const RewardsListsEmpty: FC = () => {
<>
<Divider indents="lg" />
<RewardsListEmptyWrapper>
<p>Connect your wallet to view your staking rewards</p>
<p>
Connect your wallet or enter your Ethereum address to see the stats.
</p>
{isWalletConnected ? null : (
<RewardsListEmptyButtonWrapper>
<Button
Expand Down
17 changes: 0 additions & 17 deletions features/rewards/components/stats/Item.tsx

This file was deleted.

20 changes: 0 additions & 20 deletions features/rewards/components/stats/Stat.tsx

This file was deleted.

96 changes: 0 additions & 96 deletions features/rewards/components/stats/Stats.tsx

This file was deleted.

21 changes: 0 additions & 21 deletions features/rewards/components/stats/Title.tsx

This file was deleted.

44 changes: 44 additions & 0 deletions features/rewards/components/stats/average-apr-block.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { FC } from 'react';
import { Box, Question, Tooltip } from '@lidofinance/lido-ui';

import NumberFormat from 'features/rewards/components/NumberFormat';
import { useRewardsHistory } from 'features/rewards/hooks';

import { Item } from './components/item';
import { FlexCenter } from './components/styles';

export const AverageAprBlock: FC = () => {
const { data, initialLoading: loading } = useRewardsHistory();

return (
<Item
loading={loading}
dataTestId="averageAprBlock"
title={
<>
<FlexCenter>
Average APR
<Tooltip title={'APR on stETH over your staking period'}>
<Question />
</Tooltip>
</FlexCenter>
</>
}
value={
<>
{parseFloat(data?.averageApr || '0') ? (
<>
<NumberFormat number={data?.averageApr} percent />
<Box display="inline-block" pl="3px">
%
</Box>
</>
) : (
'—'
)}
</>
}
valueDataTestId="averageApr"
/>
);
};
40 changes: 40 additions & 0 deletions features/rewards/components/stats/components/item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { FC, ReactNode } from 'react';

import { Block, Title, Value, UnderValue, InlineLoader } from './styles';

type ItemProps = {
dataTestId: string;
title: ReactNode | ReactNode[];

value: ReactNode | ReactNode[];
valueDataTestId: string;

underValue?: ReactNode | ReactNode[] | undefined;
underValueDataTestId?: string | undefined;

loading: boolean;
};

export const Item: FC<ItemProps> = (props) => {
const {
dataTestId,
title,
value,
valueDataTestId,
underValue,
underValueDataTestId,
loading,
} = props;

return (
<Block data-testid={dataTestId}>
<Title>{title}</Title>
<Value data-testid={valueDataTestId}>
{!loading ? value : <InlineLoader />}
</Value>
<UnderValue data-testid={underValueDataTestId}>
{!loading ? underValue : <InlineLoader />}
</UnderValue>
</Block>
);
};
Loading

0 comments on commit 84a98b2

Please sign in to comment.