Skip to content

Commit 8c55f46

Browse files
authored
feat(staking): [LW-8684] add tooltip to piechart (#616)
* feat: lw-8684-add tooltip to delegation piechart * fix: add custom tooltip dot style
1 parent c193547 commit 8c55f46

File tree

14 files changed

+178
-24
lines changed

14 files changed

+178
-24
lines changed

packages/staking/src/features/delegation-card/DelegationCard.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import cn from 'classnames';
33
import { Fragment, useMemo } from 'react';
44
import { useTranslation } from 'react-i18next';
55
import { TranslationKey } from '../i18n';
6-
// import { PERCENTAGE_SCALE_MAX } from '../store';
76
import * as styles from './DelegationCard.css';
7+
import { DelegationTooltip } from './DelegationTooltip';
8+
import { DistributionItem } from './types';
89

910
// TODO
1011
const PERCENTAGE_SCALE_MAX = 100;
@@ -15,17 +16,11 @@ export type DelegationStatus =
1516
| 'under-allocated'
1617
| 'no-selection';
1718

18-
type Distribution = Array<{
19-
name: string;
20-
percentage: number;
21-
color: PieChartColor;
22-
}>;
23-
2419
type DelegationCardProps = {
2520
arrangement?: 'vertical' | 'horizontal';
2621
balance: string;
2722
cardanoCoinSymbol: string;
28-
distribution: Distribution;
23+
distribution: DistributionItem[];
2924
status: DelegationStatus;
3025
showDistribution?: boolean;
3126
};
@@ -72,7 +67,7 @@ export const DelegationCard = ({
7267

7368
const { data, colorSet = PIE_CHART_DEFAULT_COLOR_SET } = useMemo((): {
7469
colorSet?: PieChartColor[];
75-
data: Distribution;
70+
data: DistributionItem[];
7671
} => {
7772
const GREY_COLOR: PieChartColor = '#C0C0C0';
7873
const RED_COLOR: PieChartColor = '#FF5470';
@@ -118,7 +113,7 @@ export const DelegationCard = ({
118113
data-testid="delegation-info-card"
119114
>
120115
<div className={styles.chart} data-testid="delegation-chart">
121-
<PieChart data={data} nameKey="name" valueKey="percentage" colors={colorSet} />
116+
<PieChart data={data} nameKey="name" valueKey="percentage" colors={colorSet} tooltip={DelegationTooltip} />
122117
{showDistribution && <Text.SubHeading className={styles.counter}>{totalPercentage}%</Text.SubHeading>}
123118
</div>
124119
<div
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { style } from '@vanilla-extract/css';
2+
import { theme } from '../theme';
3+
4+
export const tooltip = style({
5+
background: theme.colors.$tooltipBgColor,
6+
borderRadius: theme.radius.$small,
7+
boxShadow: theme.elevation.$tooltip,
8+
margin: theme.spacing.$10,
9+
maxWidth: theme.spacing.$214,
10+
padding: theme.spacing.$16,
11+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Box, Flex, RichContentInner, TooltipContentRendererProps } from '@lace/ui';
2+
import { ReactElement } from 'react';
3+
import { useTranslation } from 'react-i18next';
4+
import * as styles from './DelegationTooltip.css';
5+
import { DistributionItem } from './types';
6+
7+
export const DelegationTooltip = ({
8+
active,
9+
name,
10+
payload,
11+
}: Readonly<TooltipContentRendererProps<DistributionItem & { fill?: string }>>): ReactElement | null => {
12+
const { t } = useTranslation();
13+
if (active && payload) {
14+
const { apy, saturation, fill } = payload;
15+
16+
return (
17+
<Box className={styles.tooltip}>
18+
<RichContentInner
19+
title={name || ''}
20+
dotColor={fill}
21+
description={
22+
<Box w="$148">
23+
<Flex justifyContent="space-between">
24+
<Box>{t('browsePools.stakePoolTableBrowser.tableHeader.ros.title')}</Box>
25+
<Box>{apy ? `${apy}%` : '-'}</Box>
26+
</Flex>
27+
<Flex justifyContent="space-between">
28+
<Box>{t('browsePools.stakePoolTableBrowser.tableHeader.saturation.title')}</Box>
29+
<Box>{saturation ? `${saturation}%` : '-'}</Box>
30+
</Flex>
31+
</Box>
32+
}
33+
/>
34+
</Box>
35+
);
36+
}
37+
38+
// eslint-disable-next-line unicorn/no-null
39+
return null;
40+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { PieChartColor } from '@lace/ui';
2+
3+
export type DistributionItem = {
4+
name: string;
5+
percentage: number;
6+
color: PieChartColor;
7+
apy?: string;
8+
saturation?: string;
9+
};

packages/staking/src/features/drawer/preferences/StepPreferencesContent.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,20 @@ export const StepPreferencesContent = () => {
4848

4949
const displayData = draftPortfolio.map((draftPool, i) => {
5050
const {
51-
displayData: { name },
51+
displayData: { name, apy, saturation },
5252
id,
5353
sliderIntegerPercentage,
5454
} = draftPool;
5555

5656
return {
57+
apy: apy ? String(apy) : undefined,
5758
cardanoCoinSymbol,
5859
color: PIE_CHART_DEFAULT_COLOR_SET[i] as PieChartColor,
5960
id,
6061
name: name || '-',
6162
onChainPercentage: draftPool.basedOnCurrentPortfolio ? draftPool.onChainPercentage : undefined,
6263
percentage: sliderIntegerPercentage,
64+
saturation: saturation ? String(saturation) : undefined,
6365
savedIntegerPercentage: draftPool.basedOnCurrentPortfolio ? draftPool.savedIntegerPercentage : undefined,
6466
// TODO
6567
sliderIntegerPercentage,

packages/staking/src/features/overview/Overview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ export const Overview = () => {
9595
<DelegationCard
9696
balance={compactNumber(balancesBalance.available.coinBalance)}
9797
cardanoCoinSymbol={walletStoreWalletUICardanoCoin.symbol}
98-
distribution={displayData.map(({ color, name = '-', onChainPercentage }) => ({
98+
distribution={displayData.map(({ color, name = '-', onChainPercentage, apy, saturation }) => ({
99+
apy: apy ? String(apy) : undefined,
99100
color,
100101
name,
101102
percentage: onChainPercentage,
103+
saturation: saturation ? String(saturation) : undefined,
102104
}))}
103105
status={currentPortfolio.length === 1 ? 'simple-delegation' : 'multi-delegation'}
104106
/>

packages/staking/src/features/overview/OverviewPopup.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ export const OverviewPopup = () => {
9898
balance={compactNumber(balancesBalance.available.coinBalance)}
9999
cardanoCoinSymbol={walletStoreWalletUICardanoCoin.symbol}
100100
arrangement="vertical"
101-
distribution={displayData.map(({ color, name = '-', onChainPercentage }) => ({
101+
distribution={displayData.map(({ color, name = '-', onChainPercentage, apy, saturation }) => ({
102+
apy: apy ? String(apy) : undefined,
102103
color,
103104
name,
104105
percentage: onChainPercentage,
106+
saturation: saturation ? String(saturation) : undefined,
105107
}))}
106108
status={currentPortfolio.length === 1 ? 'simple-delegation' : 'multi-delegation'}
107109
/>

packages/staking/src/features/theme/colors.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const colorsContract = {
2323
$sliderFillSecondary: '',
2424
$sliderKnobFill: '',
2525
$sliderRailFill: '',
26+
$tooltipBgColor: '',
2627
};
2728

2829
export const lightThemeColors: typeof colorsContract = {
@@ -48,6 +49,7 @@ export const lightThemeColors: typeof colorsContract = {
4849
$sliderFillSecondary: lightColorScheme.$primary_dark_grey,
4950
$sliderKnobFill: lightColorScheme.$primary_white,
5051
$sliderRailFill: lightColorScheme.$primary_light_grey_plus,
52+
$tooltipBgColor: lightColorScheme.$primary_white,
5153
};
5254

5355
export const darkThemeColors: typeof colorsContract = {
@@ -78,4 +80,5 @@ export const darkThemeColors: typeof colorsContract = {
7880
$sliderFillSecondary: darkColorScheme.$primary_light_grey,
7981
$sliderKnobFill: lightColorScheme.$primary_black,
8082
$sliderRailFill: darkColorScheme.$primary_dark_grey_plus,
83+
$tooltipBgColor: darkColorScheme.$primary_mid_grey,
8184
};

packages/ui/src/design-system/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export * as FlowCard from './flow-card';
2121
export * as IconButton from './icon-buttons';
2222
export * as TransactionSummary from './transaction-summary';
2323
export { ToastBar } from './toast-bar';
24-
export { Tooltip } from './tooltip';
24+
export * from './tooltip';
2525
export { Message } from './message';
2626
export { PasswordBox } from './password-box';
2727
export { Metadata } from './metadata';

packages/ui/src/design-system/pie-chart/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
export type { PieChartColor, PieChartProps } from './pie-chart.component';
1+
export type {
2+
PieChartColor,
3+
PieChartProps,
4+
TooltipContentRendererProps,
5+
} from './pie-chart.component';
26
export { PieChart } from './pie-chart.component';
37
export {
48
PIE_CHART_DEFAULT_COLOR_SET,

0 commit comments

Comments
 (0)