From 3c5bee6dcf21066d1ea85f014d6a948b81e250c8 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 29 Oct 2019 21:34:26 +0100 Subject: [PATCH] Era points (#1811) --- packages/app-staking/src/Overview/Address.tsx | 15 ++++++++++++--- .../app-staking/src/Overview/CurrentList.tsx | 17 ++++++++++++----- packages/app-staking/src/Overview/index.tsx | 5 ++++- packages/app-staking/src/index.tsx | 10 +++++++--- packages/app-staking/src/types.ts | 2 ++ packages/react-components/src/AddressInfo.tsx | 17 ++++++++++++++++- packages/react-components/src/AddressRow.tsx | 10 +++++++--- packages/react-components/src/Row.tsx | 5 +++++ 8 files changed, 65 insertions(+), 16 deletions(-) diff --git a/packages/app-staking/src/Overview/Address.tsx b/packages/app-staking/src/Overview/Address.tsx index 7d83c27906..c3ab71ebe2 100644 --- a/packages/app-staking/src/Overview/Address.tsx +++ b/packages/app-staking/src/Overview/Address.tsx @@ -2,7 +2,7 @@ // 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 } from '@polkadot/types/interfaces'; +import { AccountId, Balance, Points } from '@polkadot/types/interfaces'; import { DerivedStaking, DerivedStakingOnlineStatus, DerivedHeartbeats } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/react-components/types'; import { ValidatorFilter } from '../types'; @@ -14,7 +14,7 @@ import { ApiContext, withCalls, withMulti } from '@polkadot/react-api'; import { AddressCard, AddressMini, OnlineStatus } from '@polkadot/react-components'; import { classes } from '@polkadot/react-components/util'; import keyring from '@polkadot/ui-keyring'; -import { formatBalance } from '@polkadot/util'; +import { formatBalance, formatNumber } from '@polkadot/util'; import { updateOnlineStatus } from '../util'; import translate from '../translate'; @@ -26,6 +26,7 @@ interface Props extends I18nProps { defaultName: string; filter: ValidatorFilter; lastAuthor?: string; + points?: [Points, Points]; recentlyOnline?: DerivedHeartbeats; stakingInfo?: DerivedStaking; withNominations?: boolean; @@ -49,7 +50,7 @@ interface OnlineState { const WITH_VALIDATOR_PREFS = { validatorPayment: true }; -function Address ({ authorsMap, className, defaultName, filter, lastAuthor, recentlyOnline, stakingInfo, t, withNominations }: Props): React.ReactElement | null { +function Address ({ authorsMap, className, defaultName, filter, lastAuthor, points, recentlyOnline, stakingInfo, t, withNominations }: Props): React.ReactElement | null { const { isSubstrateV2 } = useContext(ApiContext); const [isNominatorMe, seIsNominatorMe] = useState(false); const [{ hasOfflineWarnings, onlineStatus }, setOnlineStatus] = useState({ @@ -123,6 +124,8 @@ function Address ({ authorsMap, className, defaultName, filter, lastAuthor, rece const lastBlockNumber = authorsMap[stashId]; + points && console.error(points); + return ( )} + isDisabled={!!points && points[0].isEmpty} key={stashId} value={stashId} withBalance={balanceOpts} diff --git a/packages/app-staking/src/Overview/CurrentList.tsx b/packages/app-staking/src/Overview/CurrentList.tsx index 078c534965..6bc53eaff9 100644 --- a/packages/app-staking/src/Overview/CurrentList.tsx +++ b/packages/app-staking/src/Overview/CurrentList.tsx @@ -4,6 +4,7 @@ import { DerivedHeartbeats } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/react-components/types'; +import { EraPoints } from '@polkadot/types/interfaces'; import { ValidatorFilter } from '../types'; import React, { useState } from 'react'; @@ -15,25 +16,31 @@ import Address from './Address'; interface Props extends I18nProps { authorsMap: Record; currentValidators: string[]; + eraPoints?: EraPoints; lastAuthor?: string; next: string[]; recentlyOnline?: DerivedHeartbeats; } -function CurrentList ({ authorsMap, currentValidators, lastAuthor, next, recentlyOnline, t }: Props): React.ReactElement { +function CurrentList ({ authorsMap, currentValidators, eraPoints, lastAuthor, next, recentlyOnline, t }: Props): React.ReactElement { const [filter, setFilter] = useState('all'); - const _renderColumn = (addresses: string[], defaultName: string, withNominations: boolean): React.ReactNode => { - return addresses.map((address): React.ReactNode => ( + const _renderColumn = (addresses: string[], defaultName: string, withExpanded: boolean): React.ReactNode => { + return addresses.map((address, index): React.ReactNode => (
)); }; diff --git a/packages/app-staking/src/Overview/index.tsx b/packages/app-staking/src/Overview/index.tsx index aaca140125..6adaafd5f9 100644 --- a/packages/app-staking/src/Overview/index.tsx +++ b/packages/app-staking/src/Overview/index.tsx @@ -4,6 +4,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { BareProps } from '@polkadot/react-components/types'; +import { EraPoints } from '@polkadot/types/interfaces'; import { ComponentProps } from '../types'; import React, { useContext, useEffect, useState } from 'react'; @@ -14,13 +15,14 @@ import CurrentList from './CurrentList'; import Summary from './Summary'; interface Props extends BareProps, ComponentProps { + eraPoints?: EraPoints; } export default function Overview (props: Props): React.ReactElement { const { isSubstrateV2 } = useContext(ApiContext); const { byAuthor, lastBlockAuthor, lastBlockNumber } = useContext(BlockAuthorsContext); const [nextSorted, setNextSorted] = useState([]); - const { allControllers, allStashes, currentValidators, recentlyOnline } = props; + const { allControllers, allStashes, currentValidators, eraPoints, recentlyOnline } = props; useEffect((): void => { setNextSorted( @@ -44,6 +46,7 @@ export default function Overview (props: Props): React.ReactElement { { +function App ({ allAccounts, allStashesAndControllers: [allStashes, allControllers] = EMPTY_ALL, className, currentValidators = EMPY_ACCOUNTS, basePath, eraPoints, recentlyOnline, t }: Props): React.ReactElement { const _renderComponent = (Component: React.ComponentType): () => React.ReactNode => { // eslint-disable-next-line react/display-name return (): React.ReactNode => { @@ -48,6 +49,7 @@ function App ({ allAccounts, allStashesAndControllers: [allStashes, allControlle allControllers={allControllers} allStashes={allStashes} currentValidators={currentValidators} + eraPoints={eraPoints} recentlyOnline={recentlyOnline} /> ); @@ -108,7 +110,9 @@ export default withMulti( propName: 'currentValidators', transform: (validators: AccountId[]): string[] => validators.map((accountId): string => accountId.toString()) - }] + }], + ['query.staking.currentEra', { propName: 'currentEra' }], + ['query.staking.currentEraPointsEarned', { paramName: 'currentEra', propName: 'eraPoints' }] ), withObservable(accountObservable.subject, { propName: 'allAccounts' }) ); diff --git a/packages/app-staking/src/types.ts b/packages/app-staking/src/types.ts index 85c3ee95a7..9fa94e7782 100644 --- a/packages/app-staking/src/types.ts +++ b/packages/app-staking/src/types.ts @@ -4,6 +4,7 @@ import { DerivedFees, DerivedBalances, DerivedHeartbeats } from '@polkadot/api-derive/types'; import { SubjectInfo } from '@polkadot/ui-keyring/observable/types'; +import { EraPoints } from '@polkadot/types/interfaces'; import BN from 'bn.js'; @@ -14,6 +15,7 @@ export interface ComponentProps { allControllers: string[]; allStashes: string[]; currentValidators: string[]; + eraPoints?: EraPoints; recentlyOnline?: DerivedHeartbeats; } diff --git a/packages/react-components/src/AddressInfo.tsx b/packages/react-components/src/AddressInfo.tsx index 921cf7fcea..adaf88d87e 100644 --- a/packages/react-components/src/AddressInfo.tsx +++ b/packages/react-components/src/AddressInfo.tsx @@ -22,6 +22,7 @@ import translate from './translate'; export interface BalanceActiveType { available?: boolean; bonded?: boolean | BN[]; + extraInfo?: [React.ReactNode, React.ReactNode][]; locked?: boolean; redeemable?: boolean; reserved?: boolean; @@ -43,6 +44,7 @@ interface Props extends BareProps, I18nProps { address: string; balances_all?: DerivedBalances; children?: React.ReactNode; + extraInfo?: [string, string][]; staking_info?: DerivedStaking; withBalance?: boolean | BalanceActiveType; withExtended?: boolean | CryptoActiveType; @@ -265,7 +267,7 @@ function renderBalances (props: Props): React.ReactNode { } function AddressInfo (props: Props): React.ReactElement { - const { className, children, staking_info, t, withHexSessionId, withRewardDestination } = props; + const { className, children, extraInfo, staking_info, t, withHexSessionId, withRewardDestination } = props; return (
@@ -278,6 +280,19 @@ function AddressInfo (props: Props): React.ReactElement { )} {renderValidatorPrefs(props)} + {extraInfo && ( + <> +
+ {extraInfo.map(([label, value], index): React.ReactNode => ( + + + ))} + + )} {withRewardDestination && staking_info && staking_info.rewardDestination && ( <>