Display session key with stashes (#911)

* Display session key with stashes

* Only display node info when connected
This commit is contained in:
Jaco Greeff 2019-04-07 18:20:02 +02:00 committed by GitHub
parent bb35c6964a
commit ed1e58d9a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 129 additions and 95 deletions

View File

@ -16,11 +16,19 @@ type Props = I18nProps & {
};
type State = {
sessionId?: string
sessionId: string
};
class Key extends React.PureComponent<Props, State> {
state: State = {};
state: State;
constructor (props: Props) {
super(props);
this.state = {
sessionId: props.accountId
};
}
render () {
const { accountId, isOpen, onClose, t } = this.props;
@ -62,15 +70,21 @@ class Key extends React.PureComponent<Props, State> {
}
private renderContent () {
const { t } = this.props;
const { accountId, t } = this.props;
const { sessionId } = this.state;
return (
<>
<Modal.Header>
{t('Key Preferences')}
{t('Session Key')}
</Modal.Header>
<Modal.Content className='ui--signer-Signer-Content'>
<InputAddress
className='medium'
defaultValue={accountId}
isDisabled
label={t('controller account')}
/>
<InputAddress
className='medium'
help={t('Changing the key only takes effect at the start of the next session. If validating, you should (currently) use an ed25519 key.')}

View File

@ -91,8 +91,8 @@ class Account extends React.PureComponent<Props, State> {
<div className='staking--Account-expand'>
{this.renderButtons()}
{this.renderBondedId()}
{this.renderSessionId()}
{this.renderStashId()}
{this.renderSessionId()}
{this.renderNominee()}
{this.renderNominators()}
</div>
@ -173,6 +173,7 @@ class Account extends React.PureComponent<Props, State> {
}
private renderNominee () {
const { t } = this.props;
const nominees = this.getNominees();
if (!nominees || !nominees.length) {
@ -181,7 +182,7 @@ class Account extends React.PureComponent<Props, State> {
return (
<div className='staking--Account-detail'>
<label className='staking--label'>nominating</label>
<label className='staking--label'>{t('nominating')}</label>
{
nominees.map((nomineeId, index) => (
<AddressMini
@ -220,6 +221,7 @@ class Account extends React.PureComponent<Props, State> {
}
private renderBondedId () {
const { t } = this.props;
const { bondedId } = this.state;
if (!bondedId) {
@ -228,16 +230,14 @@ class Account extends React.PureComponent<Props, State> {
return (
<div className='staking--Account-detail'>
<label className='staking--label'>controller account</label>
<AddressMini
value={bondedId}
withBalance
/>
<label className='staking--label'>{t('controller')}</label>
<AddressMini value={bondedId} />
</div>
);
}
private renderSessionId () {
const { t } = this.props;
const { sessionId } = this.state;
if (!sessionId) {
@ -246,16 +246,14 @@ class Account extends React.PureComponent<Props, State> {
return (
<div className='staking--Account-detail'>
<label className='staking--label'>session account</label>
<AddressMini
value={sessionId}
withBalance
/>
<label className='staking--label'>{t('session')}</label>
<AddressMini value={sessionId} />
</div>
);
}
private renderStashId () {
const { t } = this.props;
const { stashId } = this.state;
if (!stashId) {
@ -264,11 +262,8 @@ class Account extends React.PureComponent<Props, State> {
return (
<div className='staking--Account-detail'>
<label className='staking--label'>stash account</label>
<AddressMini
value={stashId}
withBalance
/>
<label className='staking--label'>{t('stash')}</label>
<AddressMini value={stashId} />
</div>
);
}
@ -305,7 +300,7 @@ class Account extends React.PureComponent<Props, State> {
isPrimary
key='bond'
onClick={this.toggleBonding}
label={t('Bond')}
label={t('Bond Funds')}
/>
);
} else {
@ -316,16 +311,7 @@ class Account extends React.PureComponent<Props, State> {
const isNominating = nominees && nominees.length;
const isValidating = intentions.indexOf(accountId) !== -1;
if (!sessionId) {
buttons.push(
<Button
isPrimary
key='session'
onClick={this.toggleSessionKey}
label={t('Set Session Key')}
/>
);
} else if (isValidating || isNominating) {
if (isValidating || isNominating) {
buttons.push(
<TxButton
accountId={accountId}
@ -336,14 +322,25 @@ class Account extends React.PureComponent<Props, State> {
/>
);
} else {
buttons.push(
<Button
isPrimary
key='validate'
onClick={this.toggleValidating}
label={t('Validate')}
/>
);
if (!sessionId) {
buttons.push(
<Button
isPrimary
key='session'
onClick={this.toggleSessionKey}
label={t('Set Session Key')}
/>
);
} else {
buttons.push(
<Button
isPrimary
key='validate'
onClick={this.toggleValidating}
label={t('Validate')}
/>
);
}
buttons.push(<Button.Or key='nominate.or' />);
buttons.push(
<Button

View File

@ -25,54 +25,63 @@ type Props = I18nProps & {
lastBlock: string,
nominators: Nominators,
recentlyOffline: RecentlyOfflineMap,
session_nextKeyFor?: Option<AccountId>,
staking_bonded?: Option<AccountId>,
staking_ledger?: Option<StakingLedger>
};
type State = {
bondedId: string | null,
bondedId: string,
stashId: string | null,
sessionId: string | null,
badgeExpanded: boolean;
};
class Address extends React.PureComponent<Props, State> {
state: State = {
bondedId: null,
stashId: null,
badgeExpanded: false
};
state: State;
static getDerivedStateFromProps ({ address, staking_bonded, staking_ledger }: Props): State | null {
if (!staking_ledger || staking_ledger.isNone || !staking_bonded) {
return null;
}
constructor (props: Props) {
super(props);
this.state = {
bondedId: props.address,
sessionId: null,
stashId: null,
badgeExpanded: false
};
}
static getDerivedStateFromProps ({ address, session_nextKeyFor, staking_bonded, staking_ledger }: Props, prevState: State): State | null {
return {
bondedId: staking_bonded.isNone
? address
bondedId: !staking_bonded || staking_bonded.isNone
? prevState.bondedId
: staking_bonded.unwrap().toString(),
stashId: staking_ledger.unwrap().stash.toString()
sessionId: !session_nextKeyFor || session_nextKeyFor.isNone
? prevState.sessionId
: session_nextKeyFor.unwrap().toString(),
stashId: !staking_ledger || staking_ledger.isNone
? prevState.stashId
: staking_ledger.unwrap().stash.toString()
} as State;
}
render () {
const { balanceArray, isAuthor, lastBlock } = this.props;
const { stashId } = this.state;
if (!stashId) {
return null;
}
const { bondedId, stashId } = this.state;
return (
<article key={stashId}>
<article key={stashId || bondedId}>
<AddressRow
balance={balanceArray(stashId)}
balance={balanceArray(stashId || '')}
name={this.getDisplayName()}
value={stashId}
withCopy={false}
withNonce={false}
>
{this.renderController()}
<div className='staking--accounts-info'>
{this.renderControllerId()}
{this.renderSessionId()}
</div>
{this.renderNominators()}
{this.renderOffline()}
</AddressRow>
@ -109,7 +118,8 @@ class Address extends React.PureComponent<Props, State> {
this.setState({ badgeExpanded: !badgeExpanded });
}
private renderController () {
private renderControllerId () {
const { t } = this.props;
const { bondedId } = this.state;
if (!bondedId) {
@ -117,12 +127,25 @@ class Address extends React.PureComponent<Props, State> {
}
return (
<div className='staking--controller-info'>
<label className='staking--label'>controller account</label>
<AddressMini
value={bondedId}
withBalance
/>
<div>
<label className='staking--label'>{t('controller')}</label>
<AddressMini value={bondedId} />
</div>
);
}
private renderSessionId () {
const { t } = this.props;
const { sessionId } = this.state;
if (!sessionId) {
return null;
}
return (
<div>
<label className='staking--label'>{t('session')}</label>
<AddressMini value={sessionId} />
</div>
);
}
@ -133,10 +156,6 @@ class Address extends React.PureComponent<Props, State> {
nominators[nominator].indexOf(address) !== -1
);
if (!myNominators.length) {
return null;
}
return (
<details className='staking--Account-detail'>
<summary>
@ -167,6 +186,7 @@ class Address extends React.PureComponent<Props, State> {
const offline = recentlyOffline[stashId];
const count = offline.reduce((total, { count }) => total.add(count), new BN(0));
const blockNumbers = offline.map(({ blockNumber }) => `#${formatNumber(blockNumber)}`);
return (
@ -178,10 +198,10 @@ class Address extends React.PureComponent<Props, State> {
{count.toString()}
</div>
<div className='detail'>
{t('Reported offline {{count}} times, at {{blockNumbers}}', {
{t('Reported offline {{count}} times, last at {{blockNumber}}', {
replace: {
count: count.toString(),
blockNumbers: blockNumbers.join(', ')
blockNumber: blockNumbers[blockNumbers.length - 1]
}
})}
</div>
@ -194,6 +214,7 @@ export default withMulti(
Address,
translate,
withCalls<Props>(
['query.session.nextKeyFor', { paramName: 'address' }],
['query.staking.ledger', { paramName: 'address' }],
['query.staking.bonded', { paramName: 'address' }]
)

View File

@ -99,11 +99,11 @@
margin-top: 0.75rem;
.staking--label {
margin-bottom: -0.25rem;
margin-bottom: -0.5rem;
}
}
.staking--controller-info {
.staking--accounts-info {
position: absolute;
top: 0.25rem;
right: 1rem;
@ -111,6 +111,6 @@
text-align: right;
.staking--label {
margin-bottom: -0.25rem;
margin-bottom: -0.5rem;
}
}

View File

@ -97,9 +97,10 @@ export default withMulti(
// These API queries are used in a number of places, warm them up
// to avoid constant un-/re-subscribe on these
withCalls<Props>(
'query.session.validators',
'derive.accounts.indexes',
'derive.balances.fees',
'derive.staking.controllers'
'derive.staking.controllers',
'query.staking.nominators',
'query.session.validators'
)
);

View File

@ -36,28 +36,31 @@ const Wrapper = styled.div`
}
`;
const HEALTH_POLL = 22500;
const pkgJson = require('../../package.json');
class NodeInfo extends React.PureComponent<Props> {
componentDidMount () {
const { api } = this.props;
window.setInterval(() => {
api.rpc.system
.health()
.catch(() => {
// ignore
});
}, HEALTH_POLL);
}
render () {
const { api } = this.props;
const uiInfo = `apps v${pkgJson.version}`;
return (
<Wrapper>
{this.renderNode()}
<div>{api.libraryInfo.replace('@polkadot/', '')}</div>
<div>{uiInfo}</div>
</Wrapper>
);
}
private renderNode () {
const { isApiReady } = this.props;
if (!isApiReady) {
return null;
}
return (
<>
<div>
<Chain />&nbsp;
<BestNumber label='#' />
@ -67,9 +70,7 @@ class NodeInfo extends React.PureComponent<Props> {
<NodeVersion label='v' />
</div>
<div className='spacer' />
<div>{api.libraryInfo.replace('@polkadot/', '')}</div>
<div>{uiInfo}</div>
</Wrapper>
</>
);
}
}