Only warn for controller === stash (Dev, Kusama) (#1519)

This commit is contained in:
Jaco Greeff 2019-08-21 21:41:13 +02:00 committed by GitHub
parent 5d3fd7797a
commit b8cb835b32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 15 deletions

View File

@ -2,8 +2,9 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, StakingLedger } from '@polkadot/types/interfaces';
import { ApiProps } from '@polkadot/react-api/types';
import { I18nProps } from '@polkadot/react-components/types';
import { AccountId, StakingLedger } from '@polkadot/types/interfaces';
import React from 'react';
import { Icon } from '@polkadot/react-components';
@ -12,7 +13,7 @@ import { withCalls } from '@polkadot/react-api';
import translate from '../../translate';
interface Props extends I18nProps {
interface Props extends ApiProps, I18nProps {
accountId: string | null;
bondedId?: string | null;
controllerId: string | null;
@ -37,7 +38,7 @@ class ValidateController extends React.PureComponent<Props, State> {
// this applies when changing controller
return null;
} else if (controllerId === accountId) {
return t('Please select distinct stash and controller accounts');
return t('Distinct stash and controller accounts are recommended to ensure fund security');
} else if (bondedId) {
return t('A controller account should not map to another stash. This selected controller is a stash, controlled by {{bondedId}}', { replace: { bondedId } });
} else if (stashId) {

View File

@ -101,7 +101,7 @@ class Validate extends TxComponent<Props, State> {
accountId={controllerId}
isDisabled={!!unstakeThresholdError}
isPrimary
label={t('Validate Preferences')}
label={t('Validate')}
onClick={onClose}
params={[
isSubstrateV2

View File

@ -10,15 +10,17 @@ import BN from 'bn.js';
import React from 'react';
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
import { Button, Dropdown, InputAddress, InputBalanceBonded, Modal, TxButton, TxComponent } from '@polkadot/react-components';
import { withApi, withMulti } from '@polkadot/react-api';
import { withCalls, withMulti } from '@polkadot/react-api';
import { Text } from '@polkadot/types';
import translate from '../translate';
import { rewardDestinationOptions } from './constants';
import InputValidationController from './Account/InputValidationController';
import { rewardDestinationOptions } from './constants';
type Props = I18nProps & ApiProps & CalculateBalanceProps & {
interface Props extends ApiProps, I18nProps, CalculateBalanceProps {
onClose: () => void;
};
systemChain?: Text;
}
interface State {
bondValue?: BN;
@ -26,9 +28,12 @@ interface State {
controllerId: string | null;
destination: number;
extrinsic: SubmittableExtrinsic | null;
ignoreController: boolean;
stashId: string | null;
}
const NO_VALIDATION_CHAINS = ['Development', 'Kusama'];
class NewStake extends TxComponent<Props, State> {
public state: State;
@ -40,15 +45,26 @@ class NewStake extends TxComponent<Props, State> {
controllerId: null,
destination: 0,
extrinsic: null,
ignoreController: false,
stashId: null
};
}
public static getDerivedStateFromProps ({ systemChain }: Props): Pick<State, any> | null {
if (!systemChain) {
return null;
}
return {
ignoreController: NO_VALIDATION_CHAINS.includes(systemChain.toString())
};
}
public render (): React.ReactNode {
const { onClose, t } = this.props;
const { bondValue, controllerError, controllerId, extrinsic, stashId } = this.state;
const { bondValue, controllerError, controllerId, extrinsic, ignoreController, stashId } = this.state;
const hasValue = !!bondValue && bondValue.gtn(0);
const canSubmit = hasValue && !controllerError && !!controllerId;
const canSubmit = (hasValue && (ignoreController || (!controllerError && !!controllerId)));
return (
<Modal
@ -83,7 +99,7 @@ class NewStake extends TxComponent<Props, State> {
private renderContent (): React.ReactNode {
const { t } = this.props;
const { controllerId, controllerError, bondValue, destination, stashId } = this.state;
const { controllerId, controllerError, bondValue, destination, ignoreController, stashId } = this.state;
const hasValue = !!bondValue && bondValue.gtn(0);
return (
@ -102,7 +118,7 @@ class NewStake extends TxComponent<Props, State> {
<InputAddress
className='medium'
help={t('The controller is the account that will be used to control any nominating or validating actions. Should not match another stash or controller.')}
isError={!!controllerError}
isError={!ignoreController && !!controllerError}
label={t('controller account')}
onChange={this.onChangeController}
type='account'
@ -144,7 +160,7 @@ class NewStake extends TxComponent<Props, State> {
private nextState (newState: Partial<State>): void {
this.setState((prevState: State): State => {
const { api } = this.props;
const { bondValue = prevState.bondValue, controllerError = prevState.controllerError, controllerId = prevState.controllerId, destination = prevState.destination, stashId = prevState.stashId } = newState;
const { bondValue = prevState.bondValue, controllerError = prevState.controllerError, controllerId = prevState.controllerId, destination = prevState.destination, ignoreController = prevState.ignoreController, stashId = prevState.stashId } = newState;
const extrinsic = (bondValue && controllerId)
? api.tx.staking.bond(controllerId, bondValue, destination)
: null;
@ -155,6 +171,7 @@ class NewStake extends TxComponent<Props, State> {
controllerId,
destination,
extrinsic,
ignoreController,
stashId
};
});
@ -184,5 +201,7 @@ class NewStake extends TxComponent<Props, State> {
export default withMulti(
NewStake,
translate,
withApi
withCalls<Props>(
['rpc.system.chain', { propName: 'systemChain' }]
)
);

View File

@ -4,6 +4,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { Route } from '@polkadot/apps-routing/types';
import { ApiProps } from '@polkadot/react-api/types';
import { I18nProps } from '@polkadot/react-components/types';
import { SIDEBAR_MENU_THRESHOLD } from '../constants';
@ -24,7 +25,7 @@ import Item from './Item';
import NodeInfo from './NodeInfo';
import getLogo from './logos';
interface Props extends I18nProps {
interface Props extends ApiProps, I18nProps {
collapse: () => void;
handleResize: () => void;
isCollapsed: boolean;