-
Notifications
You must be signed in to change notification settings - Fork 13
feat(staking): [LW-6437, LW-8877] past epochs rewards chart #718
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
Merged
przemyslaw-wlodek
merged 17 commits into
main
from
feat/LW-6437-past-epochs-rewards-chart
Nov 28, 2023
Merged
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d08e749
feat(staking): add activity tab
refi93 3e715af
Merge branch 'main' into feat/lw-8877-activity-tab
refi93 32f07b5
Merge branch 'main' into feat/lw-8877-activity-tab
refi93 dcd5f83
feat(staking): [LW-8877] Add activity tab to staking, show rewards li…
refi93 665fed5
feat(staking): add past epochs rewards chart
mrcnk 801f33d
fix(staking): fix yarn lock resolution
mrcnk be0a21c
fix(staking): add missing translations
mrcnk bacce5c
Merge branch 'main' into feat/LW-6437-past-epochs-rewards-chart
refi93 436057c
fix(staking): fix types
refi93 f09ac55
fix(staking): show rewards chart only if non-empty
refi93 f417372
refactor(staking): refactor useRewardsByEpoch
refi93 60827b2
fix(staking): fix epoch numbers in rewards chart
refi93 843637e
fix(staking): use consistent coloring of pools across epochs
refi93 e294271
refactor(staking): reorganize rewards chart files into own subfolder
refi93 29e17a6
feat(staking): remove USE_MULTI_DELEGATION_STAKING_ACTIVITY feature flag
refi93 a1a91f0
Merge remote-tracking branch 'upstream/main' into feat/LW-6437-past-e…
przemyslaw-wlodek 48668a8
feat(staking): disable chart animation
oldGreg5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { StateStatus, useOutsideHandles } from 'features/outside-handles-provider'; | ||
| import { getGroupedRewardsActivities } from './helpers/getGroupedRewardsHistory'; | ||
| import { NoStakingActivity } from './NoStakingActivity'; | ||
| import { PastEpochsRewards } from './PastEpochsRewards'; | ||
| import { RewardsHistory } from './RewardsHistory'; | ||
|
|
||
| export const Activity = () => { | ||
| const { walletStoreWalletActivitiesStatus: walletActivitiesStatus, walletStoreWalletActivities: walletActivities } = | ||
| useOutsideHandles(); | ||
| const groupedRewardsActivities = getGroupedRewardsActivities(walletActivities); | ||
|
|
||
| return ( | ||
| <> | ||
| <PastEpochsRewards /> | ||
| {walletActivitiesStatus === StateStatus.LOADED && groupedRewardsActivities.length === 0 ? ( | ||
| <NoStakingActivity /> | ||
| ) : ( | ||
| <RewardsHistory | ||
| walletActivitiesStatus={walletActivitiesStatus} | ||
| groupedRewardsActivities={groupedRewardsActivities} | ||
| /> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
4 changes: 4 additions & 0 deletions
4
packages/staking/src/features/activity/EpochsSwitch.module.scss
refi93 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .buttonsBackground { | ||
| background-color: var(--light-mode-light-grey, var(--dark-mode-dark-grey, #2f2f2f)); | ||
| border-radius: 1rem; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { ControlButton, Flex, Text } from '@lace/ui'; | ||
| import styles from './EpochsSwitch.module.scss'; | ||
|
|
||
| // eslint-disable-next-line no-magic-numbers | ||
| const EPOCHS_OPTIONS = [5, 15]; | ||
|
|
||
| export type EpochsSwitchProps = { | ||
mrcnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| epochsCount: number; | ||
| setEpochsCount: (epochsCount: number) => void; | ||
| }; | ||
|
|
||
| export const EpochsSwitch = ({ epochsCount, setEpochsCount }: EpochsSwitchProps) => ( | ||
| <Flex gap="$8" alignItems="center"> | ||
| <Text.Body.Normal>Epochs:</Text.Body.Normal> | ||
mrcnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Flex p="$8" gap="$8" alignItems="center" className={styles.buttonsBackground}> | ||
| {EPOCHS_OPTIONS.map((option, i) => { | ||
| const activeOption = epochsCount === option; | ||
| const Component = activeOption ? ControlButton.Filled : ControlButton.Outlined; | ||
| return <Component key={i} label={`Last ${option}`} onClick={() => setEpochsCount(option)} />; | ||
mrcnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| })} | ||
| </Flex> | ||
| </Flex> | ||
| ); | ||
13 changes: 13 additions & 0 deletions
13
packages/staking/src/features/activity/NoStakingActivity.css.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { style } from '@lace/ui'; | ||
| import { theme } from 'features/theme'; | ||
|
|
||
| export const sadFaceIcon = style({ | ||
| height: theme.spacing.$112, | ||
| width: theme.spacing.$112, | ||
| }); | ||
|
|
||
| export const noActivityText = style({ | ||
| color: theme.colors.$activityNoActivityTextColor, | ||
| fontSize: theme.fontSizes.$14, | ||
| fontWeight: theme.fontWeights.$semibold, | ||
| }); |
17 changes: 17 additions & 0 deletions
17
packages/staking/src/features/activity/NoStakingActivity.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import SadFaceIcon from '@lace/core/src/ui/assets/icons/sad-face.component.svg'; | ||
| import { Flex } from '@lace/ui'; | ||
| import { Typography } from 'antd'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import * as styles from './NoStakingActivity.css'; | ||
|
|
||
| export const NoStakingActivity = () => { | ||
| const { t } = useTranslation(); | ||
| return ( | ||
| <Flex h="$fill" flexDirection="column" alignItems="center" justifyContent="center" gap="$8"> | ||
| <SadFaceIcon className={styles.sadFaceIcon} /> | ||
| <Typography.Text className={styles.noActivityText}> | ||
| {t('activity.rewardsHistory.noStakingActivityYet')} | ||
| </Typography.Text> | ||
| </Flex> | ||
| ); | ||
| }; |
23 changes: 23 additions & 0 deletions
23
packages/staking/src/features/activity/PastEpochsRewards.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { Flex, Text } from '@lace/ui'; | ||
| import { useState } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { EpochsSwitch } from './EpochsSwitch'; | ||
| import { RewardsChart } from './RewardsChart'; | ||
| import { useRewardsByEpoch } from './useRewardsByEpoch'; | ||
|
|
||
| const DEFAULT_LAST_EPOCHS = 5; | ||
|
|
||
| export const PastEpochsRewards = () => { | ||
| const [epochsCount, setEpochsCount] = useState(DEFAULT_LAST_EPOCHS); | ||
| const { t } = useTranslation(); | ||
| const { rewardsByEpoch } = useRewardsByEpoch({ epochsCount }); | ||
| return ( | ||
| <> | ||
| <Flex mb="$32" justifyContent="space-between" alignItems="center"> | ||
| <Text.SubHeading>{t('activity.rewardsChart.title')}</Text.SubHeading> | ||
| <EpochsSwitch epochsCount={epochsCount} setEpochsCount={setEpochsCount} /> | ||
| </Flex> | ||
| {rewardsByEpoch && <RewardsChart chartData={rewardsByEpoch} />} | ||
| </> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { PIE_CHART_DEFAULT_COLOR_SET } from '@lace/ui'; | ||
|
|
||
| export const PoolIndicator = ({ color = PIE_CHART_DEFAULT_COLOR_SET[0] }: { color?: string }) => ( | ||
| <svg width="4" height="41" viewBox="0 0 4 41" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
| <rect x="4" y="0.5" width="40" height="4" rx="2" transform="rotate(90 4 0.5)" fill={color} /> | ||
| </svg> | ||
| ); |
3 changes: 3 additions & 0 deletions
3
packages/staking/src/features/activity/RewardsChart.module copy.scss
mrcnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .chartContainer { | ||
| height: auto; | ||
| } |
3 changes: 3 additions & 0 deletions
3
packages/staking/src/features/activity/RewardsChart.module.scss
mrcnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .chartContainer { | ||
| height: auto; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { Card, PIE_CHART_DEFAULT_COLOR_SET } from '@lace/ui'; | ||
| import { Bar, BarChart, Cell, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'; | ||
| import { GRAYSCALE_PALETTE, maxPoolsIterator } from './const'; | ||
| import { RewardsChartTooltip } from './RewardsChartTooltip'; | ||
| import { usePoolInPortfolioPresence } from './usePoolInPortfolioPresence'; | ||
| import { RewardsByEpoch } from './useRewardsByEpoch'; | ||
|
|
||
| export const RewardsChart = ({ chartData }: { chartData: RewardsByEpoch }) => { | ||
| const { checkIfPoolIsInPortfolio } = usePoolInPortfolioPresence(); | ||
| return ( | ||
| <Card.Outlined> | ||
| <ResponsiveContainer width="100%" aspect={2.4} height="auto"> | ||
| <BarChart | ||
| width={500} | ||
| height={300} | ||
| data={chartData} | ||
| margin={{ | ||
| bottom: 32, | ||
| left: 24, | ||
| right: 24, | ||
| top: 32, | ||
| }} | ||
| > | ||
| <XAxis dataKey="epoch" tickLine={false} axisLine={false} tickMargin={16} /> | ||
| <YAxis tickLine={false} axisLine={false} tickFormatter={(value) => `${value} ADA`} /> | ||
| <Tooltip cursor={false} content={<RewardsChartTooltip />} /> | ||
| {maxPoolsIterator.map((_, i) => ( | ||
| <Bar key={i} dataKey={`rewards[${i}].rewards`} stackId="a" maxBarSize={24}> | ||
| {chartData.map((entry, j) => { | ||
| const fill = | ||
| entry.rewards[i]?.poolId && checkIfPoolIsInPortfolio(entry.rewards[i]?.poolId) | ||
| ? PIE_CHART_DEFAULT_COLOR_SET[i] | ||
| : GRAYSCALE_PALETTE[i]; | ||
| return <Cell key={`cell-${j}`} fill={fill} />; | ||
| })} | ||
| </Bar> | ||
| ))} | ||
| </BarChart> | ||
| </ResponsiveContainer> | ||
| </Card.Outlined> | ||
| ); | ||
| }; |
38 changes: 38 additions & 0 deletions
38
packages/staking/src/features/activity/RewardsChartTooltip.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { Card, Flex, PIE_CHART_DEFAULT_COLOR_SET, Text } from '@lace/ui'; | ||
| import { TooltipProps } from 'recharts'; | ||
| import { NameType, ValueType } from 'recharts/types/component/DefaultTooltipContent'; | ||
| import { GRAYSCALE_PALETTE, maxPoolsIterator } from './const'; | ||
| import { PoolIndicator } from './PoolIndicator'; | ||
| import { usePoolInPortfolioPresence } from './usePoolInPortfolioPresence'; | ||
|
|
||
| export const RewardsChartTooltip = ({ active, payload, label }: TooltipProps<ValueType, NameType>) => { | ||
| const { checkIfPoolIsInPortfolio } = usePoolInPortfolioPresence(); | ||
| if (active && payload && payload.length > 0) { | ||
| return ( | ||
| <Card.Elevated className="custom-tooltip"> | ||
| <Flex flexDirection="column" px="$16" py="$8"> | ||
| <Text.Body.Small weight="$semibold">Epoch {label}</Text.Body.Small> | ||
mrcnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Flex flexDirection="column" gap="$4"> | ||
| {maxPoolsIterator.map((_, i) => { | ||
| const poolId = payload[i]?.payload?.rewards?.[i]?.poolId; | ||
| const poolInPortfolio = payload[i] && checkIfPoolIsInPortfolio(poolId); | ||
| return ( | ||
| payload[i] && ( | ||
| <Flex gap="$8" key={i} alignItems="center"> | ||
| <PoolIndicator color={poolInPortfolio ? PIE_CHART_DEFAULT_COLOR_SET[i] : GRAYSCALE_PALETTE[i]} /> | ||
refi93 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Flex flexDirection="column"> | ||
| <Text.Body.Small>{payload[i]?.payload?.rewards?.[i]?.metadata.name}</Text.Body.Small> | ||
| <Text.Body.Small>Rewards: {payload[i]?.value} ADA</Text.Body.Small> | ||
mrcnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </Flex> | ||
| </Flex> | ||
| ) | ||
| ); | ||
| })} | ||
| </Flex> | ||
| </Flex> | ||
| </Card.Elevated> | ||
| ); | ||
| } | ||
|
|
||
| return null; | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.