From 0854c78bfae4609e33ed466cb722de602c9af3b5 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sun, 7 Apr 2019 14:05:56 +0200 Subject: [PATCH] Display controller on overview (#907) * Display controller (with stash in overview) * Styles --- packages/app-staking/src/Overview/Address.tsx | 36 ++++++++++++++++--- packages/app-staking/src/index.css | 12 +++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/packages/app-staking/src/Overview/Address.tsx b/packages/app-staking/src/Overview/Address.tsx index 6d94d0d33b..01a5aa565e 100644 --- a/packages/app-staking/src/Overview/Address.tsx +++ b/packages/app-staking/src/Overview/Address.tsx @@ -9,7 +9,7 @@ import { Nominators, RecentlyOfflineMap } from '../types'; import BN from 'bn.js'; import React from 'react'; import { AccountId, Balance, Option, StakingLedger } from '@polkadot/types'; -import { withCall, withMulti } from '@polkadot/ui-api/with'; +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'; @@ -25,26 +25,32 @@ type Props = I18nProps & { lastBlock: string, nominators: Nominators, recentlyOffline: RecentlyOfflineMap, + staking_bonded?: Option, staking_ledger?: Option }; type State = { + bondedId: string | null, stashId: string | null, badgeExpanded: boolean; }; class Address extends React.PureComponent { state: State = { + bondedId: null, stashId: null, badgeExpanded: false }; - static getDerivedStateFromProps ({ staking_ledger }: Props): State | null { - if (!staking_ledger || staking_ledger.isNone) { + static getDerivedStateFromProps ({ address, staking_bonded, staking_ledger }: Props): State | null { + if (!staking_ledger || staking_ledger.isNone || !staking_bonded) { return null; } return { + bondedId: staking_bonded.isNone + ? address + : staking_bonded.unwrap().toString(), stashId: staking_ledger.unwrap().stash.toString() } as State; } @@ -66,6 +72,7 @@ class Address extends React.PureComponent { withCopy={false} withNonce={false} > + {this.renderController()} {this.renderNominators()} {this.renderOffline()} @@ -102,6 +109,24 @@ class Address extends React.PureComponent { this.setState({ badgeExpanded: !badgeExpanded }); } + private renderController () { + const { bondedId } = this.state; + + if (!bondedId) { + return null; + } + + return ( +
+ + +
+ ); + } + private renderNominators () { const { address, nominators, t } = this.props; const myNominators = Object.keys(nominators).filter((nominator) => @@ -168,5 +193,8 @@ class Address extends React.PureComponent { export default withMulti( Address, translate, - withCall('query.staking.ledger', { paramName: 'address' }) + withCalls( + ['query.staking.ledger', { paramName: 'address' }], + ['query.staking.bonded', { paramName: 'address' }] + ) ); diff --git a/packages/app-staking/src/index.css b/packages/app-staking/src/index.css index d4d9bfd508..8067fd94f1 100644 --- a/packages/app-staking/src/index.css +++ b/packages/app-staking/src/index.css @@ -102,3 +102,15 @@ margin-bottom: -0.25rem; } } + +.staking--controller-info { + position: absolute; + top: 0.25rem; + right: 1rem; + margin-top: 0.75rem; + text-align: right; + + .staking--label { + margin-bottom: -0.25rem; + } +}