diff --git a/package.json b/package.json index d255f5af9d..4ee39bd608 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.31.0-beta.40", + "version": "0.31.0-beta.42", "private": true, "engines": { "node": ">=10.13.0", diff --git a/packages/app-staking/src/Overview/Address.tsx b/packages/app-staking/src/Overview/Address.tsx index 8aa507eab5..c44e508eef 100644 --- a/packages/app-staking/src/Overview/Address.tsx +++ b/packages/app-staking/src/Overview/Address.tsx @@ -4,10 +4,10 @@ import { DerivedBalancesMap } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; -import { Nominators, RecentlyOfflineMap } from '../types'; +import { RecentlyOfflineMap } from '../types'; import React from 'react'; -import { AccountId, Option, StakingLedger } from '@polkadot/types'; +import { AccountId, Balance, Option, StakingLedger, Exposure } from '@polkadot/types'; import { withCalls, withMulti } from '@polkadot/ui-api/with'; import { AddressMini, AddressRow, RecentlyOffline } from '@polkadot/ui-app'; import { getAddrName } from '@polkadot/ui-app/util'; @@ -21,18 +21,18 @@ type Props = I18nProps & { defaultName: string, lastAuthor: string, lastBlock: string, - nominators: Nominators, recentlyOffline: RecentlyOfflineMap, session_nextKeyFor?: Option, staking_bonded?: Option, - staking_ledger?: Option + staking_ledger?: Option, + staking_stakers?: Exposure, + stashId?: string | null }; type State = { controllerId: string, stashActive: string | null, stashTotal: string | null, - stashId: string | null, sessionId: string | null, badgeExpanded: boolean; }; @@ -48,7 +48,6 @@ class Address extends React.PureComponent { sessionId: null, stashActive: null, stashTotal: null, - stashId: null, badgeExpanded: false }; } @@ -57,6 +56,7 @@ class Address extends React.PureComponent { const ledger = staking_ledger ? staking_ledger.unwrapOr(null) : null; + return { controllerId: !staking_bonded || staking_bonded.isNone ? prevState.controllerId @@ -69,24 +69,24 @@ class Address extends React.PureComponent { : formatBalance(ledger.active), stashTotal: !ledger ? prevState.stashTotal - : formatBalance(ledger.total), - stashId: !ledger - ? prevState.stashId - : ledger.stash.toString() + : formatBalance(ledger.total) } as State; } render () { - const { address, lastAuthor, lastBlock } = this.props; - const { controllerId, stashActive, stashId } = this.state; + const { address, lastAuthor, lastBlock, stashId, staking_stakers } = this.props; + const { controllerId } = 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)] + : undefined; return (
{ {this.renderOffline()} { - isAuthor + isAuthor && stashId ?
#{lastBlock}
: null } @@ -106,8 +106,7 @@ class Address extends React.PureComponent { } private getDisplayName = (): string | undefined => { - const { defaultName } = this.props; - const { stashId } = this.state; + const { defaultName, stashId } = this.props; if (!stashId) { return defaultName; @@ -150,15 +149,12 @@ class Address extends React.PureComponent { } private renderNominators () { - const { nominators, t } = this.props; - const { stashId } = this.state; - const myNominators = stashId - ? Object.keys(nominators).filter((nominator) => - nominators[nominator].indexOf(stashId) !== -1 - ) + const { staking_stakers, t } = this.props; + const nominators = staking_stakers + ? staking_stakers.others.map(({ who, value }): [AccountId, Balance] => [who, value]) : []; - if (!myNominators.length) { + if (!nominators.length) { return null; } @@ -167,14 +163,15 @@ class Address extends React.PureComponent { {t('Nominators ({{count}})', { replace: { - count: myNominators.length + count: nominators.length } })} - {myNominators.map((accountId) => + {nominators.map(([who, bonded]) => )} @@ -183,8 +180,7 @@ class Address extends React.PureComponent { } private renderOffline () { - const { recentlyOffline } = this.props; - const { stashId } = this.state; + const { recentlyOffline, stashId } = this.props; if (!stashId || !recentlyOffline[stashId]) { return null; @@ -206,8 +202,15 @@ export default withMulti( Address, translate, withCalls( + ['query.staking.bonded', { paramName: 'address' }], ['query.session.nextKeyFor', { paramName: 'address' }], ['query.staking.ledger', { paramName: 'address' }], - ['query.staking.bonded', { paramName: 'address' }] + ['query.staking.ledger', { + paramName: 'address', + propName: 'stashId', + transform: (ledger: Option) => + ledger.unwrapOr({ stash: { toString: () => { return null; } } }).stash.toString() + }], + ['query.staking.stakers', { paramName: 'stashId' }] ) ); diff --git a/packages/app-staking/src/Overview/CurrentList.tsx b/packages/app-staking/src/Overview/CurrentList.tsx index dda062053b..bcd65d12d7 100644 --- a/packages/app-staking/src/Overview/CurrentList.tsx +++ b/packages/app-staking/src/Overview/CurrentList.tsx @@ -4,7 +4,7 @@ import { DerivedBalancesMap } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; -import { Nominators, RecentlyOfflineMap } from '../types'; +import { RecentlyOfflineMap } from '../types'; import React from 'react'; @@ -17,7 +17,6 @@ type Props = I18nProps & { lastAuthor?: string, lastBlock: string, next: Array, - nominators: Nominators, recentlyOffline: RecentlyOfflineMap }; @@ -64,7 +63,7 @@ class CurrentList extends React.PureComponent { } private renderColumn (addresses: Array, defaultName: string) { - const { balances, lastAuthor, lastBlock, nominators, recentlyOffline, t } = this.props; + const { balances, lastAuthor, lastBlock, recentlyOffline, t } = this.props; if (addresses.length === 0) { return ( @@ -82,7 +81,6 @@ class CurrentList extends React.PureComponent { key={address} lastAuthor={lastAuthor} lastBlock={lastBlock} - nominators={nominators} recentlyOffline={recentlyOffline} /> ))} diff --git a/packages/app-staking/src/Overview/index.tsx b/packages/app-staking/src/Overview/index.tsx index 6c84cd1c94..cc6179f56a 100644 --- a/packages/app-staking/src/Overview/index.tsx +++ b/packages/app-staking/src/Overview/index.tsx @@ -23,7 +23,7 @@ const ZERO = new Balance(0); class Overview extends React.PureComponent { render () { - const { balances, chain_subscribeNewHead, controllers, nominators, recentlyOffline, validators } = this.props; + const { balances, chain_subscribeNewHead, controllers, recentlyOffline, validators } = this.props; const nextSorted = this.sortByBalance( controllers.filter((address) => !validators.includes(address) @@ -54,7 +54,6 @@ class Overview extends React.PureComponent { lastBlock={lastBlock} lastAuthor={lastAuthor} next={nextSorted} - nominators={nominators} recentlyOffline={recentlyOffline} /> diff --git a/packages/app-staking/src/index.tsx b/packages/app-staking/src/index.tsx index 746eb324a3..20e8fcab29 100644 --- a/packages/app-staking/src/index.tsx +++ b/packages/app-staking/src/index.tsx @@ -6,7 +6,7 @@ import { DerivedBalancesMap } from '@polkadot/api-derive/types'; import { AppProps, I18nProps } from '@polkadot/ui-app/types'; import { ApiProps } from '@polkadot/ui-api/types'; import { SubjectInfo } from '@polkadot/ui-keyring/observable/types'; -import { ComponentProps, Nominators, RecentlyOffline, RecentlyOfflineMap } from './types'; +import { ComponentProps, RecentlyOffline, RecentlyOfflineMap } from './types'; import React from 'react'; import { Route, Switch } from 'react-router'; @@ -28,13 +28,11 @@ type Props = AppProps & ApiProps & I18nProps & { balances?: DerivedBalancesMap, session_validators?: Array, staking_controllers?: [Array, Array>], - staking_nominators?: [Array, Array>], staking_recentlyOffline?: RecentlyOffline }; type State = { controllers: Array, - nominators: Nominators, recentlyOffline: RecentlyOfflineMap, stashes: Array, tabs: Array, @@ -51,7 +49,6 @@ class App extends React.PureComponent { this.state = { controllers: [], - nominators: {}, recentlyOffline: {}, stashes: [], tabs: [ @@ -68,18 +65,11 @@ class App extends React.PureComponent { }; } - static getDerivedStateFromProps ({ staking_controllers = [[], []], session_validators = [], staking_nominators = [[], []], staking_recentlyOffline = [] }: Props): State { + static getDerivedStateFromProps ({ staking_controllers = [[], []], session_validators = [], staking_recentlyOffline = [] }: Props): State { return { controllers: staking_controllers[1].filter((optId) => optId.isSome).map((accountId) => accountId.unwrap().toString() ), - nominators: staking_nominators[0].reduce((result, accountId, index) => { - result[accountId.toString()] = staking_nominators[1][index].map((accountId) => - accountId.toString() - ); - - return result; - }, {} as Nominators), stashes: staking_controllers[0].map((accountId) => accountId.toString()), validators: session_validators.map((authorityId) => authorityId.toString() @@ -129,14 +119,13 @@ class App extends React.PureComponent { private renderComponent (Component: React.ComponentType) { return (): React.ReactNode => { - const { controllers, nominators, recentlyOffline, stashes, validators } = this.state; + const { controllers, recentlyOffline, stashes, validators } = this.state; const { balances = {} } = this.props; return ( ( 'derive.staking.controllers', 'query.session.validators', - 'query.staking.nominators', 'query.staking.recentlyOffline' ), withObservable(accountObservable.subject, { propName: 'allAccounts' }) diff --git a/packages/app-staking/src/types.ts b/packages/app-staking/src/types.ts index 33ecb92225..e8ac59faa9 100644 --- a/packages/app-staking/src/types.ts +++ b/packages/app-staking/src/types.ts @@ -14,7 +14,6 @@ export type Nominators = { export type ComponentProps = { balances: DerivedBalancesMap, controllers: Array, - nominators: Nominators, recentlyOffline: RecentlyOfflineMap, stashes: Array, validators: Array diff --git a/packages/ui-app/src/AddressMini.tsx b/packages/ui-app/src/AddressMini.tsx index 23f2f10884..65a094d178 100644 --- a/packages/ui-app/src/AddressMini.tsx +++ b/packages/ui-app/src/AddressMini.tsx @@ -6,7 +6,7 @@ import { BareProps } from './types'; import BN from 'bn.js'; import React from 'react'; -import { AccountId, AccountIndex, Address, Balance } from '@polkadot/types'; +import { AccountId, AccountIndex, Address } from '@polkadot/types'; import { OfflineStatus } from '@polkadot/app-staking/types'; import { RecentlyOffline } from '@polkadot/ui-app'; @@ -16,7 +16,8 @@ import BondedDisplay from './Bonded'; import IdentityIcon from './IdentityIcon'; type Props = BareProps & { - balance?: Balance | Array | BN, + balance?: BN | Array, + bonded?: BN | Array, children?: React.ReactNode, isPadded?: boolean, isShort?: boolean, @@ -94,7 +95,7 @@ export default class AddressMini extends React.PureComponent { } private renderBonded () { - const { value, withBonded = false } = this.props; + const { bonded, value, withBonded = false } = this.props; if (!withBonded || !value) { return null; @@ -102,6 +103,7 @@ export default class AddressMini extends React.PureComponent { return ( , - bonded?: Balance | Array, + balance?: BN | Array, + bonded?: BN | Array, children?: React.ReactNode, extraInfo?: React.ReactNode, name?: string, @@ -155,7 +156,7 @@ class AddressSummary extends React.PureComponent { } protected renderBonded () { - const { accounts_idAndIndex = [], t, value, withBonded } = this.props; + const { accounts_idAndIndex = [], bonded, t, value, withBonded } = this.props; const [_accountId] = accounts_idAndIndex; const accountId = _accountId || value; @@ -165,6 +166,7 @@ class AddressSummary extends React.PureComponent { return ( | BN, + balance?: BN | Array, label?: string, params?: AccountId | AccountIndex | Address | string | Uint8Array | null, withLabel?: boolean @@ -30,7 +30,7 @@ export default class BalanceDisplay extends React.PureComponent { return balance ? this.renderProvided() : ( - { private renderProvided () { const { balance, className, label, style } = this.props; - - if (!balance) { - return null; - } - let value = `${formatBalance(Array.isArray(balance) ? balance[0] : balance)}`; if (Array.isArray(balance)) { diff --git a/packages/ui-app/src/Bonded.tsx b/packages/ui-app/src/Bonded.tsx index e0ee752496..7fabd7f734 100644 --- a/packages/ui-app/src/Bonded.tsx +++ b/packages/ui-app/src/Bonded.tsx @@ -4,13 +4,16 @@ import { BareProps } from './types'; +import BN from 'bn.js'; import React from 'react'; import { AccountId, AccountIndex, Address } from '@polkadot/types'; -import RxBonded from '@polkadot/ui-reactive/Bonded'; +import { formatBalance } from '@polkadot/util'; +import { Bonded } from '@polkadot/ui-reactive'; import { classes } from './util'; export type Props = BareProps & { + bonded?: BN | Array, label?: string, params?: AccountId | AccountIndex | Address | string | Uint8Array | null, withLabel?: boolean @@ -18,19 +21,44 @@ export type Props = BareProps & { export default class BondedDisplay extends React.PureComponent { render () { - const { params, className, label, style } = this.props; + const { bonded, params, className, label, style } = this.props; if (!params) { return null; } + return bonded + ? this.renderProvided() + : ( + + ); + } + + private renderProvided () { + const { bonded, className, label, style } = this.props; + let value = `${formatBalance(Array.isArray(bonded) ? bonded[0] : bonded)}`; + + if (Array.isArray(bonded)) { + const totals = bonded.filter((value, index) => index !== 0); + const total = totals.reduce((total, value) => total.add(value), new BN(0)).gtn(0) + ? `(+${totals.map((bonded) => formatBalance(bonded)).join(', ')})` + : ''; + + value = `${value} ${total}`; + } + return ( - + > + {label}{value} + ); } } diff --git a/packages/ui-reactive/src/index.ts b/packages/ui-reactive/src/index.ts index 3e058dfdb8..e345eef166 100644 --- a/packages/ui-reactive/src/index.ts +++ b/packages/ui-reactive/src/index.ts @@ -4,6 +4,7 @@ export { default as AccountIndex } from './AccountIndex'; export { default as Balance } from './Balance'; +export { default as Bonded } from './Bonded'; export { default as BestFinalized } from './BestFinalized'; export { default as BestNumber } from './BestNumber'; export { default as Chain } from './Chain';