Remove unsafe chain detection, always warn (#2400)

This commit is contained in:
Jaco Greeff 2020-03-16 17:31:59 +01:00 committed by GitHub
parent 3a86fd0ccd
commit 1ff83ff074
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 35 deletions

View File

@ -14,7 +14,6 @@ import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
import { withCalls, withApi, withMulti } from '@polkadot/react-api/hoc';
import translate from '../../translate';
import detectUnsafe from '../../unsafeChains';
import ValidateAmount from './InputValidateAmount';
interface Props extends I18nProps, ApiProps, CalculateBalanceProps {
@ -72,9 +71,8 @@ class BondExtra extends TxComponent<Props, State> {
}
private renderContent (): React.ReactNode {
const { stashId, systemChain, t } = this.props;
const { stashId, t } = this.props;
const { amountError, maxAdditional, maxBalance } = this.state;
const isUnsafeChain = detectUnsafe(systemChain);
return (
<Modal.Content className='ui--signer-Signer-Content'>
@ -94,7 +92,6 @@ class BondExtra extends TxComponent<Props, State> {
maxValue={maxBalance}
onChange={this.onChangeValue}
onEnter={this.sendTx}
withMax={!isUnsafeChain}
/>
<ValidateAmount
accountId={stashId}

View File

@ -15,13 +15,10 @@ interface Props {
accountId: string | null;
controllerId: string | null;
defaultController?: string;
isUnsafeChain?: boolean;
onError: (error: string | null) => void;
}
const DISTINCT = 'Distinct stash and controller accounts are recommended to ensure fund security.';
function ValidateController ({ accountId, controllerId, defaultController, isUnsafeChain, onError }: Props): React.ReactElement<Props> | null {
function ValidateController ({ accountId, controllerId, defaultController, onError }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const { api } = useApi();
const bondedId = useCall<string | null>(api.query.staking.bonded, [controllerId], {
@ -45,9 +42,7 @@ function ValidateController ({ accountId, controllerId, defaultController, isUns
let newError: string | null = null;
if (controllerId === accountId) {
newError = isUnsafeChain
? t(`${DISTINCT} You will be allowed to make the transaction, but take care to not tie up all funds, only use a portion of the available funds during this period.`)
: t(DISTINCT);
newError = t('Distinct stash and controller accounts are recommended to ensure fund security. You will be allowed to make the transaction, but take care to not tie up all funds, only use a portion of the available funds during this period.');
} else if (bondedId) {
newError = 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

@ -10,7 +10,6 @@ import { Icon, InputAddress, Modal, TxButton, TxComponent } from '@polkadot/reac
import { withApi, withMulti } from '@polkadot/react-api/hoc';
import translate from '../../translate';
import detectUnsafe from '../../unsafeChains';
import InputValidationController from '../Account/InputValidationController';
interface Props extends ApiProps, I18nProps {
@ -36,10 +35,9 @@ class SetControllerAccount extends TxComponent<Props, State> {
}
public render (): React.ReactNode {
const { defaultControllerId, isValidating, onClose, stashId, systemChain, t } = this.props;
const { controllerError, controllerId } = this.state;
const isUnsafeChain = detectUnsafe(systemChain);
const canSubmit = isUnsafeChain || (!controllerError && !!controllerId && (defaultControllerId !== controllerId));
const { defaultControllerId, isValidating, onClose, stashId, t } = this.props;
const { controllerId } = this.state;
const canSubmit = !!controllerId;
return (
<Modal
@ -66,7 +64,6 @@ class SetControllerAccount extends TxComponent<Props, State> {
className='medium'
defaultValue={defaultControllerId}
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={!isUnsafeChain && !!controllerError}
label={t('controller account')}
onChange={this.onChangeController}
type='account'
@ -76,7 +73,6 @@ class SetControllerAccount extends TxComponent<Props, State> {
accountId={stashId}
defaultController={defaultControllerId}
controllerId={controllerId}
isUnsafeChain={isUnsafeChain}
onError={this.onControllerError}
/>
</Modal.Content>

View File

@ -13,7 +13,6 @@ import { Dropdown, InputAddress, InputBalanceBonded, Modal, TxButton, TxComponen
import { withApi, withMulti } from '@polkadot/react-api/hoc';
import translate from '../translate';
import detectUnsafe from '../unsafeChains';
import InputValidateAmount from './Account/InputValidateAmount';
import InputValidationController from './Account/InputValidationController';
import { rewardDestinationOptions } from './constants';
@ -49,11 +48,10 @@ class NewStake extends TxComponent<Props, State> {
}
public render (): React.ReactNode {
const { onClose, systemChain, t } = this.props;
const { amountError, bondValue, controllerError, controllerId, destination, extrinsic, stashId } = this.state;
const { onClose, t } = this.props;
const { amountError, bondValue, controllerId, destination, extrinsic, stashId } = this.state;
const hasValue = !!bondValue && bondValue.gtn(0);
const isUnsafeChain = detectUnsafe(systemChain);
const canSubmit = (hasValue && (isUnsafeChain || (!controllerError && !!controllerId)));
const canSubmit = hasValue && !!controllerId;
return (
<Modal
@ -72,7 +70,6 @@ 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={!isUnsafeChain && !!controllerError}
label={t('controller account')}
onChange={this.onChangeController}
type='account'
@ -81,7 +78,6 @@ class NewStake extends TxComponent<Props, State> {
<InputValidationController
accountId={stashId}
controllerId={controllerId}
isUnsafeChain={isUnsafeChain}
onError={this.onControllerError}
/>
<InputBalanceBonded
@ -96,7 +92,6 @@ class NewStake extends TxComponent<Props, State> {
onChange={this.onChangeValue}
onEnter={this.sendTx}
stashId={stashId}
withMax={!isUnsafeChain}
/>
<InputValidateAmount
accountId={stashId}

View File

@ -1,9 +0,0 @@
// Copyright 2017-2020 @polkadot/ui-staking authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
export const UNSAFE_CHAINS = ['Development', 'Kusama CC1', 'Kusama CC2', 'Kusama CC3', 'Kusama'];
export default function detectUnsafe (chain: Text | string): boolean {
return UNSAFE_CHAINS.includes(chain.toString());
}