From f9f5b39a0e5424d785729fb297b3a0fe95d42dd6 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 8 Apr 2019 00:15:33 +0200 Subject: [PATCH] Display bonded amount on overview (#915) --- packages/app-staking/src/Overview/Address.tsx | 27 ++++++++++++++----- packages/ui-app/src/AddressRow.tsx | 1 + packages/ui-app/src/AddressSummary.tsx | 16 +++++++++++ packages/ui-app/src/styles/components.css | 1 + 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/packages/app-staking/src/Overview/Address.tsx b/packages/app-staking/src/Overview/Address.tsx index f3d85c54c0..80227f0bdf 100644 --- a/packages/app-staking/src/Overview/Address.tsx +++ b/packages/app-staking/src/Overview/Address.tsx @@ -12,7 +12,7 @@ import { AccountId, Balance, Option, StakingLedger } from '@polkadot/types'; import { withCalls, withMulti } from '@polkadot/ui-api/with'; import { AddressMini, AddressRow } from '@polkadot/ui-app'; import keyring from '@polkadot/ui-keyring'; -import { formatNumber } from '@polkadot/util'; +import { formatBalance, formatNumber } from '@polkadot/util'; import translate from '../translate'; @@ -32,6 +32,8 @@ type Props = I18nProps & { type State = { bondedId: string, + stashActive: string | null, + stashTotal: string | null, stashId: string | null, sessionId: string | null, badgeExpanded: boolean; @@ -46,12 +48,17 @@ class Address extends React.PureComponent { this.state = { bondedId: props.address, sessionId: null, + stashActive: null, + stashTotal: null, stashId: null, badgeExpanded: false }; } - static getDerivedStateFromProps ({ address, session_nextKeyFor, staking_bonded, staking_ledger }: Props, prevState: State): State | null { + static getDerivedStateFromProps ({ session_nextKeyFor, staking_bonded, staking_ledger }: Props, prevState: State): State | null { + const ledger = staking_ledger + ? staking_ledger.unwrapOr(null) + : null; return { bondedId: !staking_bonded || staking_bonded.isNone ? prevState.bondedId @@ -59,20 +66,26 @@ class Address extends React.PureComponent { sessionId: !session_nextKeyFor || session_nextKeyFor.isNone ? prevState.sessionId : session_nextKeyFor.unwrap().toString(), - stashId: !staking_ledger || staking_ledger.isNone + stashActive: !ledger + ? prevState.stashActive + : formatBalance(ledger.active), + stashTotal: !ledger + ? prevState.stashTotal + : formatBalance(ledger.total), + stashId: !ledger ? prevState.stashId - : staking_ledger.unwrap().stash.toString() + : ledger.stash.toString() } as State; } render () { - const { balanceArray, isAuthor, lastBlock } = this.props; - const { bondedId, stashId } = this.state; + const { isAuthor, lastBlock } = this.props; + const { bondedId, stashActive, stashId } = this.state; return (
{this.renderAddress()} {this.renderBalance()} + {this.renderExtra()} {this.renderNonce()} diff --git a/packages/ui-app/src/AddressSummary.tsx b/packages/ui-app/src/AddressSummary.tsx index 256810ab7d..24c6bbdcc2 100644 --- a/packages/ui-app/src/AddressSummary.tsx +++ b/packages/ui-app/src/AddressSummary.tsx @@ -18,6 +18,7 @@ export type Props = I18nProps & { accounts_idAndIndex?: [AccountId?, AccountIndex?], balance?: Balance | Array, children?: React.ReactNode, + extraInfo?: React.ReactNode, name?: string, value: AccountId | AccountIndex | Address | string | null, withBalance?: boolean, @@ -48,6 +49,7 @@ class AddressSummary extends React.PureComponent { {this.renderAccountId()} {this.renderAccountIndex()} {this.renderBalance()} + {this.renderExtra()} {this.renderNonce()} {this.renderChildren()} @@ -148,6 +150,20 @@ class AddressSummary extends React.PureComponent { ); } + protected renderExtra () { + const { extraInfo } = this.props; + + if (!extraInfo) { + return null; + } + + return ( +
+ {extraInfo} +
+ ); + } + protected renderIcon (className: string = 'ui--AddressSummary-icon', size?: number) { const { accounts_idAndIndex = [], identIconSize = 96, value, withIcon = true } = this.props; diff --git a/packages/ui-app/src/styles/components.css b/packages/ui-app/src/styles/components.css index a89491aafb..3f2c6de3d1 100644 --- a/packages/ui-app/src/styles/components.css +++ b/packages/ui-app/src/styles/components.css @@ -113,6 +113,7 @@ header .ui--Button-Group { .ui--Balance, .ui--AddressSummary-balance, +.ui--AddressSummary-extra, .ui--AddressSummary-nonce { font-weight: 100; opacity: 0.75;