From fa8e13c5623d2f9e7a4e0028d4086f1fa588a1b2 Mon Sep 17 00:00:00 2001 From: kwingram25 Date: Wed, 10 Apr 2019 23:30:03 -0700 Subject: [PATCH] add last block to staking overview, reposition warning (#959) --- packages/app-staking/src/Overview/Address.tsx | 3 +- .../app-staking/src/Overview/CurrentList.tsx | 25 +++------------ packages/app-staking/src/Overview/Summary.tsx | 19 ++++++++++-- packages/app-staking/src/Overview/index.tsx | 31 ++++++++++++++++--- packages/ui-app/src/AddressMini.tsx | 1 + packages/ui-app/src/CardSummary.tsx | 1 + packages/ui-app/src/RecentlyOffline.tsx | 8 +++-- packages/ui-app/src/styles/components.css | 11 +++++-- 8 files changed, 65 insertions(+), 34 deletions(-) diff --git a/packages/app-staking/src/Overview/Address.tsx b/packages/app-staking/src/Overview/Address.tsx index a7c47a179a..6a13de10a5 100644 --- a/packages/app-staking/src/Overview/Address.tsx +++ b/packages/app-staking/src/Overview/Address.tsx @@ -99,7 +99,7 @@ class Address extends React.PureComponent { { isAuthor - ?
{lastBlock}
+ ?
#{lastBlock}
: null } @@ -199,6 +199,7 @@ class Address extends React.PureComponent { ); } diff --git a/packages/app-staking/src/Overview/CurrentList.tsx b/packages/app-staking/src/Overview/CurrentList.tsx index 1942af3715..61d863b210 100644 --- a/packages/app-staking/src/Overview/CurrentList.tsx +++ b/packages/app-staking/src/Overview/CurrentList.tsx @@ -7,9 +7,7 @@ import { I18nProps } from '@polkadot/ui-app/types'; import { Nominators, RecentlyOfflineMap } from '../types'; import React from 'react'; -import { AccountId, Balance, HeaderExtended } from '@polkadot/types'; -import { withCalls, withMulti } from '@polkadot/ui-api/with'; -import { formatNumber } from '@polkadot/util'; +import { AccountId, Balance } from '@polkadot/types'; import translate from '../translate'; import Address from './Address'; @@ -17,8 +15,9 @@ import Address from './Address'; type Props = I18nProps & { balances: DerivedBalancesMap, balanceArray: (_address: AccountId | string) => Array | undefined, - chain_subscribeNewHead?: HeaderExtended, current: Array, + lastAuthor?: string, + lastBlock: string, next: Array, nominators: Nominators, recentlyOffline: RecentlyOfflineMap @@ -67,7 +66,7 @@ class CurrentList extends React.PureComponent { } private renderColumn (addresses: Array, defaultName: string) { - const { balances, balanceArray, chain_subscribeNewHead, nominators, recentlyOffline, t } = this.props; + const { balances, balanceArray, lastAuthor, lastBlock, nominators, recentlyOffline, t } = this.props; if (addresses.length === 0) { return ( @@ -75,14 +74,6 @@ class CurrentList extends React.PureComponent { ); } - let lastBlock: string = ''; - let lastAuthor: string; - - if (chain_subscribeNewHead) { - lastBlock = `#${formatNumber(chain_subscribeNewHead.blockNumber)}`; - lastAuthor = (chain_subscribeNewHead.author || '').toString(); - } - return (
{addresses.map((address) => ( @@ -103,10 +94,4 @@ class CurrentList extends React.PureComponent { } } -export default withMulti( - CurrentList, - translate, - withCalls( - 'derive.chain.subscribeNewHead' - ) -); +export default translate(CurrentList); diff --git a/packages/app-staking/src/Overview/Summary.tsx b/packages/app-staking/src/Overview/Summary.tsx index 68b54ed9da..2bbd3e267f 100644 --- a/packages/app-staking/src/Overview/Summary.tsx +++ b/packages/app-staking/src/Overview/Summary.tsx @@ -8,7 +8,7 @@ import { I18nProps } from '@polkadot/ui-app/types'; import BN from 'bn.js'; import React from 'react'; import SummarySession from '@polkadot/app-explorer/SummarySession'; -import { SummaryBox, CardSummary } from '@polkadot/ui-app'; +import { AddressMini, SummaryBox, CardSummary } from '@polkadot/ui-app'; import { withCall, withMulti } from '@polkadot/ui-api'; import translate from '../translate'; @@ -16,6 +16,8 @@ import translate from '../translate'; type Props = I18nProps & { balances: DerivedBalancesMap, intentions: Array, + lastAuthor?: string, + lastBlock: string, lastLengthChange?: BN, staking_validatorCount?: BN, validators: Array @@ -23,7 +25,7 @@ type Props = I18nProps & { class Summary extends React.PureComponent { render () { - const { className, intentions, style, t, staking_validatorCount, validators } = this.props; + const { className, intentions, lastAuthor, lastBlock, style, t, staking_validatorCount, validators } = this.props; const waiting = intentions.length > validators.length ? (intentions.length - validators.length) : 0; @@ -41,7 +43,18 @@ class Summary extends React.PureComponent { {waiting} -
+
+ + {lastAuthor && ( + + )} + {lastBlock} +
diff --git a/packages/app-staking/src/Overview/index.tsx b/packages/app-staking/src/Overview/index.tsx index 29b8bc5c92..4a5b47e0cb 100644 --- a/packages/app-staking/src/Overview/index.tsx +++ b/packages/app-staking/src/Overview/index.tsx @@ -2,24 +2,28 @@ // 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 { BareProps } from '@polkadot/ui-app/types'; import { ComponentProps } from '../types'; import './index.css'; import React from 'react'; -import { Balance } from '@polkadot/types'; +import { withCalls, withMulti } from '@polkadot/ui-api/with'; +import { formatNumber } from '@polkadot/util'; import CurrentList from './CurrentList'; import Summary from './Summary'; -type Props = BareProps & ComponentProps; +type Props = BareProps & ComponentProps & { + chain_subscribeNewHead?: HeaderExtended +}; const ZERO = new Balance(0); -export default class Overview extends React.PureComponent { +class Overview extends React.PureComponent { render () { - const { balances, balanceArray, intentions, nominators, recentlyOffline, validators } = this.props; + const { balances, balanceArray, chain_subscribeNewHead, intentions, nominators, recentlyOffline, validators } = this.props; const intentionsSorted = this.sortByBalance( intentions.filter((address) => !validators.includes(address) @@ -27,17 +31,29 @@ export default class Overview extends React.PureComponent { ); const validatorsSorted = this.sortByBalance(validators); + let lastBlock: string = '—'; + let lastAuthor: string | undefined; + + if (chain_subscribeNewHead) { + lastBlock = formatNumber(chain_subscribeNewHead.blockNumber); + lastAuthor = (chain_subscribeNewHead.author || '').toString(); + } + return (
{ }); } } + +export default withMulti( + Overview, + withCalls( + 'derive.chain.subscribeNewHead' + ) +); diff --git a/packages/ui-app/src/AddressMini.tsx b/packages/ui-app/src/AddressMini.tsx index 062f2aae76..2c8aa3938d 100644 --- a/packages/ui-app/src/AddressMini.tsx +++ b/packages/ui-app/src/AddressMini.tsx @@ -113,6 +113,7 @@ export default class AddressMini extends React.PureComponent { accountId={value.toString()} offline={offlineStatus} tooltip + inline /> ); } diff --git a/packages/ui-app/src/CardSummary.tsx b/packages/ui-app/src/CardSummary.tsx index d5f7854108..d3dc8880d5 100644 --- a/packages/ui-app/src/CardSummary.tsx +++ b/packages/ui-app/src/CardSummary.tsx @@ -28,6 +28,7 @@ const Card = styled.article` > div { font-size: 2.1rem; font-weight: 100; + position: relative; line-height: 2.1rem; text-align: right; diff --git a/packages/ui-app/src/RecentlyOffline.tsx b/packages/ui-app/src/RecentlyOffline.tsx index 6f0ca3da05..26e27db596 100644 --- a/packages/ui-app/src/RecentlyOffline.tsx +++ b/packages/ui-app/src/RecentlyOffline.tsx @@ -16,7 +16,8 @@ import translate from './translate'; type Props = I18nProps & { accountId: AccountId | string, offline: Array, - tooltip?: boolean + tooltip?: boolean, + inline?: boolean }; type State = { @@ -29,7 +30,7 @@ class RecentlyOffline extends React.PureComponent { }; render () { - const { offline, tooltip = false, t } = this.props; + const { offline, inline, tooltip = false, t } = this.props; const { isOpen } = this.state; const accountId = this.props.accountId.toString(); @@ -54,7 +55,8 @@ class RecentlyOffline extends React.PureComponent { className={[ 'ui--RecentlyOffline', isOpen ? 'expand' : '', - tooltip ? 'tooltip' : '' + tooltip ? 'tooltip' : '', + inline ? 'inline' : '' ].join(' ')} {...(!tooltip ? { onClick: this.toggleOpen } : diff --git a/packages/ui-app/src/styles/components.css b/packages/ui-app/src/styles/components.css index 96803e000d..c76e87004e 100644 --- a/packages/ui-app/src/styles/components.css +++ b/packages/ui-app/src/styles/components.css @@ -49,6 +49,11 @@ header .ui--Button-Group { padding: 0.25rem 0 0 0; } +.ui--AddressMini.summary { + position: relative; + top: -0.2rem; +} + .ui--AddressMini-info div { display: inline-block; vertical-align: middle; @@ -264,12 +269,12 @@ header .ui--Button-Group { .ui--RecentlyOffline { position: absolute; - bottom: 0.75rem; + top: 0.75rem; font-size: 12px; cursor: help; display: flex; justify-content: center; - right: 0.75rem; + left: 0.75rem; width: 22px; height: 22px; padding: 0; @@ -307,7 +312,7 @@ header .ui--Button-Group { } } - &.tooltip { + &.inline { position: static; margin: .3rem 0 .3rem .5rem; }