Skip to content
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
20 changes: 15 additions & 5 deletions packages/app-staking/src/Query/Validator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type LineData = LineDataEntry[];
interface SplitEntry {
colors: string[];
label: string;
tooltip: string;
value: number;
}

Expand Down Expand Up @@ -70,16 +71,25 @@ function extractSplit (values: [Hash, Exposure][], validatorId: string): SplitDa
return null;
}

const currency = formatBalance.getDefaults().unit;

return [{ accountId: validatorId, isOwn: true, value: last.own.unwrap() }]
.concat(last.others.map(({ who, value }): { accountId: string; isOwn: boolean; value: Balance } => ({
accountId: who.toString(), isOwn: false, value: value.unwrap()
})))
.sort((a, b): number => b.value.cmp(a.value))
.map(({ accountId, isOwn, value }): SplitEntry => ({
colors: isOwn ? COLORS_MINE : COLORS_OTHER,
label: toShortAddress(accountId),
value: value.muln(10000).div(total).toNumber() / 100
}));
.map(({ accountId, isOwn, value }): SplitEntry => {
const label = toShortAddress(accountId);
const percentage = value.muln(10000).div(total).toNumber() / 100;
const tooltip = `${formatBalance(value, { forceUnit: '-', withSi: false })} ${currency} (${percentage.toFixed(2)}%)`;

return {
colors: isOwn ? COLORS_MINE : COLORS_OTHER,
label,
tooltip,
value: percentage
};
});
}

function extractEraSlash (validatorId: string, slashes: Slash[]): BN {
Expand Down
12 changes: 12 additions & 0 deletions packages/react-components/src/Chart/HorizBar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
// Copyright 2017-2019 @polkadot/react-components authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
Expand All @@ -13,6 +14,7 @@ import { bnToBn, isNumber } from '@polkadot/util';
interface Value {
colors: string[];
label: string;
tooltip?: string;
value: number | BN;
}

Expand All @@ -30,6 +32,10 @@ interface State {
jsonValues?: string;
}

interface TooltipItem {
index: number;
}

interface Config {
labels: string[];
datasets: {
Expand Down Expand Up @@ -76,6 +82,12 @@ function calculateOptions (aspectRatio: number, values: Value[], jsonValues: str
? { beginAtZero: true, max }
: { display: false }
}]
},
tooltips: {
callbacks: {
label: (item: TooltipItem, _: any): string =>
values[item.index].tooltip || values[item.index].label
}
}
},
jsonValues
Expand Down