Import session keys for author_rotateKeys (#1484)

* Session keys input

* Impoirt session keys for author_rotateKeys

* Bump API

* Defaults
This commit is contained in:
Jaco Greeff 2019-08-08 16:16:57 +02:00 committed by GitHub
parent 933af283ec
commit 87351fdd1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 233 additions and 130 deletions

View File

@ -10,10 +10,10 @@
"packages/*"
],
"resolutions": {
"@polkadot/api": "^0.90.0-beta.30",
"@polkadot/api-contract": "^0.90.0-beta.30",
"@polkadot/api": "^0.90.0-beta.31",
"@polkadot/api-contract": "^0.90.0-beta.31",
"@polkadot/keyring": "^1.0.1",
"@polkadot/types": "^0.90.0-beta.30",
"@polkadot/types": "^0.90.0-beta.31",
"@polkadot/util": "^1.0.1",
"@polkadot/util-crypto": "^1.0.1",
"@types/styled-components": "4.1.8",

View File

@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.5",
"@polkadot/api-contract": "^0.90.0-beta.30",
"@polkadot/api-contract": "^0.90.0-beta.31",
"@polkadot/ui-app": "^0.34.0-beta.111"
}
}

View File

@ -12,7 +12,7 @@ import translate from '../../translate';
interface Props extends I18nProps {
controllerId: string;
onError: (error: string | null) => void;
sessionId: string;
sessionId: string | null;
stashId: string;
}

View File

@ -6,7 +6,7 @@ import { ApiProps } from '@polkadot/ui-api/types';
import { I18nProps } from '@polkadot/ui-app/types';
import React from 'react';
import { Button, InputAddress, Modal, TxButton } from '@polkadot/ui-app';
import { Button, InputAddress, Input, Modal, TxButton } from '@polkadot/ui-app';
import { withApi, withMulti } from '@polkadot/ui-api';
import ValidationSessionKey from './InputValidationSessionKey';
@ -21,13 +21,10 @@ type Props = I18nProps & ApiProps & {
};
interface State {
babe: string;
babeError: string | null;
// TODO rename grandpa
ed25519: string;
// TODO remove once we drop v1 support
ed25519: string | null;
ed25519Error: string | null;
imOnline: string;
imOnlineError: string | null;
keys: string | null;
}
class SetSessionKey extends React.PureComponent<Props, State> {
@ -37,24 +34,23 @@ class SetSessionKey extends React.PureComponent<Props, State> {
super(props);
this.state = {
babe: props.sessionIds[1] || props.controllerId,
babeError: null,
ed25519: props.sessionIds[0] || props.controllerId,
ed25519Error: null,
imOnline: props.sessionIds[2] || props.controllerId,
imOnlineError: null
keys: null
};
}
public render (): React.ReactNode {
const { controllerId, isOpen, isSubstrateV2, onClose, t } = this.props;
const { ed25519, ed25519Error, babe, babeError, imOnline, imOnlineError } = this.state;
const { ed25519, ed25519Error, keys } = this.state;
if (!isOpen) {
return null;
}
const hasError = !ed25519 || !!ed25519Error || (isSubstrateV2 ? ((!babe || !!babeError) && (!imOnline || !!imOnlineError)) : false);
const hasError = isSubstrateV2
? !keys
: (!ed25519 || !!ed25519Error);
return (
<Modal
@ -80,7 +76,7 @@ class SetSessionKey extends React.PureComponent<Props, State> {
onClick={onClose}
params={
isSubstrateV2
? [{ babe, grandpa: ed25519, imOnline }, new Uint8Array([])]
? [keys, new Uint8Array([])]
: [ed25519]
}
tx={
@ -96,8 +92,7 @@ class SetSessionKey extends React.PureComponent<Props, State> {
}
private renderContent (): React.ReactNode {
const { controllerId, isSubstrateV2, stashId, t } = this.props;
const { ed25519, imOnline, babe } = this.state;
const { controllerId, isSubstrateV2, t } = this.props;
return (
<>
@ -111,86 +106,67 @@ class SetSessionKey extends React.PureComponent<Props, State> {
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, it must be an ed25519 key.')}
label={
isSubstrateV2
? t('Grandpa key')
: t('Session key (ed25519)')
}
onChange={this.onChangeEd25519}
value={ed25519}
/>
<ValidationSessionKey
controllerId={controllerId}
onError={this.onSessionErrorEd25519}
sessionId={ed25519}
stashId={stashId}
/>
{
isSubstrateV2
? (
<>
<InputAddress
className='medium'
help={t('Changing the key only takes effect at the start of the next session. If validating, it must be an sr25519 key.')}
label={t('Babe key')}
onChange={this.onChangeBabe}
value={babe}
/>
<ValidationSessionKey
controllerId={controllerId}
onError={this.onSessionErrorBabe}
sessionId={babe}
stashId={stashId}
/>
<InputAddress
className='medium'
help={t('Changing the key only takes effect at the start of the next session.')}
label={t('ImOnline key')}
onChange={this.onChangeImOnline}
value={imOnline}
/>
<ValidationSessionKey
controllerId={controllerId}
onError={this.onSessionErrorImOnline}
sessionId={imOnline}
stashId={stashId}
/>
</>
)
: null
? this.renderV2Keys()
: this.renderV1Keys()
}
</Modal.Content>
</>
);
}
private onChangeBabe = (babe: string): void => {
this.setState({ babe });
private renderV1Keys (): React.ReactNode {
const { controllerId, stashId, t } = this.props;
const { ed25519 } = this.state;
return (
<>
<InputAddress
className='medium'
help={t('Changing the key only takes effect at the start of the next session. If validating, it must be an ed25519 key.')}
label={t('Session key (ed25519)')}
onChange={this.onChangeEd25519}
value={ed25519}
/>
<ValidationSessionKey
controllerId={controllerId}
onError={this.onSessionErrorEd25519}
sessionId={ed25519}
stashId={stashId}
/>
</>
);
}
private onChangeEd25519 = (ed25519: string): void => {
private renderV2Keys (): React.ReactNode {
const { t } = this.props;
const { keys } = this.state;
return (
<>
<Input
className='medium'
help={t('Changing the key only takes effect at the start of the next session. The input here is generates from the author_rotateKeys command')}
isError={!keys}
label={t('Keys from rotateKeys')}
onChange={this.onChangeKeys}
/>
</>
);
}
private onChangeEd25519 = (ed25519: string | null): void => {
this.setState({ ed25519 });
}
private onChangeImOnline = (imOnline: string): void => {
this.setState({ imOnline });
}
private onSessionErrorBabe = (babeError: string | null): void => {
this.setState({ babeError });
private onChangeKeys = (keys: string): void => {
this.setState({ keys: keys || null });
}
private onSessionErrorEd25519 = (ed25519Error: string | null): void => {
this.setState({ ed25519Error });
}
private onSessionErrorImOnline = (imOnlineError: string | null): void => {
this.setState({ imOnlineError });
}
}
export default withMulti(

View File

@ -31,7 +31,7 @@
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme",
"dependencies": {
"@babel/runtime": "^7.5.5",
"@polkadot/api": "^0.90.0-beta.30",
"@polkadot/api": "^0.90.0-beta.31",
"@polkadot/extension-dapp": "^0.6.1",
"rxjs-compat": "^6.4.0"
}

View File

@ -0,0 +1,73 @@
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { BareProps } from './types';
import React from 'react';
import styled from 'styled-components';
import addressToAddress from './util/toAddress';
import IdentityIcon from './IdentityIcon';
import Input from './Input';
interface Props extends BareProps {
help?: React.ReactNode;
label?: React.ReactNode;
onChange?: (address: string | null) => void;
}
interface State {
address: string | null;
isError: boolean;
}
class InputAddressSimple extends React.PureComponent<Props, State> {
public state: State = {
address: null,
isError: true
};
public render (): React.ReactNode {
const { className, help, label } = this.props;
const { address, isError } = this.state;
return (
<div className={className}>
<Input
help={help}
isError={isError}
label={label}
onChange={this.onChange}
/>
<IdentityIcon
className='ui--InputAddressSimpleIcon'
size={32}
value={address}
/>
</div>
);
}
private onChange = (_address: string): void => {
const { onChange } = this.props;
const address = addressToAddress(_address) || null;
this.setState({ address, isError: !address }, (): void => {
onChange && onChange(address);
});
}
}
export default styled(InputAddressSimple)`
position: relative;
.ui--InputAddressSimpleIcon {
background: #eee;
border: 1px solid #888;
border-radius: 50%;
left: 0.75rem;
position: absolute;
top: 1rem;
}
`;

View File

@ -34,6 +34,7 @@ export { default as IdentityIcon } from './IdentityIcon';
export { default as InfoForInput } from './InfoForInput';
export { default as Input } from './Input';
export { default as InputAddress } from './InputAddress';
export { default as InputAddressSimple } from './InputAddressSimple';
export { default as InputBalance } from './InputBalance';
export { default as InputBalanceBonded } from './InputBalanceBonded';
export { default as InputConsts } from './InputConsts';

View File

@ -0,0 +1,47 @@
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Props } from '../types';
import React from 'react';
import { Input } from '@polkadot/ui-app';
import Bare from './Bare';
export default class Data extends React.PureComponent<Props> {
public render (): React.ReactNode {
const { className, defaultValue: { value }, isDisabled, isError, label, onEnter, style, withLabel } = this.props;
const defaultValue = value || '';
return (
<Bare
className={className}
style={style}
>
<Input
className='full'
defaultValue={defaultValue}
isDisabled={isDisabled}
isError={isError}
label={label}
onChange={this.onChange}
onEnter={onEnter}
placeholder='Hex data'
type='text'
withLabel={withLabel}
/>
</Bare>
);
}
private onChange = (value: string): void => {
const { onChange } = this.props;
const isValid = value.length !== 0;
onChange && onChange({
isValid,
value
});
}
}

View File

@ -14,6 +14,7 @@ import Balance from './Balance';
import Bool from './Bool';
import Bytes from './Bytes';
import Code from './Code';
import Data from './Data';
import Enum from './Enum';
import Hash from './Hash';
import Moment from './Moment';
@ -41,6 +42,7 @@ const components: ComponentMap = ([
{ c: Bool, t: ['bool'] },
{ c: Bytes, t: ['Bytes'] },
{ c: Code, t: ['Code'] },
{ c: Data, t: ['Data', 'Keys'] },
{ c: Enum, t: ['Enum'] },
{ c: Hash, t: ['CodeHash', 'Hash', 'SeedOf', 'Signature'] },
{ c: KeyValue, t: ['KeyValue'] },

View File

@ -75,6 +75,10 @@ export default function getInitValue (def: TypeDef): RawParamValue | RawParamVal
case 'Hash':
return createType('Hash');
case 'Data':
case 'Keys':
return '';
case 'AccountId':
case 'AccountIdOf':
case 'Address':
@ -112,7 +116,7 @@ export default function getInitValue (def: TypeDef): RawParamValue | RawParamVal
}
console.error(`Unable to determine default type for ${JSON.stringify(def)}`);
return void 0;
return '0x';
}
}
}

View File

@ -1931,44 +1931,44 @@
universal-user-agent "^3.0.0"
url-template "^2.0.8"
"@polkadot/api-contract@^0.90.0-beta.30":
version "0.90.0-beta.30"
resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.90.0-beta.30.tgz#bba855f02d9a77651a0d934224365bc4026a47d6"
integrity sha512-lV3UCNMJuJNoRq3EmFfJd6fxeQkv6Ywi6SgvwWmBuxAuTGOyarc0M2uMsaCXAaRhQiynhKXKeiHdNTkLgvRFwQ==
"@polkadot/api-contract@^0.90.0-beta.31":
version "0.90.0-beta.31"
resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.90.0-beta.31.tgz#b484e7ac1e36b45e5769ee7dc1b32b88f4e6abb8"
integrity sha512-aXunLiPX53lD7FJGnaybBv1jtZFsYAOLfL9rVoZnKX3ye5uKaPMmZ7NvdrTWXLJsyv2XyrMnqiKPITUrNIo0PQ==
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/types" "^0.90.0-beta.30"
"@polkadot/types" "^0.90.0-beta.31"
"@polkadot/api-derive@^0.90.0-beta.30":
version "0.90.0-beta.30"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.90.0-beta.30.tgz#0f1658d58698c779da535c9e970e7ef70a0f3811"
integrity sha512-Ji0q15F3E5b2LnA6nW58KAYkvq34CGCYXayT8pAm1f6the/3qCrT8rh7XXY4adqzs/Lyk8ICaEWJxtDfT/e5qA==
"@polkadot/api-derive@^0.90.0-beta.31":
version "0.90.0-beta.31"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.90.0-beta.31.tgz#5457db993429ae40e283e425c1b670fe811b658d"
integrity sha512-Eo/j88GE4EY/IKUjXVFJo1nIGjUY9HSEmD8lVqRK24ZTwaNuRB6ToPlCW0HbBPz8qNFrX7iGBXF0sGP3Ih01AA==
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/api" "^0.90.0-beta.30"
"@polkadot/types" "^0.90.0-beta.30"
"@polkadot/api" "^0.90.0-beta.31"
"@polkadot/types" "^0.90.0-beta.31"
"@polkadot/api-metadata@^0.90.0-beta.30":
version "0.90.0-beta.30"
resolved "https://registry.yarnpkg.com/@polkadot/api-metadata/-/api-metadata-0.90.0-beta.30.tgz#2f38b955d6091b83b5bcad16a9f12df267f4558e"
integrity sha512-9uhdWOIKp80t60DAeEkqbEZoP82ZOr9kuk/4xLKccD76aNr0G9ywnHIDJVazXVITFU4uQx0ptHjfHaXR8RkGWA==
"@polkadot/api-metadata@^0.90.0-beta.31":
version "0.90.0-beta.31"
resolved "https://registry.yarnpkg.com/@polkadot/api-metadata/-/api-metadata-0.90.0-beta.31.tgz#dfb70a3af5375a2a5a9649496a5388c59121b8ed"
integrity sha512-mKkz7e1fBEBbZeZiCWJj4OzDvbKbCsqtsMsY8j5oMNP+5RD4O29pXYp9T52pFJkJPrGmKp41MEF0GpyAzLci2A==
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/types" "^0.90.0-beta.30"
"@polkadot/types" "^0.90.0-beta.31"
"@polkadot/util" "^1.0.1"
"@polkadot/util-crypto" "^1.0.1"
"@polkadot/api@^0.90.0-beta.30":
version "0.90.0-beta.30"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.90.0-beta.30.tgz#9fd1f3f8646cc696e21a1b5dde2002c0b6bd1c36"
integrity sha512-Ysut9XmZJ+Qiftvakgi38oMgKeBE1+GENz2JWDQ2NcMR4JTKbSTKdXy0I1PZv6SFVnHMG698cBRYoqYeu+hI+w==
"@polkadot/api@^0.90.0-beta.31":
version "0.90.0-beta.31"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.90.0-beta.31.tgz#cacdcee528e0d12ee76545defe64c6e4b155414b"
integrity sha512-e+0kV5h3aRW7npd2NbZxYHac2Zp9V0+CPHiWjJFgWjPTxY4M7GOBth5BVqwp7dXC2re7T6Q2w8CqOpIV271yFw==
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/api-derive" "^0.90.0-beta.30"
"@polkadot/api-metadata" "^0.90.0-beta.30"
"@polkadot/rpc-core" "^0.90.0-beta.30"
"@polkadot/rpc-provider" "^0.90.0-beta.30"
"@polkadot/types" "^0.90.0-beta.30"
"@polkadot/api-derive" "^0.90.0-beta.31"
"@polkadot/api-metadata" "^0.90.0-beta.31"
"@polkadot/rpc-core" "^0.90.0-beta.31"
"@polkadot/rpc-provider" "^0.90.0-beta.31"
"@polkadot/types" "^0.90.0-beta.31"
"@polkadot/util-crypto" "^1.0.1"
"@polkadot/dev-react@^0.30.0-beta.26":
@ -2071,10 +2071,10 @@
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/jsonrpc@^0.90.0-beta.30":
version "0.90.0-beta.30"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.90.0-beta.30.tgz#39e185e5d75e76ba929e836e0fc8d79c9ff71b41"
integrity sha512-8VP+XvlFgzf8q7ybWwFopOpMql+iQgwUsjYh7PBFlA7PArl2Remjm12TZsDIDhO5Yz+o9bPBP1D66PH3xwDC2w==
"@polkadot/jsonrpc@^0.90.0-beta.31":
version "0.90.0-beta.31"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.90.0-beta.31.tgz#f617c24ff545c7339d31389e69378d53cce9281b"
integrity sha512-9PiMoARAXyjZPcNHY2rMQqL5jaUQBPZtQYIDQn+mQphkjd2PntruWe6u8kGP39FV3cOgc+ketgl01U8i9Sr6sQ==
dependencies:
"@babel/runtime" "^7.5.5"
@ -2102,25 +2102,25 @@
react-copy-to-clipboard "^5.0.1"
styled-components "^4.3.1"
"@polkadot/rpc-core@^0.90.0-beta.30":
version "0.90.0-beta.30"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.90.0-beta.30.tgz#6c17fd8158d65e689d41d8f46048ccfd2b6d3bdb"
integrity sha512-o2hV0q5js0VgtcT4f9yZ72QZ+lyrNxQVpCdJrZb7dmDTv5ulZyhPUqmJCx2k7DShRXLVszTQQTtYLIva6vg67w==
"@polkadot/rpc-core@^0.90.0-beta.31":
version "0.90.0-beta.31"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.90.0-beta.31.tgz#786a99911df567f65b8de146bc89ba94274abfc3"
integrity sha512-P6RQSKnVB42w4BstS/JMnOvjpDmmb6v7yALCJE6brp5lhy0y7Is14s2ZUXkD8dCQyf+RiHm8J8hud8UIJy9uwQ==
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/jsonrpc" "^0.90.0-beta.30"
"@polkadot/rpc-provider" "^0.90.0-beta.30"
"@polkadot/types" "^0.90.0-beta.30"
"@polkadot/jsonrpc" "^0.90.0-beta.31"
"@polkadot/rpc-provider" "^0.90.0-beta.31"
"@polkadot/types" "^0.90.0-beta.31"
"@polkadot/util" "^1.0.1"
rxjs "^6.5.2"
"@polkadot/rpc-provider@^0.90.0-beta.30":
version "0.90.0-beta.30"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.90.0-beta.30.tgz#1bfce4e43100255cefa496f74c6a7221ce49df40"
integrity sha512-CiUUo/9XtlR9P5+9habwFexfssJN1xyJ1Hr+IZ+kS9B6aLiwOOTvlUNjyp99iksDpTQEYUrCj6lBnsYge/P1bg==
"@polkadot/rpc-provider@^0.90.0-beta.31":
version "0.90.0-beta.31"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.90.0-beta.31.tgz#04d543e1fe3840275e8eba1247f5ef3ed76d74d7"
integrity sha512-lv/7aK9VQLdTBX6/WJaeTGuhvK9N1CnMyXBDTrqgzokW2j9tewLIAyNiuWO34pr+sb4zdJp22dHZ+1Fp5K//Zg==
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/api-metadata" "^0.90.0-beta.30"
"@polkadot/api-metadata" "^0.90.0-beta.31"
"@polkadot/util" "^1.0.1"
"@polkadot/util-crypto" "^1.0.1"
"@types/nock" "^10.0.3"
@ -2135,10 +2135,10 @@
dependencies:
"@types/chrome" "^0.0.86"
"@polkadot/types@^0.90.0-beta.30":
version "0.90.0-beta.30"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.90.0-beta.30.tgz#7d619dcaf45fd2d3a8f6081dc97f06901f33f91c"
integrity sha512-SzkfCmi8gZSfSRU8tIyvl80XE7cxOUdWUiJMZS4LmI8pAELSaCjdhaBcfjUcYuzpbtsS8PfTVf1RPvALTs4rUQ==
"@polkadot/types@^0.90.0-beta.31":
version "0.90.0-beta.31"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.90.0-beta.31.tgz#54d43c1615705b92c02ad399b0b357130654d7db"
integrity sha512-/OvEfl+5eC40lfZsTsV5ssWigU0Nmu0PyOselt/XZ9eyyblV6I3mdJ/ws+pBl2o+IBnFXHwEwiZV3b0ueM8a3g==
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/util" "^1.0.1"