diff --git a/package.json b/package.json index 00817e3ae6..f1bb183a7d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/app-contracts/package.json b/packages/app-contracts/package.json index ebdfdf4250..a5f278dcf8 100644 --- a/packages/app-contracts/package.json +++ b/packages/app-contracts/package.json @@ -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" } } diff --git a/packages/app-staking/src/Actions/Account/Validate.tsx b/packages/app-staking/src/Actions/Account/Validate.tsx index 928941416d..3ef1e0a2cd 100644 --- a/packages/app-staking/src/Actions/Account/Validate.tsx +++ b/packages/app-staking/src/Actions/Account/Validate.tsx @@ -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 { // 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 | 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 { } 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 ( @@ -95,12 +101,13 @@ class Validate extends TxComponent { 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 { } 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 { isDisabled label={t('controller account')} /> - - + {!isSubstrateV2 && ( + <> + + + + )} { } } -export default translate(Validate); +export default withMulti( + Validate, + translate, + withApi +); diff --git a/packages/react-api/package.json b/packages/react-api/package.json index 7e432f0bad..e64c29e638 100644 --- a/packages/react-api/package.json +++ b/packages/react-api/package.json @@ -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" } diff --git a/packages/react-components/src/AddressInfo.tsx b/packages/react-components/src/AddressInfo.tsx index 7d0df9bd92..7d5a57d5a3 100644 --- a/packages/react-components/src/AddressInfo.tsx +++ b/packages/react-components/src/AddressInfo.tsx @@ -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 { return ( <>
- {validatorPrefsDisplay.unstakeThreshold && staking_info.validatorPrefs.unstakeThreshold && ( + {validatorPrefsDisplay.unstakeThreshold && (staking_info.validatorPrefs as ValidatorPrefs0to145).unstakeThreshold && ( <>