Update for 2.x ValidatorPrefs (#1513)
* Update for 2.x ValidatorPrefs * Whitepace, linting... * Type cleanups * Cater for ValidatorPrefs, no unstake
This commit is contained in:
parent
40cc96eb66
commit
48faaf9541
@ -10,10 +10,10 @@
|
||||
"packages/*"
|
||||
],
|
||||
"resolutions": {
|
||||
"@polkadot/api": "^0.90.0-beta.66",
|
||||
"@polkadot/api-contract": "^0.90.0-beta.66",
|
||||
"@polkadot/api": "^0.90.0-beta.67",
|
||||
"@polkadot/api-contract": "^0.90.0-beta.67",
|
||||
"@polkadot/keyring": "^1.1.1",
|
||||
"@polkadot/types": "^0.90.0-beta.66",
|
||||
"@polkadot/types": "^0.90.0-beta.67",
|
||||
"@polkadot/util": "^1.1.1",
|
||||
"@polkadot/util-crypto": "^1.1.1",
|
||||
"@types/styled-components": "4.1.8",
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.5.5",
|
||||
"@polkadot/api-contract": "^0.90.0-beta.66",
|
||||
"@polkadot/api-contract": "^0.90.0-beta.67",
|
||||
"@polkadot/react-components": "^0.34.0-beta.133"
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,22 +2,24 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ValidatorPrefs } from '@polkadot/types/interfaces';
|
||||
import { ValidatorPrefs, ValidatorPrefs0to145 } from '@polkadot/types/interfaces';
|
||||
import { ApiProps } from '@polkadot/react-api/types';
|
||||
import { I18nProps } from '@polkadot/react-components/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import { withApi, withMulti } from '@polkadot/react-api';
|
||||
import { Button, InputAddress, InputBalance, InputNumber, Modal, TxButton, TxComponent } from '@polkadot/react-components';
|
||||
|
||||
import InputValidationUnstakeThreshold from './InputValidationUnstakeThreshold';
|
||||
import translate from '../../translate';
|
||||
|
||||
interface Props extends I18nProps {
|
||||
interface Props extends ApiProps, I18nProps {
|
||||
controllerId: string;
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
stashId: string;
|
||||
validatorPrefs?: ValidatorPrefs;
|
||||
validatorPrefs?: ValidatorPrefs | ValidatorPrefs0to145;
|
||||
}
|
||||
|
||||
interface State {
|
||||
@ -35,26 +37,31 @@ class Validate extends TxComponent<Props, State> {
|
||||
|
||||
// inject the preferences returned via RPC once into the state (from this
|
||||
// point forward it will be entirely managed by the actual inputs)
|
||||
public static getDerivedStateFromProps (props: Props, state: State): State | null {
|
||||
public static getDerivedStateFromProps ({ isSubstrateV2, validatorPrefs }: Props, state: State): Pick<State, never> | null {
|
||||
if (state.unstakeThreshold && state.validatorPayment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (props.validatorPrefs) {
|
||||
const { unstakeThreshold, validatorPayment } = props.validatorPrefs;
|
||||
if (validatorPrefs) {
|
||||
// 1.x, it has both values
|
||||
if (isSubstrateV2) {
|
||||
const { validatorPayment } = validatorPrefs as ValidatorPrefs;
|
||||
|
||||
return {
|
||||
unstakeThreshold: unstakeThreshold.toBn(),
|
||||
unstakeThresholdError: null,
|
||||
validatorPayment: validatorPayment.toBn()
|
||||
};
|
||||
return {
|
||||
validatorPayment: validatorPayment.toBn()
|
||||
};
|
||||
} else {
|
||||
const { unstakeThreshold, validatorPayment } = validatorPrefs as ValidatorPrefs0to145;
|
||||
|
||||
return {
|
||||
unstakeThreshold: unstakeThreshold.toBn(),
|
||||
unstakeThresholdError: null,
|
||||
validatorPayment: validatorPayment.toBn()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
unstakeThreshold: undefined,
|
||||
unstakeThresholdError: null,
|
||||
validatorPayment: undefined
|
||||
};
|
||||
return null;
|
||||
}
|
||||
|
||||
public render (): React.ReactNode {
|
||||
@ -78,9 +85,8 @@ class Validate extends TxComponent<Props, State> {
|
||||
}
|
||||
|
||||
private renderButtons (): React.ReactNode {
|
||||
const { controllerId, onClose, t, validatorPrefs } = this.props;
|
||||
const { controllerId, isSubstrateV2, onClose, t } = this.props;
|
||||
const { unstakeThreshold, unstakeThresholdError, validatorPayment } = this.state;
|
||||
const isChangingPrefs = validatorPrefs && !!validatorPrefs.unstakeThreshold;
|
||||
|
||||
return (
|
||||
<Modal.Actions>
|
||||
@ -95,12 +101,13 @@ class Validate extends TxComponent<Props, State> {
|
||||
accountId={controllerId}
|
||||
isDisabled={!!unstakeThresholdError}
|
||||
isPrimary
|
||||
label={isChangingPrefs ? t('Set validator preferences') : t('Validate')}
|
||||
label={t('Validate Preferences')}
|
||||
onClick={onClose}
|
||||
params={[{
|
||||
unstakeThreshold,
|
||||
validatorPayment
|
||||
}]}
|
||||
params={[
|
||||
isSubstrateV2
|
||||
? { validatorPayment }
|
||||
: { unstakeThreshold, validatorPayment }
|
||||
]}
|
||||
tx='staking.validate'
|
||||
ref={this.button}
|
||||
/>
|
||||
@ -110,9 +117,9 @@ class Validate extends TxComponent<Props, State> {
|
||||
}
|
||||
|
||||
private renderContent (): React.ReactNode {
|
||||
const { controllerId, stashId, t, validatorPrefs } = this.props;
|
||||
const { controllerId, isSubstrateV2, stashId, t, validatorPrefs } = this.props;
|
||||
const { unstakeThreshold, unstakeThresholdError, validatorPayment } = this.state;
|
||||
const defaultValue = validatorPrefs && validatorPrefs.unstakeThreshold && validatorPrefs.unstakeThreshold.toBn();
|
||||
const defaultThreshold = validatorPrefs && (validatorPrefs as ValidatorPrefs0to145).unstakeThreshold && (validatorPrefs as ValidatorPrefs0to145).unstakeThreshold.toBn();
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -132,26 +139,30 @@ class Validate extends TxComponent<Props, State> {
|
||||
isDisabled
|
||||
label={t('controller account')}
|
||||
/>
|
||||
<InputNumber
|
||||
autoFocus
|
||||
bitLength={32}
|
||||
className='medium'
|
||||
defaultValue={defaultValue}
|
||||
help={t('The number of time this validator can get slashed before being automatically unstaked (maximum of 10 allowed)')}
|
||||
isError={!!unstakeThresholdError}
|
||||
label={t('automatic unstake threshold')}
|
||||
onChange={this.onChangeThreshold}
|
||||
onEnter={this.sendTx}
|
||||
value={
|
||||
unstakeThreshold
|
||||
? unstakeThreshold.toString()
|
||||
: '3'
|
||||
}
|
||||
/>
|
||||
<InputValidationUnstakeThreshold
|
||||
onError={this.onUnstakeThresholdError}
|
||||
unstakeThreshold={unstakeThreshold}
|
||||
/>
|
||||
{!isSubstrateV2 && (
|
||||
<>
|
||||
<InputNumber
|
||||
autoFocus
|
||||
bitLength={32}
|
||||
className='medium'
|
||||
defaultValue={defaultThreshold}
|
||||
help={t('The number of time this validator can get slashed before being automatically unstaked (maximum of 10 allowed)')}
|
||||
isError={!!unstakeThresholdError}
|
||||
label={t('automatic unstake threshold')}
|
||||
onChange={this.onChangeThreshold}
|
||||
onEnter={this.sendTx}
|
||||
value={
|
||||
unstakeThreshold
|
||||
? unstakeThreshold.toString()
|
||||
: '3'
|
||||
}
|
||||
/>
|
||||
<InputValidationUnstakeThreshold
|
||||
onError={this.onUnstakeThresholdError}
|
||||
unstakeThreshold={unstakeThreshold}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<InputBalance
|
||||
className='medium'
|
||||
defaultValue={validatorPrefs && validatorPrefs.validatorPayment && validatorPrefs.validatorPayment.toBn()}
|
||||
@ -187,4 +198,8 @@ class Validate extends TxComponent<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
export default translate(Validate);
|
||||
export default withMulti(
|
||||
Validate,
|
||||
translate,
|
||||
withApi
|
||||
);
|
||||
|
||||
@ -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.66",
|
||||
"@polkadot/api": "^0.90.0-beta.67",
|
||||
"@polkadot/extension-dapp": "^0.7.1",
|
||||
"rxjs-compat": "^6.4.0"
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { DerivedBalances, DerivedStaking } from '@polkadot/api-derive/types';
|
||||
import { ValidatorPrefs0to145 } from '@polkadot/types/interfaces';
|
||||
import { BareProps, I18nProps } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@ -262,10 +263,11 @@ class AddressInfo extends React.PureComponent<Props> {
|
||||
return (
|
||||
<>
|
||||
<div className='spacer'></div>
|
||||
{validatorPrefsDisplay.unstakeThreshold && staking_info.validatorPrefs.unstakeThreshold && (
|
||||
{validatorPrefsDisplay.unstakeThreshold && (staking_info.validatorPrefs as ValidatorPrefs0to145).unstakeThreshold && (
|
||||
<>
|
||||
<Label label={t('unstake threshold')} />
|
||||
<div className='result'>{staking_info.validatorPrefs.unstakeThreshold.toString()}
|
||||
<div className='result'>
|
||||
{(staking_info.validatorPrefs as ValidatorPrefs0to145).unstakeThreshold.toString()}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
90
yarn.lock
90
yarn.lock
@ -1931,44 +1931,44 @@
|
||||
universal-user-agent "^3.0.0"
|
||||
url-template "^2.0.8"
|
||||
|
||||
"@polkadot/api-contract@^0.90.0-beta.66":
|
||||
version "0.90.0-beta.66"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.90.0-beta.66.tgz#0078f56637a787d97877982d67377caa0ef65d6b"
|
||||
integrity sha512-BxhHi5MyTaaeaPczfP5NyTiSvRPJ5DMf1bkL24XnLihH3/fMMFbzlYrQV0vGeoy1uxNp/m0oj4OYBEQ/NjP6Bg==
|
||||
"@polkadot/api-contract@^0.90.0-beta.67":
|
||||
version "0.90.0-beta.67"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.90.0-beta.67.tgz#199a27b81cfe4673a35ca5a1bf2c1d9ecf71a853"
|
||||
integrity sha512-ei+hBKznNnZ6V2yN4Il5JYpHItgU96YyMa6lRoZ1qHG0CZGs0ACuaZFjHWnrV6hF3pwkZcArKjXUCjve68p++g==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.5.5"
|
||||
"@polkadot/types" "^0.90.0-beta.66"
|
||||
"@polkadot/types" "^0.90.0-beta.67"
|
||||
|
||||
"@polkadot/api-derive@^0.90.0-beta.66":
|
||||
version "0.90.0-beta.66"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.90.0-beta.66.tgz#ace54dad83dc76c2bded9e556d71084a6d2f2acd"
|
||||
integrity sha512-tUGY/lXK5egG+tr633dzBGJPFJCSubX/TDDGwJ6YU20FotsExIytlk6HRq1u0SOULtgcs7lO417UVuHBHXT/FA==
|
||||
"@polkadot/api-derive@^0.90.0-beta.67":
|
||||
version "0.90.0-beta.67"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.90.0-beta.67.tgz#ccbf0b3e1c68fa25fe4080bfcf42e6920b504f4d"
|
||||
integrity sha512-NrBO7eIL/Znes8i2UZoywp3mOPg6RUhrZDd+7b70Nb22XvivW8ADzcC76h2Zm/EYF9lL15BSoE+pPq5k17Yb6Q==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.5.5"
|
||||
"@polkadot/api" "^0.90.0-beta.66"
|
||||
"@polkadot/types" "^0.90.0-beta.66"
|
||||
"@polkadot/api" "^0.90.0-beta.67"
|
||||
"@polkadot/types" "^0.90.0-beta.67"
|
||||
|
||||
"@polkadot/api-metadata@^0.90.0-beta.66":
|
||||
version "0.90.0-beta.66"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/api-metadata/-/api-metadata-0.90.0-beta.66.tgz#64d3869d12f7dc39636acf7f32404dc2484b42a5"
|
||||
integrity sha512-NNfeS+ewuxbnHu+u5hOIyfqWs6M+mLB/u2vYnY6xk4JJgr1onwtGcIfjC6aFXBgy0oAgmoa1VJoOMzscuO7pmg==
|
||||
"@polkadot/api-metadata@^0.90.0-beta.67":
|
||||
version "0.90.0-beta.67"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/api-metadata/-/api-metadata-0.90.0-beta.67.tgz#73d6379317f2440070b8f4ebb964e94d4ba41c84"
|
||||
integrity sha512-vVRd/vA18b9CLDI5Jg6RwsXU+5lAS73bZfmUooY5LVli4Kbby41PVwnFA1W4YQd8RGjxN2O3M/F3oA/OUsBNwQ==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.5.5"
|
||||
"@polkadot/types" "^0.90.0-beta.66"
|
||||
"@polkadot/types" "^0.90.0-beta.67"
|
||||
"@polkadot/util" "^1.1.1"
|
||||
"@polkadot/util-crypto" "^1.1.1"
|
||||
|
||||
"@polkadot/api@^0.90.0-beta.66":
|
||||
version "0.90.0-beta.66"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.90.0-beta.66.tgz#c3bee2bf64333aceee99f449602e2a318cd73947"
|
||||
integrity sha512-ulxtjFnR4Arwpt1Znz5cWzDWL9jhjR+rJo349WRiYTYEBM8n4UEOIA85JY2mNDPKSoZqe7/Wq12/9lIG8e3K9A==
|
||||
"@polkadot/api@^0.90.0-beta.67":
|
||||
version "0.90.0-beta.67"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.90.0-beta.67.tgz#0335a57090a0adcfd2a182531ce883f6618d078d"
|
||||
integrity sha512-1FgI7Q9nq4Gnx91Fthk8u4huvqo+U9VNZ7Wd0tAuSs0K+1cPHLEnZ0x+QMYEd3Iy4O5oRmc1kWNy3APsdTfDiQ==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.5.5"
|
||||
"@polkadot/api-derive" "^0.90.0-beta.66"
|
||||
"@polkadot/api-metadata" "^0.90.0-beta.66"
|
||||
"@polkadot/rpc-core" "^0.90.0-beta.66"
|
||||
"@polkadot/rpc-provider" "^0.90.0-beta.66"
|
||||
"@polkadot/types" "^0.90.0-beta.66"
|
||||
"@polkadot/api-derive" "^0.90.0-beta.67"
|
||||
"@polkadot/api-metadata" "^0.90.0-beta.67"
|
||||
"@polkadot/rpc-core" "^0.90.0-beta.67"
|
||||
"@polkadot/rpc-provider" "^0.90.0-beta.67"
|
||||
"@polkadot/types" "^0.90.0-beta.67"
|
||||
"@polkadot/util-crypto" "^1.1.1"
|
||||
|
||||
"@polkadot/dev-react@^0.31.0-beta.3":
|
||||
@ -2071,10 +2071,10 @@
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.5.5"
|
||||
|
||||
"@polkadot/jsonrpc@^0.90.0-beta.66":
|
||||
version "0.90.0-beta.66"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.90.0-beta.66.tgz#cd65bdec97ebbe314b9d18126ef2c57adbd32ea9"
|
||||
integrity sha512-Sxqd/Eh7m0MhBCXo3ItbHeZEKDUdnJqUbZWyQnNUXRlQHgxmpfDdtEdPfnLbgeBJeoDL3q2oG1PDBmAV2Po44g==
|
||||
"@polkadot/jsonrpc@^0.90.0-beta.67":
|
||||
version "0.90.0-beta.67"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.90.0-beta.67.tgz#bd0d3c27107136c6d6722970419a08bd739b4239"
|
||||
integrity sha512-BQUfrD7vD3zthWpcnHNiHn++hvrnkgnFXzMJcwAicelBHTpQ9ZmrmZQjckTge/nhcS24VycvlloJKhd6frlhWw==
|
||||
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.66":
|
||||
version "0.90.0-beta.66"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.90.0-beta.66.tgz#d7df054aafec3ea0a791c0887f7b74495ab8594d"
|
||||
integrity sha512-wu1B3ol6KI/AkicLeZ/CVM3LyjRuVwnpfNrf198vN1eTv4wOpM5O5P0EyuTYQ5X0L6WGIcaBCnyv/rhBR/E6+g==
|
||||
"@polkadot/rpc-core@^0.90.0-beta.67":
|
||||
version "0.90.0-beta.67"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.90.0-beta.67.tgz#143dc10621767d41778e7d56b41dabc6b34c658d"
|
||||
integrity sha512-c3uQAFA8/kYS56jWhcqycp2xI9y8hLzuGiu+LYgE4XqNCEAL7pG3P8R13DvaI+WSSag6QmSx1G3lLmfcv+Y30Q==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.5.5"
|
||||
"@polkadot/jsonrpc" "^0.90.0-beta.66"
|
||||
"@polkadot/rpc-provider" "^0.90.0-beta.66"
|
||||
"@polkadot/types" "^0.90.0-beta.66"
|
||||
"@polkadot/jsonrpc" "^0.90.0-beta.67"
|
||||
"@polkadot/rpc-provider" "^0.90.0-beta.67"
|
||||
"@polkadot/types" "^0.90.0-beta.67"
|
||||
"@polkadot/util" "^1.1.1"
|
||||
rxjs "^6.5.2"
|
||||
|
||||
"@polkadot/rpc-provider@^0.90.0-beta.66":
|
||||
version "0.90.0-beta.66"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.90.0-beta.66.tgz#5fcb293b298849f0ce3b6bb82faadcfc06e0ff29"
|
||||
integrity sha512-fBA/pkxh9Bl07d8A9u7aQuZflcN5NxqwkndWdp/g4GBRJzYWojBWFoybOeVvfrd7GjffNK2o0b+znwuVJOFxYA==
|
||||
"@polkadot/rpc-provider@^0.90.0-beta.67":
|
||||
version "0.90.0-beta.67"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.90.0-beta.67.tgz#b0e7a346936c25950db82c224e121e92e93ef0db"
|
||||
integrity sha512-1PScOtQcsUiL87gomCwzu6rHdV0jwPQF47NHc9tINahCHJ9yjFl8tShF3SReJp2EQrDUzM7+NvCc81inylTT3g==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.5.5"
|
||||
"@polkadot/api-metadata" "^0.90.0-beta.66"
|
||||
"@polkadot/api-metadata" "^0.90.0-beta.67"
|
||||
"@polkadot/util" "^1.1.1"
|
||||
"@polkadot/util-crypto" "^1.1.1"
|
||||
"@types/nock" "^10.0.3"
|
||||
@ -2135,10 +2135,10 @@
|
||||
dependencies:
|
||||
"@types/chrome" "^0.0.86"
|
||||
|
||||
"@polkadot/types@^0.90.0-beta.66":
|
||||
version "0.90.0-beta.66"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.90.0-beta.66.tgz#8022693a7d8fde133ef7588dd9601d2cde988519"
|
||||
integrity sha512-swQ2DvPe6QRL+M70AowQsIyI2ynp0g0HFaF9kueEsIWURMImJh13VT80NhBjcOAV6AA/bIgFhiEjw1fF0d+77Q==
|
||||
"@polkadot/types@^0.90.0-beta.67":
|
||||
version "0.90.0-beta.67"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.90.0-beta.67.tgz#c27bbb26973304cad55f5c786a57e08250c709ae"
|
||||
integrity sha512-QoNFjiZdT8IlSo8kisqr36NvSlGqa+lNXK/fP3Ptw9x4TO6LF/Svo4MoGl75FFeG/GdFSrXKcNJk1ICcJ/Dt8w==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.5.5"
|
||||
"@polkadot/util" "^1.1.1"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user