Show session key on controller, before anything (allow selection) (#906)

* Show session key on the controller

* Force session keys on controllers

* Display session

* Padding cleanups
This commit is contained in:
Jaco Greeff 2019-04-07 13:33:14 +02:00 committed by GitHub
parent 2c4a4e6f20
commit f3876d573a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 14 deletions

View File

@ -15,13 +15,16 @@ type Props = I18nProps & {
onClose: () => void
};
type State = {};
type State = {
sessionId?: string
};
class Key extends React.PureComponent<Props, State> {
state: State = {};
render () {
const { accountId, isOpen, onClose, t } = this.props;
const { sessionId } = this.state;
if (!isOpen) {
return null;
@ -45,10 +48,11 @@ class Key extends React.PureComponent<Props, State> {
<Button.Or />
<TxButton
accountId={accountId}
isDisabled={!sessionId}
isPrimary
label={t('Set Session Key')}
onClick={onClose}
params={[accountId]}
params={[sessionId]}
tx='session.setKey'
/>
</Button.Group>
@ -58,7 +62,8 @@ class Key extends React.PureComponent<Props, State> {
}
private renderContent () {
const { accountId, t } = this.props;
const { t } = this.props;
const { sessionId } = this.state;
return (
<>
@ -69,14 +74,19 @@ class Key extends React.PureComponent<Props, State> {
<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.')}
isDisabled
label={t('session key')}
value={accountId}
onChange={this.onChangeSession}
value={sessionId}
type='account'
/>
</Modal.Content>
</>
);
}
private onChangeSession = (sessionId: string) => {
this.setState({ sessionId });
}
}
export default translate(Key);

View File

@ -91,6 +91,7 @@ class Account extends React.PureComponent<Props, State> {
<div className='staking--Account-expand'>
{this.renderButtons()}
{this.renderBondedId()}
{this.renderSessionId()}
{this.renderStashId()}
{this.renderNominee()}
{this.renderNominators()}
@ -236,6 +237,24 @@ class Account extends React.PureComponent<Props, State> {
);
}
private renderSessionId () {
const { sessionId } = this.state;
if (!sessionId) {
return null;
}
return (
<div className='staking--Account-detail'>
<label className='staking--label'>session account</label>
<AddressMini
value={sessionId}
withBalance
/>
</div>
);
}
private renderStashId () {
const { stashId } = this.state;
@ -276,11 +295,11 @@ class Account extends React.PureComponent<Props, State> {
private renderButtons () {
const { accountId, intentions, t } = this.props;
const { sessionId, stashId } = this.state;
const { sessionId, bondedId, stashId } = this.state;
const buttons = [];
if (!stashId) {
if (sessionId) {
if (!bondedId) {
buttons.push(
<Button
isPrimary
@ -290,6 +309,14 @@ class Account extends React.PureComponent<Props, State> {
/>
);
} else {
return null;
}
} else {
const nominees = this.getNominees();
const isNominating = nominees && nominees.length;
const isValidating = intentions.indexOf(accountId) !== -1;
if (!sessionId) {
buttons.push(
<Button
isPrimary
@ -298,13 +325,7 @@ class Account extends React.PureComponent<Props, State> {
label={t('Set Session Key')}
/>
);
}
} else {
const nominees = this.getNominees();
const isNominating = nominees && nominees.length;
const isValidating = intentions.indexOf(accountId) !== -1;
if (isValidating || isNominating) {
} else if (isValidating || isNominating) {
buttons.push(
<TxButton
accountId={accountId}