From 1bea7eb2fd298a7884db174ece9c03ebfeea69ae Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 27 Mar 2019 10:59:01 +0100 Subject: [PATCH] Be explicit in setting session keys, rework controlling (#852) * Be explicit in keys * Bump API --- package.json | 10 +- packages/app-staking/src/Account/Bonding.tsx | 22 ++- .../{Controller.tsx => SessionKey.tsx} | 39 +---- packages/app-staking/src/Account/index.tsx | 77 +++++---- packages/ui-api/package.json | 2 +- yarn.lock | 156 +++++++++--------- 6 files changed, 146 insertions(+), 160 deletions(-) rename packages/app-staking/src/Account/{Controller.tsx => SessionKey.tsx} (60%) diff --git a/package.json b/package.json index 28ca5355c1..7c2c5b1cab 100644 --- a/package.json +++ b/package.json @@ -10,11 +10,11 @@ "packages/*" ], "resolutions": { - "@polkadot/api": "^0.51.1", - "@polkadot/keyring": "^0.42.0-beta.0", - "@polkadot/types": "^0.51.1", - "@polkadot/util": "^0.42.0-beta.0", - "@polkadot/util-crypto": "^0.42.0-beta.0", + "@polkadot/api": "^0.52.0-beta.1", + "@polkadot/keyring": "^0.42.0-beta.1", + "@polkadot/types": "^0.52.0-beta.1", + "@polkadot/util": "^0.42.0-beta.1", + "@polkadot/util-crypto": "^0.42.0-beta.1", "babel-core": "^7.0.0-bridge.0", "rxjs": "^6.4.0", "typescript": "^3.3.4000" diff --git a/packages/app-staking/src/Account/Bonding.tsx b/packages/app-staking/src/Account/Bonding.tsx index 57dad38795..92b945bfa8 100644 --- a/packages/app-staking/src/Account/Bonding.tsx +++ b/packages/app-staking/src/Account/Bonding.tsx @@ -12,13 +12,14 @@ import translate from '../translate'; type Props = I18nProps & { accountId: string, - controllerId: string, + sessionId: string, isOpen: boolean, onClose: () => void }; type State = { bondValue?: BN, + controllerId: string | null, destination: number }; @@ -30,13 +31,14 @@ const stashOptions = [ class Bonding extends React.PureComponent { state: State = { + controllerId: null, destination: 0 }; render () { - const { accountId, controllerId, isOpen, onClose, t } = this.props; - const { bondValue, destination } = this.state; - const canSubmit = !!bondValue && bondValue.gtn(0); + const { accountId, isOpen, onClose, t } = this.props; + const { bondValue, controllerId, destination } = this.state; + const canSubmit = !!bondValue && bondValue.gtn(0) && controllerId; if (!isOpen) { return null; @@ -74,7 +76,8 @@ class Bonding extends React.PureComponent { } private renderContent () { - const { accountId, controllerId, t } = this.props; + const { accountId, sessionId, t } = this.props; + const { controllerId } = this.state; return ( <> @@ -90,9 +93,10 @@ class Bonding extends React.PureComponent { /> { ); } + private onChangeController = (controllerId: string) => { + this.setState({ controllerId }); + } + private onChangeDestination = (destination: number) => { this.setState({ destination }); } diff --git a/packages/app-staking/src/Account/Controller.tsx b/packages/app-staking/src/Account/SessionKey.tsx similarity index 60% rename from packages/app-staking/src/Account/Controller.tsx rename to packages/app-staking/src/Account/SessionKey.tsx index 7d6fb77b53..067a428ac4 100644 --- a/packages/app-staking/src/Account/Controller.tsx +++ b/packages/app-staking/src/Account/SessionKey.tsx @@ -11,21 +11,17 @@ import translate from '../translate'; type Props = I18nProps & { accountId: string, - controllerId: string | null, isOpen: boolean, onClose: () => void }; -type State = { - nextController?: string -}; +type State = {}; -class Controller extends React.PureComponent { +class Key extends React.PureComponent { state: State = {}; render () { const { accountId, isOpen, onClose, t } = this.props; - const { nextController } = this.state; if (!isOpen) { return null; @@ -33,7 +29,7 @@ class Controller extends React.PureComponent { return ( { @@ -63,40 +58,24 @@ class Controller extends React.PureComponent { } private renderContent () { - const { accountId, controllerId, t } = this.props; - const { nextController } = this.state; - const defaultValue = controllerId - ? controllerId - : undefined; + const { accountId, t } = this.props; return ( <> - {t('Controller Preferences')} + {t('Key Preferences')} - ); } - - private onChangeController = (nextController: string) => { - this.setState({ nextController }); - } } -export default translate(Controller); +export default translate(Key); diff --git a/packages/app-staking/src/Account/index.tsx b/packages/app-staking/src/Account/index.tsx index 9dfb653f7f..9ee9d57a42 100644 --- a/packages/app-staking/src/Account/index.tsx +++ b/packages/app-staking/src/Account/index.tsx @@ -12,7 +12,7 @@ import { AddressMini, AddressSummary, Button, TxButton } from '@polkadot/ui-app' import { withCalls } from '@polkadot/ui-api'; import Bonding from './Bonding'; -import Controller from './Controller'; +import SessionKey from './SessionKey'; import Staking from './Staking'; import Nominating from './Nominating'; import translate from '../translate'; @@ -35,12 +35,12 @@ type Props = ApiProps & I18nProps & { type State = { isBondingOpen: boolean, - isControllerOpen: boolean, + isKeyOpen: boolean, isNominateOpen: boolean, isStakingOpen: boolean, isUnbondOpen: boolean, bondedId: string | null, - controllerId: string | null, + sessionId: string | null, nomineeId: string | null, stashId: string | null }; @@ -48,12 +48,12 @@ type State = { class Account extends React.PureComponent { state: State = { isBondingOpen: false, - isControllerOpen: false, + isKeyOpen: false, isNominateOpen: false, isStakingOpen: false, isUnbondOpen: false, bondedId: null, - controllerId: null, + sessionId: null, nomineeId: null, stashId: null }; @@ -63,7 +63,7 @@ class Account extends React.PureComponent { bondedId: staking_bonded && staking_bonded.isSome ? staking_bonded.unwrap().toString() : null, - controllerId: session_nextKeyFor && session_nextKeyFor.isSome + sessionId: session_nextKeyFor && session_nextKeyFor.isSome ? session_nextKeyFor.unwrap().toString() : null, nomineeId: staking_nominating && staking_nominating.isSome @@ -81,8 +81,8 @@ class Account extends React.PureComponent { return (
{this.renderBonding()} - {this.renderController()} {this.renderNominating()} + {this.renderKey()} {this.renderStaking()} { private renderBonding () { const { accountId } = this.props; - const { controllerId, isBondingOpen } = this.state; + const { sessionId, isBondingOpen } = this.state; - if (!controllerId) { + if (!sessionId) { return null; } return ( ); } - private renderController () { - const { accountId } = this.props; - const { controllerId, isControllerOpen } = this.state; - - return ( - - ); - } - private renderStaking () { const { accountId, staking_validators } = this.props; const { isStakingOpen, stashId } = this.state; @@ -151,6 +137,19 @@ class Account extends React.PureComponent { ); } + private renderKey () { + const { accountId } = this.props; + const { isKeyOpen } = this.state; + + return ( + + ); + } + // private renderUnbond () { // const { accountId } = this.props; // const { controllerId, isBondingOpen } = this.state; @@ -229,12 +228,21 @@ class Account extends React.PureComponent { private renderButtons () { const { accountId, t } = this.props; - const { controllerId, stashId } = this.state; + const { sessionId, stashId } = this.state; const buttons = []; if (!stashId) { - // only display bonding if we already have a controller - if (controllerId) { + buttons.push( +