diff --git a/package.json b/package.json index 7154f37a42..9a43a74e55 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,9 @@ "packages/*" ], "resolutions": { - "@polkadot/api": "^0.79.0-beta.23", + "@polkadot/api": "^0.79.0-beta.31", "@polkadot/keyring": "^0.91.0-beta.1", - "@polkadot/types": "^0.79.0-beta.23", + "@polkadot/types": "^0.79.0-beta.31", "@polkadot/util": "^0.91.0-beta.1", "@polkadot/util-crypto": "^0.91.0-beta.1", "babel-core": "^7.0.0-bridge.0", diff --git a/packages/app-explorer/src/BlockHeader/index.tsx b/packages/app-explorer/src/BlockHeader/index.tsx index 708169cc79..2bf73b7dac 100644 --- a/packages/app-explorer/src/BlockHeader/index.tsx +++ b/packages/app-explorer/src/BlockHeader/index.tsx @@ -8,7 +8,7 @@ import './BlockHeader.css'; import React from 'react'; import { Link } from 'react-router-dom'; -import { HeaderExtended } from '@polkadot/types'; +import { HeaderExtended } from '@polkadot/api-derive'; import { AddressMini } from '@polkadot/ui-app'; import { formatNumber } from '@polkadot/util'; diff --git a/packages/app-explorer/src/BlockHeaders.tsx b/packages/app-explorer/src/BlockHeaders.tsx index 4fd90dbdf4..803fa2f69a 100644 --- a/packages/app-explorer/src/BlockHeaders.tsx +++ b/packages/app-explorer/src/BlockHeaders.tsx @@ -5,7 +5,7 @@ import { CallProps } from '@polkadot/ui-api/types'; import React from 'react'; -import { HeaderExtended } from '@polkadot/types'; +import { HeaderExtended } from '@polkadot/api-derive'; import { withCalls } from '@polkadot/ui-api'; import BlockHeader from './BlockHeader'; diff --git a/packages/app-explorer/src/BlockInfo/ByHash.tsx b/packages/app-explorer/src/BlockInfo/ByHash.tsx index f6005d2189..78624c5ad4 100644 --- a/packages/app-explorer/src/BlockInfo/ByHash.tsx +++ b/packages/app-explorer/src/BlockInfo/ByHash.tsx @@ -6,7 +6,8 @@ import { I18nProps } from '@polkadot/ui-app/types'; import { ApiProps } from '@polkadot/ui-api/types'; import React from 'react'; -import { EventRecord, HeaderExtended, SignedBlock } from '@polkadot/types'; +import { HeaderExtended } from '@polkadot/api-derive'; +import { EventRecord, SignedBlock } from '@polkadot/types'; import { withCalls } from '@polkadot/ui-api'; import BlockHeader from '../BlockHeader'; diff --git a/packages/app-explorer/src/SummarySession.tsx b/packages/app-explorer/src/SummarySession.tsx index 6da0a13b13..b829f75c77 100644 --- a/packages/app-explorer/src/SummarySession.tsx +++ b/packages/app-explorer/src/SummarySession.tsx @@ -2,25 +2,17 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { DerivedSessionInfo } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; -import BN from 'bn.js'; import React from 'react'; -import { BlockNumber } from '@polkadot/types'; import { CardSummary } from '@polkadot/ui-app'; import { withCalls } from '@polkadot/ui-api'; import translate from './translate'; type Props = I18nProps & { - session_eraLength?: BN, - session_eraProgress?: BN, - session_sessionProgress?: BN, - // FIXME Replaced in poc-3, we should calculate the session reward - // sessionBrokenValue?: BN, - // sessionBrokenPercentLate?: BN, - session_sessionLength?: BlockNumber, - withBroken?: boolean, + session_info?: DerivedSessionInfo, withEra?: boolean, withSession?: boolean }; @@ -35,28 +27,8 @@ class SummarySession extends React.PureComponent { ); } - // private renderBroken () { - // const { sessionBrokenValue, sessionBrokenPercentLate, t, withBroken = true } = this.props; - - // if (!withBroken) { - // return null; - // } - - // return ( - // - // ); - // } - private renderEra () { - const { session_eraLength, session_eraProgress, t, withEra = true } = this.props; + const { session_info, t, withEra = true } = this.props; if (!withEra) { return null; @@ -66,15 +38,15 @@ class SummarySession extends React.PureComponent { ); } private renderSession () { - const { session_sessionProgress, session_sessionLength = new BN(0), t, withSession = true } = this.props; + const { session_info, t, withSession = true } = this.props; if (!withSession) { return null; @@ -84,8 +56,8 @@ class SummarySession extends React.PureComponent { ); @@ -94,9 +66,6 @@ class SummarySession extends React.PureComponent { export default translate( withCalls( - 'derive.session.eraLength', - 'derive.session.eraProgress', - 'derive.session.sessionProgress', - 'query.session.sessionLength' + 'derive.session.info' )(SummarySession) ); diff --git a/packages/app-staking/src/Account/Validating.tsx b/packages/app-staking/src/Account/Validating.tsx index 8d29ea5615..fbdf821571 100644 --- a/packages/app-staking/src/Account/Validating.tsx +++ b/packages/app-staking/src/Account/Validating.tsx @@ -15,8 +15,8 @@ type Props = I18nProps & { accountId: string, isOpen: boolean, onClose: () => void, - preferences: ValidatorPrefs, - stashId: string + stashId: string, + validatorPrefs: ValidatorPrefs }; type State = { @@ -37,7 +37,7 @@ class Staking extends React.PureComponent { return null; } - const { unstakeThreshold, validatorPayment } = props.preferences; + const { unstakeThreshold, validatorPayment } = props.validatorPrefs; return { unstakeThreshold: unstakeThreshold.toBn(), diff --git a/packages/app-staking/src/Account/index.tsx b/packages/app-staking/src/Account/index.tsx index b6bce12ba0..0efc414425 100644 --- a/packages/app-staking/src/Account/index.tsx +++ b/packages/app-staking/src/Account/index.tsx @@ -2,10 +2,10 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { AccountId, Balance, Exposure, Option, StakingLedger, ValidatorPrefs } from '@polkadot/types'; +import { DerivedBalancesMap, DerivedStaking } from '@polkadot/api-derive/types'; +import { AccountId, Balance, Exposure, StakingLedger, ValidatorPrefs } from '@polkadot/types'; import { ApiProps } from '@polkadot/ui-api/types'; import { AddressMini, AddressSummary, Button, TxButton } from '@polkadot/ui-app'; -import { DerivedBalancesMap } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; import { KeyringSectionOption } from '@polkadot/ui-keyring/options/types'; import React from 'react'; @@ -23,43 +23,81 @@ import Validating from './Validating'; type Props = ApiProps & I18nProps & { accountId: string, balances: DerivedBalancesMap, - controllerId?: string | null, filter: AccountFilter, isValidator: boolean, recentlyOffline: RecentlyOfflineMap, - sessionId?: string | null, - stashId?: string | null, freeBalance?: Balance, - staking_stakers?: Exposure, - staking_nominators?: [Array], - staking_validators?: [ValidatorPrefs], - stashOptions: Array, - staking_ledger?: StakingLedger + staking_info?: DerivedStaking, + stashOptions: Array }; type State = { + controllerId: string | null, + isActiveController: boolean, + isActiveSession: boolean, + isActiveStash: boolean, isBondOpen: boolean, isBondExtraOpen: boolean, isNominateOpen: boolean, isSessionKeyOpen: boolean, isValidatingOpen: boolean, - isUnbondOpen: boolean + isUnbondOpen: boolean, + nominators?: Array, + sessionId: string | null, + stakers?: Exposure, + stakingLedger?: StakingLedger, + stashId: string | null, + validatorPrefs?: ValidatorPrefs }; +function toIdString (id?: AccountId | null): string | null { + return id + ? id.toString() + : null; +} + class Account extends React.PureComponent { state: State = { + isActiveController: false, + isActiveSession: false, + isActiveStash: false, + controllerId: null, isBondOpen: false, isBondExtraOpen: false, isSessionKeyOpen: false, isNominateOpen: false, isValidatingOpen: false, - isUnbondOpen: false + isUnbondOpen: false, + sessionId: null, + stashId: null }; - render () { - const { accountId, controllerId, filter, stashId } = this.props; + static getDerivedStateFromProps ({ staking_info }: Props): State | null { + if (!staking_info) { + return null; + } - if ((filter === 'controller' && !stashId) || (filter === 'stash' && !controllerId) || (filter === 'unbonded' && (controllerId || stashId))) { + const { accountId, controllerId, nextSessionId, nominators, stakers, stakingLedger, stashId, validatorPrefs } = staking_info; + + return { + controllerId: toIdString(controllerId), + isActiveController: accountId.eq(controllerId), + isActiveSession: accountId.eq(nextSessionId), + isActiveStash: accountId.eq(stashId), + nominators, + sessionId: toIdString(nextSessionId), + stakers, + stakingLedger, + stashId: toIdString(stashId), + validatorPrefs + } as State; + } + + render () { + const { accountId, filter } = this.props; + const { controllerId, isActiveController, isActiveStash, stashId } = this.state; + + if ((filter === 'controller' && isActiveController) || (filter === 'stash' && isActiveStash) || (filter === 'unbonded' && (controllerId || stashId))) { return null; } @@ -99,8 +137,8 @@ class Account extends React.PureComponent { } private renderBond () { - const { accountId, controllerId } = this.props; - const { isBondOpen } = this.state; + const { accountId } = this.props; + const { controllerId, isBondOpen } = this.state; return ( { } private renderBondExtra () { - const { accountId, controllerId } = this.props; - const { isBondExtraOpen } = this.state; + const { accountId } = this.props; + const { controllerId, isBondExtraOpen } = this.state; return ( { } private renderUnbond () { - const { controllerId } = this.props; - const { isUnbondOpen } = this.state; + const { controllerId, isUnbondOpen } = this.state; return ( { } private renderValidating () { - const { accountId, stashId, staking_validators } = this.props; - const { isValidatingOpen } = this.state; + const { accountId } = this.props; + const { isValidatingOpen, stashId, validatorPrefs } = this.state; - if (!staking_validators || !isValidatingOpen || !stashId) { + if (!validatorPrefs || !isValidatingOpen || !stashId) { return null; } @@ -152,15 +189,15 @@ class Account extends React.PureComponent { accountId={accountId} isOpen onClose={this.toggleValidating} - preferences={staking_validators[0]} stashId={stashId} + validatorPrefs={validatorPrefs} /> ); } private renderSessionKey () { - const { accountId, stashId } = this.props; - const { isSessionKeyOpen } = this.state; + const { accountId } = this.props; + const { isSessionKeyOpen, stashId } = this.state; if (!stashId) { return null; @@ -177,9 +214,10 @@ class Account extends React.PureComponent { } private renderNominee () { - const { recentlyOffline, staking_nominators, t } = this.props; + const { recentlyOffline, t } = this.props; + const { nominators } = this.state; - if (!staking_nominators || !staking_nominators[0] || !staking_nominators[0].length) { + if (!nominators || !nominators.length) { return null; } @@ -187,7 +225,7 @@ class Account extends React.PureComponent {
{ - staking_nominators[0].map((nomineeId, index) => ( + nominators.map((nomineeId, index) => ( { } private renderControllerId () { - const { controllerId, recentlyOffline, t } = this.props; + const { recentlyOffline, t } = this.props; + const { controllerId, isActiveController } = this.state; - if (!controllerId) { + if (!controllerId || isActiveController) { return null; } @@ -220,9 +259,10 @@ class Account extends React.PureComponent { } private renderSessionId () { - const { sessionId, t } = this.props; + const { t } = this.props; + const { isActiveSession, sessionId } = this.state; - if (!sessionId) { + if (!sessionId || isActiveSession) { return null; } @@ -235,9 +275,10 @@ class Account extends React.PureComponent { } private renderStashId () { - const { recentlyOffline, stashId, t } = this.props; + const { recentlyOffline, t } = this.props; + const { isActiveStash, stashId } = this.state; - if (!stashId) { + if (!stashId || isActiveStash) { return null; } @@ -255,8 +296,8 @@ class Account extends React.PureComponent { } private renderNominating () { - const { accountId, stashId, stashOptions } = this.props; - const { isNominateOpen } = this.state; + const { accountId, stashOptions } = this.props; + const { isNominateOpen, stashId } = this.state; if (!stashId) { return null; @@ -274,50 +315,42 @@ class Account extends React.PureComponent { } private renderButtons () { - const { accountId, controllerId, sessionId, staking_nominators, staking_validators, stashId, freeBalance, staking_ledger, t } = this.props; + const { accountId, freeBalance, t } = this.props; + const { isActiveStash, isActiveController, nominators, sessionId, stakingLedger, validatorPrefs } = this.state; const buttons = []; - if (!stashId) { - if (!controllerId) { + if (isActiveStash) { + // only show a "Bond Additional" button if this stash account actually doesn't bond everything already + // staking_ledger.total gives the total amount that can be slashed (any active amount + what is being unlocked) + if (freeBalance && stakingLedger && stakingLedger.total && (freeBalance.gt(stakingLedger.total))) { buttons.push(