From a878d0ca99563ae1d1b09466be3beda71b835f92 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sun, 7 Apr 2019 12:14:03 +0200 Subject: [PATCH] Highlight validator stashes --- packages/app-staking/src/Overview/Address.tsx | 2 +- packages/ui-app/src/AddressMini.tsx | 15 +----- packages/ui-app/src/AddressSummary.tsx | 11 ++--- packages/ui-app/src/IdentityIcon.tsx | 47 ++++++++++++++----- 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/packages/app-staking/src/Overview/Address.tsx b/packages/app-staking/src/Overview/Address.tsx index 47471911bf..6d94d0d33b 100644 --- a/packages/app-staking/src/Overview/Address.tsx +++ b/packages/app-staking/src/Overview/Address.tsx @@ -92,7 +92,7 @@ class Address extends React.PureComponent { : keyring.getAddress(stashId); return pair.isValid() - ? pair.getMeta().name + ? (pair.getMeta().name || defaultName) : defaultName; } diff --git a/packages/ui-app/src/AddressMini.tsx b/packages/ui-app/src/AddressMini.tsx index d7a5f9ab7a..3e2db6c576 100644 --- a/packages/ui-app/src/AddressMini.tsx +++ b/packages/ui-app/src/AddressMini.tsx @@ -7,7 +7,6 @@ import { BareProps } from './types'; import BN from 'bn.js'; import React from 'react'; import { AccountId, AccountIndex, Address, Balance } from '@polkadot/types'; -import { withCall, withMulti } from '@polkadot/ui-api'; import { classes, toShortAddress } from './util'; import BalanceDisplay from './Balance'; @@ -18,24 +17,20 @@ type Props = BareProps & { children?: React.ReactNode, isPadded?: boolean, isShort?: boolean, - session_validators?: Array, value?: AccountId | AccountIndex | Address | string, withAddress?: boolean, withBalance?: boolean }; -class AddressMini extends React.PureComponent { +export default class AddressMini extends React.PureComponent { render () { - const { children, className, isPadded = true, session_validators, style, value } = this.props; + const { children, className, isPadded = true, style, value } = this.props; if (!value) { return null; } const address = value.toString(); - const isValidator = (session_validators || []).find((validator) => - validator.toString() === address - ); return (
{ >
@@ -84,8 +78,3 @@ class AddressMini extends React.PureComponent { ); } } - -export default withMulti( - AddressMini, - withCall('query.session.validators') -); diff --git a/packages/ui-app/src/AddressSummary.tsx b/packages/ui-app/src/AddressSummary.tsx index a12f0fe7f7..256810ab7d 100644 --- a/packages/ui-app/src/AddressSummary.tsx +++ b/packages/ui-app/src/AddressSummary.tsx @@ -149,7 +149,7 @@ class AddressSummary extends React.PureComponent { } protected renderIcon (className: string = 'ui--AddressSummary-icon', size?: number) { - const { accounts_idAndIndex = [], identIconSize = 96, session_validators, value, withIcon = true } = this.props; + const { accounts_idAndIndex = [], identIconSize = 96, value, withIcon = true } = this.props; if (!withIcon) { return null; @@ -157,16 +157,12 @@ class AddressSummary extends React.PureComponent { const [_accountId] = accounts_idAndIndex; const accountId = (_accountId || value || '').toString(); - const isValidator = (session_validators || []).find((validator) => - validator.toString() === accountId - ); return ( ); } @@ -212,7 +208,6 @@ export { export default translate( withCalls( - ['derive.accounts.idAndIndex', { paramName: 'value' }], - 'query.session.validators' + ['derive.accounts.idAndIndex', { paramName: 'value' }] )(AddressSummary) ); diff --git a/packages/ui-app/src/IdentityIcon.tsx b/packages/ui-app/src/IdentityIcon.tsx index 0c6cb8c862..187f2435b1 100644 --- a/packages/ui-app/src/IdentityIcon.tsx +++ b/packages/ui-app/src/IdentityIcon.tsx @@ -8,8 +8,8 @@ import { QueueProps, QueueAction$Add } from './Status/types'; import { I18nProps } from './types'; import React from 'react'; -import { AccountId } from '@polkadot/types'; -import { withCall } from '@polkadot/ui-api/with'; +import { AccountId, Option } from '@polkadot/types'; +import { withCalls } from '@polkadot/ui-api/with'; import BaseIdentityIcon from '@polkadot/ui-identicon'; import { QueueConsumer } from './Status/Context'; @@ -20,7 +20,14 @@ type CopyProps = IdentityProps & I18nProps & { }; type IconProps = ApiProps & IdentityProps & { - session_validators?: Array + session_validators?: Array, + staking_bonded?: Option +}; + +type Props = IconProps & IdentityProps; + +type State = { + isValidator: boolean }; class CopyIcon extends React.PureComponent { @@ -53,20 +60,35 @@ class CopyIcon extends React.PureComponent { const CopyIconI18N = translate(CopyIcon); -class IdentityIcon extends React.PureComponent { - render () { - const { session_validators = [], value } = this.props; +class IdentityIcon extends React.PureComponent { + state: State = { + isValidator: false + }; - const address = (value || '').toString(); - const isValidator = (session_validators || []).find((validator) => - validator.toString() === address + static getDerivedStateFromProps ({ session_validators = [], staking_bonded, value }: Props, prevState: State): State | null { + const address = value + ? value.toString() + : null; + const bonded = staking_bonded && staking_bonded.isSome + ? staking_bonded.unwrap().toString() + : null; + const isValidator = !!session_validators.find((validator) => + [address, bonded].includes(validator.toString()) ); + return prevState.isValidator !== isValidator + ? { isValidator } + : null; + } + + render () { + const { isValidator } = this.state; + return ( {({ queueAction }: QueueProps) => @@ -76,4 +98,7 @@ class IdentityIcon extends React.PureComponent { } } -export default withCall('query.session.validators')(IdentityIcon); +export default withCalls( + 'query.session.validators', + ['query.staking.bonded', { paramName: 'value' }] +)(IdentityIcon);