Skip to content
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

Show precise balance in chart tooltip #1600

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/1600.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show precise balance in chart tooltip
5 changes: 2 additions & 3 deletions src/app/components/charts/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const StyledPaper = styled(Paper)(({ theme }) => ({

export type Formatters = {
formatters?: {
data?: (value: number) => string
data?: (value: number, payload?: { [key: string]: string | number }) => string
label?: (value: string) => string
}
}
Expand All @@ -36,7 +36,6 @@ export const TooltipContent = ({
if (!active || !payload || !payload.length) {
return null
}

const { [payload[0].dataKey!]: value, ...rest } = payload[0].payload
const labelKey = dataLabelKey || Object.keys(rest)[0]

Expand All @@ -46,7 +45,7 @@ export const TooltipContent = ({
{formatters?.label ? formatters.label(payload[0].payload[labelKey]) : payload[0].payload[labelKey]}
</Typography>
<Typography paragraph={false} sx={{ fontSize: 12, fontWeight: 600 }}>
{formatters?.data ? formatters.data(payload[0].value!) : payload[0].value}
{formatters?.data ? formatters.data(payload[0].value!, payload[0].payload.payload) : payload[0].value}
</Typography>
</StyledPaper>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,21 @@ const BalanceDistributionContent: FC<BalanceDistributionContentProps> = ({ accou
return <ConsensusAccountCardEmptyState label={t('account.noBalances')} />
}

// value props have rounding issues. Avoid displaying in text, but they are fine for visualization
const data = [
{
label: t('account.available'),
preciseValue: account.available,
value: Number(account.available),
buberdds marked this conversation as resolved.
Show resolved Hide resolved
},
{
label: t('common.staked'),
preciseValue: account.delegations_balance,
value: Number(account.delegations_balance),
},
{
label: t('account.debonding'),
preciseValue: account.debonding_delegations_balance,
value: Number(account.debonding_delegations_balance),
},
]
Expand All @@ -88,9 +92,9 @@ const BalanceDistributionContent: FC<BalanceDistributionContentProps> = ({ accou
data={data}
dataKey="value"
formatters={{
data: (value: number) =>
data: (value, payload) =>
t('common.valueInToken', {
...getPreciseNumberFormat(value.toString()),
...getPreciseNumberFormat(String(payload!.preciseValue)),
ticker: account.ticker,
}),
label: (label: string) => label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ function chartData(t: TFunction, validator: Validator | undefined) {
return []
}

// value props have rounding issues. Avoid displaying in text, but they are fine for visualization
return [
{
label: t('validator.self'),
preciseValue: validator.escrow.self_delegation_balance,
value: Number(validator.escrow.self_delegation_balance),
},
{
label: t('validator.others'),
preciseValue: validator.escrow.self_delegation_balance,
value: Number(validator.escrow.otherBalance),
},
]
Expand Down Expand Up @@ -59,9 +62,9 @@ export const BalanceDistributionCard: FC<BalanceDistributionCardProps> = ({ vali
data={chartData(t, validator)}
dataKey="value"
formatters={{
data: (value: number) =>
data: (value, payload) =>
t('common.valueInToken', {
...getPreciseNumberFormat(value.toString()),
...getPreciseNumberFormat(String(payload!.preciseValue)),
ticker: validator.ticker,
}),
label: (label: string) => label,
Expand Down
Loading