Convert to new api.derive (multi-query) functions (#1173)
* Convert to new api.derive functions * Ensure stashId passed-through * Bump api * Update validation details * Lint fixes * Bump API * Drop linked nominator query
This commit is contained in:
parent
e8c15e7a69
commit
a86f8231d5
@ -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",
|
||||
|
||||
@ -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';
|
||||
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
// private renderBroken () {
|
||||
// const { sessionBrokenValue, sessionBrokenPercentLate, t, withBroken = true } = this.props;
|
||||
|
||||
// if (!withBroken) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// return (
|
||||
// <CardSummary
|
||||
// label={t('lateness')}
|
||||
// progress={{
|
||||
// color: 'autoReverse',
|
||||
// isPercent: true,
|
||||
// total: sessionBrokenPercentLate,
|
||||
// value: sessionBrokenValue
|
||||
// }}
|
||||
// />
|
||||
// );
|
||||
// }
|
||||
|
||||
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<Props> {
|
||||
<CardSummary
|
||||
label={t('era')}
|
||||
progress={{
|
||||
total: session_eraLength,
|
||||
value: session_eraProgress
|
||||
total: session_info && session_info.eraLength,
|
||||
value: session_info && session_info.eraProgress
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
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<Props> {
|
||||
<CardSummary
|
||||
label={t('session')}
|
||||
progress={{
|
||||
total: session_sessionLength,
|
||||
value: session_sessionProgress
|
||||
total: session_info && session_info.sessionLength,
|
||||
value: session_info && session_info.sessionProgress
|
||||
}}
|
||||
/>
|
||||
);
|
||||
@ -94,9 +66,6 @@ class SummarySession extends React.PureComponent<Props> {
|
||||
|
||||
export default translate(
|
||||
withCalls<Props>(
|
||||
'derive.session.eraLength',
|
||||
'derive.session.eraProgress',
|
||||
'derive.session.sessionProgress',
|
||||
'query.session.sessionLength'
|
||||
'derive.session.info'
|
||||
)(SummarySession)
|
||||
);
|
||||
|
||||
@ -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<Props, State> {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { unstakeThreshold, validatorPayment } = props.preferences;
|
||||
const { unstakeThreshold, validatorPayment } = props.validatorPrefs;
|
||||
|
||||
return {
|
||||
unstakeThreshold: unstakeThreshold.toBn(),
|
||||
|
||||
@ -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<AccountId>],
|
||||
staking_validators?: [ValidatorPrefs],
|
||||
stashOptions: Array<KeyringSectionOption>,
|
||||
staking_ledger?: StakingLedger
|
||||
staking_info?: DerivedStaking,
|
||||
stashOptions: Array<KeyringSectionOption>
|
||||
};
|
||||
|
||||
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<AccountId>,
|
||||
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<Props, State> {
|
||||
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<Props, State> {
|
||||
}
|
||||
|
||||
private renderBond () {
|
||||
const { accountId, controllerId } = this.props;
|
||||
const { isBondOpen } = this.state;
|
||||
const { accountId } = this.props;
|
||||
const { controllerId, isBondOpen } = this.state;
|
||||
|
||||
return (
|
||||
<Bond
|
||||
@ -113,8 +151,8 @@ class Account extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
private renderBondExtra () {
|
||||
const { accountId, controllerId } = this.props;
|
||||
const { isBondExtraOpen } = this.state;
|
||||
const { accountId } = this.props;
|
||||
const { controllerId, isBondExtraOpen } = this.state;
|
||||
|
||||
return (
|
||||
<BondExtra
|
||||
@ -127,8 +165,7 @@ class Account extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
private renderUnbond () {
|
||||
const { controllerId } = this.props;
|
||||
const { isUnbondOpen } = this.state;
|
||||
const { controllerId, isUnbondOpen } = this.state;
|
||||
|
||||
return (
|
||||
<Unbond
|
||||
@ -140,10 +177,10 @@ class Account extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
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<Props, State> {
|
||||
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<Props, State> {
|
||||
}
|
||||
|
||||
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<Props, State> {
|
||||
<div className='staking--Account-detail'>
|
||||
<label className='staking--label'>{t('nominating')}</label>
|
||||
{
|
||||
staking_nominators[0].map((nomineeId, index) => (
|
||||
nominators.map((nomineeId, index) => (
|
||||
<AddressMini
|
||||
key={index}
|
||||
value={nomineeId}
|
||||
@ -202,9 +240,10 @@ class Account extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
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<Props, State> {
|
||||
}
|
||||
|
||||
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<Props, State> {
|
||||
}
|
||||
|
||||
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<Props, State> {
|
||||
}
|
||||
|
||||
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<Props, State> {
|
||||
}
|
||||
|
||||
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(
|
||||
<Button
|
||||
isPrimary
|
||||
key='bond'
|
||||
onClick={this.toggleBond}
|
||||
label={t('Bond Funds')}
|
||||
onClick={this.toggleBondExtra}
|
||||
label={t('Bond Additional')}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
// 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 && staking_ledger && staking_ledger.total && (freeBalance.gt(staking_ledger.total))) {
|
||||
buttons.push(
|
||||
<Button
|
||||
isPrimary
|
||||
key='bond'
|
||||
onClick={this.toggleBondExtra}
|
||||
label={t('Bond Additional')}
|
||||
/>
|
||||
);
|
||||
}
|
||||
// don't show the `unbond` button if there's nothing to unbond
|
||||
// staking_ledger.active gives the amount that can be unbonded (total - what's being unlocked).
|
||||
if (staking_ledger && staking_ledger.active && staking_ledger.active.gtn(0)) {
|
||||
buttons.length && buttons.push(<Button.Or key='bondAdditional.or' />);
|
||||
buttons.push(
|
||||
<Button
|
||||
isNegative
|
||||
key='unbond'
|
||||
onClick={this.toggleUnbond}
|
||||
label={t('Unbond')}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const isNominating = !!staking_nominators && !!staking_nominators[0] && staking_nominators[0].length;
|
||||
const isValidating = !!staking_validators && !!staking_validators[0] && !(staking_validators[0].isEmpty);
|
||||
|
||||
// don't show the `unbond` button if there's nothing to unbond
|
||||
// staking_ledger.active gives the amount that can be unbonded (total - what's being unlocked).
|
||||
if (stakingLedger && stakingLedger.active && stakingLedger.active.gtn(0)) {
|
||||
buttons.length && buttons.push(<Button.Or key='bondAdditional.or' />);
|
||||
buttons.push(
|
||||
<Button
|
||||
isNegative
|
||||
key='unbond'
|
||||
onClick={this.toggleUnbond}
|
||||
label={t('Unbond')}
|
||||
/>
|
||||
);
|
||||
}
|
||||
} else if (isActiveController) {
|
||||
const isNominating = !!nominators && nominators.length;
|
||||
const isValidating = !!validatorPrefs && !validatorPrefs.isEmpty;
|
||||
|
||||
// if we are validating/nominating show stop
|
||||
if (isValidating || isNominating) {
|
||||
buttons.push(
|
||||
<TxButton
|
||||
@ -352,6 +385,7 @@ class Account extends React.PureComponent<Props, State> {
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
buttons.push(<Button.Or key='nominate.or' />);
|
||||
buttons.push(
|
||||
<Button
|
||||
@ -362,6 +396,16 @@ class Account extends React.PureComponent<Props, State> {
|
||||
/>
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// we have nothing here, show the bond to get started
|
||||
buttons.push(
|
||||
<Button
|
||||
isPrimary
|
||||
key='bond'
|
||||
onClick={this.toggleBond}
|
||||
label={t('Bond Funds')}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
@ -408,44 +452,13 @@ class Account extends React.PureComponent<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
function toIdString (id: AccountId | null): string | null {
|
||||
return id
|
||||
? id.toString()
|
||||
: null;
|
||||
}
|
||||
|
||||
export default translate(
|
||||
withCalls<Props>(
|
||||
['derive.staking.info', { paramName: 'accountId' }],
|
||||
'query.staking.recentlyOffline',
|
||||
['query.session.nextKeyFor', {
|
||||
paramName: 'accountId',
|
||||
propName: 'sessionId',
|
||||
transform: (session: Option<AccountId>) =>
|
||||
toIdString(session.unwrapOr(null))
|
||||
}],
|
||||
['query.staking.bonded', {
|
||||
paramName: 'accountId',
|
||||
propName: 'controllerId',
|
||||
transform: (bonded: Option<AccountId>) =>
|
||||
toIdString(bonded.unwrapOr(null))
|
||||
}],
|
||||
['query.staking.ledger', {
|
||||
paramName: 'accountId',
|
||||
propName: 'stashId',
|
||||
transform: (ledger: Option<StakingLedger>) =>
|
||||
toIdString(ledger.unwrapOr({ stash: null }).stash)
|
||||
}],
|
||||
['query.staking.ledger', {
|
||||
paramName: 'controllerId',
|
||||
transform: (ledger: Option<StakingLedger>) =>
|
||||
ledger.unwrapOr({ stash: null, total: null, active: null })
|
||||
}],
|
||||
['query.balances.freeBalance', {
|
||||
paramName: 'accountId',
|
||||
propName: 'freeBalance'
|
||||
}],
|
||||
['query.staking.stakers', { paramName: 'accountId' }],
|
||||
['query.staking.nominators', { paramName: 'stashId' }],
|
||||
['query.staking.validators', { paramName: 'stashId' }]
|
||||
}]
|
||||
)(Account)
|
||||
);
|
||||
|
||||
@ -2,16 +2,16 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { DerivedBalancesMap } from '@polkadot/api-derive/types';
|
||||
import { DerivedBalancesMap, DerivedStaking } from '@polkadot/api-derive/types';
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { ValidatorFilter, RecentlyOfflineMap } from '../types';
|
||||
|
||||
import React from 'react';
|
||||
import { AccountId, Balance, Option, StakingLedger, Exposure } from '@polkadot/types';
|
||||
import { AccountId, Balance, Exposure } from '@polkadot/types';
|
||||
import { withCalls, withMulti } from '@polkadot/ui-api/with';
|
||||
import { AddressMini, AddressRow, RecentlyOffline } from '@polkadot/ui-app';
|
||||
import { formatBalance } from '@polkadot/util';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
import { formatBalance } from '@polkadot/util';
|
||||
|
||||
import translate from '../translate';
|
||||
|
||||
@ -23,11 +23,7 @@ type Props = I18nProps & {
|
||||
lastBlock: string,
|
||||
recentlyOffline: RecentlyOfflineMap,
|
||||
filter: ValidatorFilter,
|
||||
session_nextKeyFor?: Option<AccountId>,
|
||||
staking_bonded?: Option<AccountId>,
|
||||
staking_ledger?: Option<StakingLedger>,
|
||||
staking_stakers?: Exposure,
|
||||
stashId?: string | null
|
||||
staking_info?: DerivedStaking
|
||||
};
|
||||
|
||||
type State = {
|
||||
@ -35,6 +31,8 @@ type State = {
|
||||
stashActive: string | null,
|
||||
stashTotal: string | null,
|
||||
sessionId: string | null,
|
||||
stakers?: Exposure,
|
||||
stashId: string | null,
|
||||
badgeExpanded: boolean;
|
||||
};
|
||||
|
||||
@ -48,38 +46,39 @@ class Address extends React.PureComponent<Props, State> {
|
||||
controllerId: props.address,
|
||||
sessionId: null,
|
||||
stashActive: null,
|
||||
stashId: null,
|
||||
stashTotal: null,
|
||||
badgeExpanded: false
|
||||
};
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps ({ session_nextKeyFor, staking_bonded, staking_ledger }: Props, prevState: State): State | null {
|
||||
const ledger = staking_ledger
|
||||
? staking_ledger.unwrapOr(null)
|
||||
: null;
|
||||
static getDerivedStateFromProps ({ staking_info }: Props, prevState: State): State | null {
|
||||
if (!staking_info) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { controllerId, nextSessionId, stakers, stashId, stakingLedger } = staking_info;
|
||||
|
||||
return {
|
||||
controllerId: !staking_bonded || staking_bonded.isNone
|
||||
? prevState.controllerId
|
||||
: staking_bonded.unwrap().toString(),
|
||||
sessionId: !session_nextKeyFor || session_nextKeyFor.isNone
|
||||
? prevState.sessionId
|
||||
: session_nextKeyFor.unwrap().toString(),
|
||||
stashActive: !ledger
|
||||
? prevState.stashActive
|
||||
: formatBalance(ledger.active),
|
||||
stashTotal: !ledger
|
||||
? prevState.stashTotal
|
||||
: formatBalance(ledger.total)
|
||||
controllerId: controllerId && controllerId.toString(),
|
||||
sessionId: nextSessionId && nextSessionId.toString(),
|
||||
stashActive: stakingLedger
|
||||
? formatBalance(stakingLedger.active)
|
||||
: prevState.stashActive,
|
||||
stakers,
|
||||
stashId: stashId && stashId.toString(),
|
||||
stashTotal: stakingLedger
|
||||
? formatBalance(stakingLedger.total)
|
||||
: prevState.stashTotal
|
||||
} as State;
|
||||
}
|
||||
|
||||
render () {
|
||||
const { address, defaultName, lastAuthor, lastBlock, stashId, staking_stakers, filter } = this.props;
|
||||
const { controllerId } = this.state;
|
||||
const { address, defaultName, lastAuthor, lastBlock, filter } = this.props;
|
||||
const { controllerId, stakers, stashId } = this.state;
|
||||
const isAuthor = [address, controllerId, stashId].includes(lastAuthor);
|
||||
const bonded = staking_stakers && !staking_stakers.own.isZero()
|
||||
? [staking_stakers.own, staking_stakers.total.sub(staking_stakers.own)]
|
||||
const bonded = stakers && !stakers.own.isZero()
|
||||
? [stakers.own, stakers.total.sub(stakers.own)]
|
||||
: undefined;
|
||||
|
||||
if ((filter === 'hasNominators' && !this.hasNominators())
|
||||
@ -95,7 +94,7 @@ class Address extends React.PureComponent<Props, State> {
|
||||
<AddressRow
|
||||
bonded={bonded}
|
||||
defaultName={defaultName}
|
||||
value={stashId || null}
|
||||
value={stashId}
|
||||
withBalance={false}
|
||||
withBonded
|
||||
withCopy={false}
|
||||
@ -148,18 +147,22 @@ class Address extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
private getNominators () {
|
||||
const { staking_stakers } = this.props;
|
||||
const { stakers } = this.state;
|
||||
|
||||
return staking_stakers
|
||||
? staking_stakers.others.map(({ who, value }): [AccountId, Balance] => [who, value])
|
||||
return stakers
|
||||
? stakers.others.map(({ who, value }): [AccountId, Balance] => [who, value])
|
||||
: [];
|
||||
}
|
||||
|
||||
private iNominated () {
|
||||
const nominators = this.getNominators();
|
||||
const myAddresses = keyring.getAccounts().map(acc => acc.address());
|
||||
const myAddresses = keyring.getAccounts().map((acc) =>
|
||||
acc.address()
|
||||
);
|
||||
|
||||
return nominators.filter(([who, value]) => myAddresses.includes(who.toString())).length > 0;
|
||||
return nominators.some(([who]) =>
|
||||
myAddresses.includes(who.toString())
|
||||
);
|
||||
}
|
||||
|
||||
private hasNominators () {
|
||||
@ -169,7 +172,8 @@ class Address extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
private hasWarnings () {
|
||||
const { recentlyOffline, stashId } = this.props;
|
||||
const { recentlyOffline } = this.props;
|
||||
const { stashId } = this.state;
|
||||
|
||||
if (!stashId || !recentlyOffline[stashId]) {
|
||||
return false;
|
||||
@ -208,7 +212,8 @@ class Address extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
private renderOffline () {
|
||||
const { recentlyOffline, stashId } = this.props;
|
||||
const { recentlyOffline } = this.props;
|
||||
const { stashId } = this.state;
|
||||
|
||||
if (!stashId || !recentlyOffline[stashId]) {
|
||||
return null;
|
||||
@ -230,15 +235,6 @@ export default withMulti(
|
||||
Address,
|
||||
translate,
|
||||
withCalls<Props>(
|
||||
['query.staking.bonded', { paramName: 'address' }],
|
||||
['query.session.nextKeyFor', { paramName: 'address' }],
|
||||
['query.staking.ledger', { paramName: 'address' }],
|
||||
['query.staking.ledger', {
|
||||
paramName: 'address',
|
||||
propName: 'stashId',
|
||||
transform: (ledger: Option<StakingLedger>) =>
|
||||
ledger.unwrapOr({ stash: { toString: () => { return null; } } }).stash.toString()
|
||||
}],
|
||||
['query.staking.stakers', { paramName: 'stashId' }]
|
||||
['derive.staking.info', { paramName: 'address' }]
|
||||
)
|
||||
);
|
||||
|
||||
@ -18,7 +18,6 @@ type Props = I18nProps & {
|
||||
controllers: Array<string>,
|
||||
lastAuthor?: string,
|
||||
lastBlock: string,
|
||||
lastLengthChange?: BN,
|
||||
staking_validatorCount?: BN,
|
||||
validators: Array<string>
|
||||
};
|
||||
@ -56,7 +55,7 @@ class Summary extends React.PureComponent<Props> {
|
||||
</CardSummary>
|
||||
</section>
|
||||
<section>
|
||||
<SummarySession withBroken={false} />
|
||||
<SummarySession />
|
||||
</section>
|
||||
</SummaryBox>
|
||||
);
|
||||
|
||||
@ -2,13 +2,14 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Balance, HeaderExtended } from '@polkadot/types';
|
||||
import { Balance } from '@polkadot/types';
|
||||
import { BareProps } from '@polkadot/ui-app/types';
|
||||
import { ComponentProps } from '../types';
|
||||
|
||||
import './index.css';
|
||||
|
||||
import React from 'react';
|
||||
import { HeaderExtended } from '@polkadot/api-derive';
|
||||
import { withCalls, withMulti } from '@polkadot/ui-api/with';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
|
||||
@ -99,11 +99,11 @@ export default withMulti(
|
||||
withCalls<Props>(
|
||||
'derive.accounts.indexes',
|
||||
'derive.balances.fees',
|
||||
// This is a very ineffective query that
|
||||
'query.session.validators'
|
||||
// This are very ineffective queries that
|
||||
// (a) adds load to the RPC node when activated globally
|
||||
// (b) is used in additional information (next-up)
|
||||
// 'derive.staking.controllers',
|
||||
'query.staking.nominators',
|
||||
'query.session.validators'
|
||||
// 'derive.staking.controllers'
|
||||
// 'query.staking.nominators'
|
||||
)
|
||||
);
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.4.4",
|
||||
"@polkadot/api": "^0.79.0-beta.23",
|
||||
"@polkadot/api": "^0.79.0-beta.31",
|
||||
"rxjs-compat": "^6.4.0"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user