Render session hex (#1497)

* Render session hex

* session keys as part of AddressInfo

* fix: 48 bits and remove from the overview

* fix validator prefs and sessionsId.length

* fix #1500 and put block number in for V2
This commit is contained in:
Jaco Greeff 2019-08-14 07:37:48 +02:00 committed by GitHub
parent dc02e34279
commit 0946e0e678
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 24 deletions

View File

@ -24,6 +24,7 @@ import SetSessionAccount from './SetSessionAccount';
import translate from '../../translate';
import Unbond from './Unbond';
import Validate from './Validate';
import { u8aToHex, u8aConcat } from '@polkadot/util';
type Props = ApiProps & I18nProps & {
accountId: string;
@ -38,6 +39,7 @@ type Props = ApiProps & I18nProps & {
interface State {
controllerId: string | null;
destination: number;
hexSessionId: string | null;
isBondExtraOpen: boolean;
isNominateOpen: boolean;
isSetControllerAccountOpen: boolean;
@ -66,6 +68,7 @@ class Account extends React.PureComponent<Props, State> {
public state: State = {
controllerId: null,
destination: 0,
hexSessionId: null,
isBondExtraOpen: false,
isNominateOpen: false,
isSetControllerAccountOpen: false,
@ -93,6 +96,11 @@ class Account extends React.PureComponent<Props, State> {
return {
controllerId: toIdString(controllerId),
destination: rewardDestination && rewardDestination.toNumber(),
hexSessionId: u8aToHex(u8aConcat(...(
nextSessionIds.length
? nextSessionIds
: sessionIds
).map((id): Uint8Array => id.toU8a())), 48),
isStashNominating,
isStashValidating,
nominees: nominators && nominators.map(toIdString),
@ -109,7 +117,7 @@ class Account extends React.PureComponent<Props, State> {
}
public render (): React.ReactNode {
const { className, t } = this.props;
const { className, isSubstrateV2, t } = this.props;
const { stashId } = this.state;
if (!stashId) {
@ -147,7 +155,7 @@ class Account extends React.PureComponent<Props, State> {
<div className={className}>
<div className='staking--Accounts'>
{this.renderControllerAccount()}
{this.renderSessionAccount()}
{!isSubstrateV2 && this.renderSessionAccount()}
</div>
<div className='staking--Infos'>
<div className='staking--balances'>
@ -187,7 +195,8 @@ class Account extends React.PureComponent<Props, State> {
}
private renderInfos (): React.ReactNode {
const { stashId } = this.state;
const { isSubstrateV2 } = this.props;
const { hexSessionId, isStashValidating, stashId } = this.state;
return (
<AddressInfo
@ -200,7 +209,8 @@ class Account extends React.PureComponent<Props, State> {
unlocking: true
}}
withRewardDestination
withValidatorPrefs
withHexSessionId={ isSubstrateV2 && hexSessionId !== '0x' && hexSessionId}
withValidatorPrefs={isStashValidating}
/>
);
}
@ -334,8 +344,8 @@ class Account extends React.PureComponent<Props, State> {
}
private renderButtons (): React.ReactNode {
const { t } = this.props;
const { controllerId, isSettingPopupOpen, isStashNominating, isStashValidating, sessionIds } = this.state;
const { isSubstrateV2, t } = this.props;
const { controllerId, hexSessionId, isSettingPopupOpen, isStashNominating, isStashValidating, sessionIds } = this.state;
const buttons = [];
// if we are validating/nominating show stop
@ -354,7 +364,7 @@ class Account extends React.PureComponent<Props, State> {
/>
);
} else {
if (!sessionIds.length) {
if (!sessionIds.length || (isSubstrateV2 && hexSessionId === '0x')) {
buttons.push(
<Button
isPrimary
@ -413,8 +423,8 @@ class Account extends React.PureComponent<Props, State> {
}
private renderPopupMenu (): React.ReactNode {
const { balances_all, t } = this.props;
const { isStashNominating, isStashValidating, sessionIds } = this.state;
const { balances_all, isSubstrateV2, t } = this.props;
const { hexSessionId, isStashNominating, isStashValidating, sessionIds } = this.state;
// only show a "Bond Additional" button if this stash account actually doesn't bond everything already
// staking_ledger.total gives the total amount that can be slashed (any active amount + what is being unlocked)
@ -445,9 +455,9 @@ class Account extends React.PureComponent<Props, State> {
{t('Change validator preferences')}
</Menu.Item>
}
{sessionIds.length &&
{(!!sessionIds.length || (isSubstrateV2 && hexSessionId !== '0x')) &&
<Menu.Item onClick={this.toggleSetSessionAccount}>
{t('Change session account')}
{isSubstrateV2 ? t('Change session keys') : t('Change session account')}
</Menu.Item>
}
{isStashNominating &&

View File

@ -5,6 +5,7 @@
import { AccountId, Balance, Exposure } from '@polkadot/types/interfaces';
import { DerivedBalancesMap, DerivedStaking } from '@polkadot/api-derive/types';
import { ApiProps } from '@polkadot/react-api/types';
import { I18nProps } from '@polkadot/react-components/types';
import { ValidatorFilter, RecentlyOfflineMap } from '../types';
@ -12,12 +13,13 @@ import React from 'react';
import styled from 'styled-components';
import { withCalls, withMulti } from '@polkadot/react-api/with';
import { AddressCard, AddressMini, RecentlyOffline } from '@polkadot/react-components';
import { classes } from '@polkadot/react-components/util';
import keyring from '@polkadot/ui-keyring';
import { formatBalance } from '@polkadot/util';
import translate from '../translate';
interface Props extends I18nProps {
interface Props extends ApiProps, I18nProps {
address: string;
balances: DerivedBalancesMap;
className?: string;
@ -107,31 +109,26 @@ class Address extends React.PureComponent<Props, State> {
}
private renderKeys (): React.ReactNode {
const { address, lastAuthor, lastBlock, t } = this.props;
const { address, isSubstrateV2, lastAuthor, lastBlock, t } = this.props;
const { controllerId, sessionId, stashId } = this.state;
const isSame = controllerId === sessionId;
const isAuthor = [address, controllerId, stashId].includes(lastAuthor);
return (
<div className='staking--Address-info'>
{isAuthor && stashId
? <div className='blockNumber'>#{lastBlock}</div>
? <div className={classes(isSubstrateV2 ? 'blockNumberV2' : 'blockNumberV1')}>#{lastBlock}</div>
: null
}
{controllerId
? (
<div>
<label className='staking--label'>{
isSame
? t('controller/session')
: t('controller')
}</label>
<label className={classes('staking--label', isSubstrateV2 && !isAuthor && 'controllerSpacer')}>{t('controller')}</label>
<AddressMini value={controllerId} />
</div>
)
: null
}
{!isSame && sessionId
{!isSubstrateV2 && sessionId
? (
<div>
<label className='staking--label'>{t('session')}</label>
@ -229,7 +226,20 @@ class Address extends React.PureComponent<Props, State> {
export default withMulti(
styled(Address as React.ComponentClass<Props>)`
.blockNumber {
.blockNumberV2 {
background: #3f3f3f;
border-radius: 0.25rem;
box-shadow: 0 3px 3px rgba(0,0,0,.2);
color: #eee;
font-size: 1.5rem;
font-weight: 100;
line-height: 1.5rem;
margin-bottom: 1rem;
padding: 0.25rem 0.5rem;
z-index: 1;
}
.blockNumberV1 {
background: #3f3f3f;
border-radius: 0.25rem;
top: 0rem;
@ -244,6 +254,10 @@ export default withMulti(
vertical-align: middle;
z-index: 1;
}
.staking--label.controllerSpacer {
margin-top:3rem;
}
`,
translate,
withCalls<Props>(

View File

@ -42,8 +42,9 @@ type Props = BareProps & I18nProps & {
children?: React.ReactNode;
staking_info?: DerivedStaking;
withBalance?: boolean | BalanceActiveType;
withRewardDestination?: boolean;
withExtended?: boolean | CryptoActiveType;
withHexSessionId: string | null;
withRewardDestination?: boolean;
withValidatorPrefs?: boolean | ValidatorPrefsType;
};
@ -55,6 +56,7 @@ class AddressInfo extends React.PureComponent<Props> {
<div className={className}>
<div className='column'>
{this.renderBalances()}
{this.renderHexSessionId()}
{this.renderValidatorPrefs()}
{this.renderRewardDestination()}
</div>
@ -173,6 +175,21 @@ class AddressInfo extends React.PureComponent<Props> {
);
}
private renderHexSessionId (): React.ReactNode {
const { t, withHexSessionId = null } = this.props;
if (!withHexSessionId) {
return null;
}
return (
<>
<Label label={t('session keys')} />
<div className='result'>{withHexSessionId}</div>
</>
);
}
private renderRewardDestination (): React.ReactNode {
const { staking_info, withRewardDestination, t } = this.props;

View File

@ -79,7 +79,7 @@ export default translate(
.ui--Card,
.ui--CardGrid-spacer {
flex: 1 1;
min-width: 35rem;
min-width: 40rem;
max-width: 71rem;
}