Add currency indicator to staking charts (#1897)

This commit is contained in:
Jaco Greeff 2019-11-15 22:18:33 +01:00 committed by GitHub
parent 786fcf96bc
commit bffa6589b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 5 deletions

View File

@ -48,7 +48,7 @@ const WITH_VALIDATOR_PREFS = { validatorPayment: true };
function Address ({ address, authorsMap, className, defaultName, filter, hasQueries, isElected, isFavorite, lastAuthors, myAccounts, points, recentlyOnline, t, toggleFavorite, withNominations = true }: Props): React.ReactElement<Props> | null {
const { api, isSubstrateV2 } = useApiContext();
// FIXME Any horrors, caused by trackStream
// FIXME Any horrors, caused by derive type mismatches
const stakingInfo = trackStream<DerivedStaking>(api.derive.staking.info as any, [address]);
const [extraInfo, setExtraInfo] = useState<[React.ReactNode, React.ReactNode][] | undefined>();
const [hasActivity, setHasActivity] = useState(true);

View File

@ -95,6 +95,7 @@ function Validator ({ className, sessionRewards, t, validatorId }: Props): React
});
const [blocksLabels, setBlocksLabels] = useState<string[]>([]);
const [blocksChart, setBlocksChart] = useState<LineData | null>(null);
const [currency] = useState(formatBalance.getDefaults().unit);
const [{ rewardsChart, rewardsLabels }, setRewardsInfo] = useState<{ rewardsChart: LineData | null; rewardsLabels: string[] }>({ rewardsChart: null, rewardsLabels: [] });
const [{ splitChart, splitMax }, setSplitInfo] = useState<{ splitChart: SplitData | null; splitMax: number }>({ splitChart: null, splitMax: 100 });
const [{ stakeChart, stakeLabels }, setStakeInfo] = useState<{ stakeChart: LineData | null; stakeLabels: string[]}>({ stakeChart: null, stakeLabels: [] });
@ -156,7 +157,7 @@ function Validator ({ className, sessionRewards, t, validatorId }: Props): React
const avgSet: number[] = [];
const idxSet: BN[] = [];
blockCounts.reduce((total: BN, value: u32, index: number): BN => {
blockCounts.reduce((total: BN, value, index): BN => {
total = total.add(value);
avgSet.push(total.muln(100).divn(index + 1).toNumber() / 100);
@ -191,7 +192,7 @@ function Validator ({ className, sessionRewards, t, validatorId }: Props): React
<Chart.Line
colors={COLORS_REWARD}
labels={rewardsLabels}
legends={[t('slashed'), t('rewards (est.)'), t('average')]}
legends={[t('{{currency}} slashed', { replace: { currency } }), t('{{currency}} rewards (est.)', { replace: { currency } }), t('{{currency}} average', { replace: { currency } })]}
values={rewardsChart}
/>
</div>
@ -207,7 +208,7 @@ function Validator ({ className, sessionRewards, t, validatorId }: Props): React
<h1>{t('elected stake')}</h1>
<Chart.Line
labels={stakeLabels}
legends={[t('total'), t('own'), t('other')]}
legends={[t('{{currency}} total', { replace: { currency } }), t('{{currency}} own', { replace: { currency } }), t('{{currency}} other', { replace: { currency } })]}
values={stakeChart}
/>
</div>

View File

@ -47,7 +47,7 @@ function extractParams (params: any[], paramMap: (params: any[]) => any): [strin
// - returns a promise with an unsubscription
// - has a callback to set the value
// FIXME The typings here need some serious TLC
export default function trackStream <T> (fn: TrackFn<T> | undefined, params: any, { paramMap = transformIdentity, transform = transformIdentity }: Options<T> = {}): T | undefined {
export default function trackStream <T> (fn: TrackFn<any> | undefined, params: any, { paramMap = transformIdentity, transform = transformIdentity }: Options<T> = {}): T | undefined {
const [value, setValue] = useState<T | undefined>();
const tracker = useRef<{ serialized: string | null; subscriber: Promise<Unsub> }>({ serialized: null, subscriber: dummySubscribe });