Nicknames & term progress (#1772)
* Nicknames & term progress * Add reserved display * Hide reserved on 0
This commit is contained in:
parent
93298ba7ac
commit
8c0c870d04
@ -20,7 +20,7 @@ interface Props extends I18nProps {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const WITH_BALANCE = { available: true, bonded: true, free: true, total: true };
|
||||
const WITH_BALANCE = { available: true, bonded: true, free: true, reserved: true, total: true };
|
||||
const WITH_EXTENDED = { nonce: true };
|
||||
|
||||
const isEditable = true;
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { I18nProps } from '@polkadot/react-components/types';
|
||||
import { BlockNumber } from '@polkadot/types/interfaces';
|
||||
import { ComponentProps } from './types';
|
||||
|
||||
import React from 'react';
|
||||
@ -12,9 +13,11 @@ import { formatNumber } from '@polkadot/util';
|
||||
|
||||
import translate from '../translate';
|
||||
|
||||
interface Props extends I18nProps, ComponentProps {}
|
||||
interface Props extends I18nProps, ComponentProps {
|
||||
bestNumber?: BlockNumber;
|
||||
}
|
||||
|
||||
function Summary ({ electionsInfo: { members, candidateCount, desiredSeats, termDuration, voteCount }, t }: Props): React.ReactElement<Props> {
|
||||
function Summary ({ bestNumber, electionsInfo: { members, candidateCount, desiredSeats, termDuration, voteCount }, t }: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<SummaryBox>
|
||||
<section>
|
||||
@ -32,11 +35,17 @@ function Summary ({ electionsInfo: { members, candidateCount, desiredSeats, term
|
||||
</CardSummary>
|
||||
</section>
|
||||
)}
|
||||
<section>
|
||||
<CardSummary label={t('term duration')}>
|
||||
{formatNumber(termDuration)}
|
||||
</CardSummary>
|
||||
</section>
|
||||
{bestNumber && termDuration && termDuration.gtn(0) && (
|
||||
<section>
|
||||
<CardSummary
|
||||
label={t('term progress')}
|
||||
progress={{
|
||||
total: termDuration,
|
||||
value: bestNumber.mod(termDuration)
|
||||
}}
|
||||
/>
|
||||
</section>
|
||||
)}
|
||||
</SummaryBox>
|
||||
);
|
||||
}
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { DerivedElectionsInfo } from '@polkadot/api-derive/types';
|
||||
import { ComponentProps as Props } from './types';
|
||||
import { BlockNumber } from '@polkadot/types/interfaces';
|
||||
import { ComponentProps } from './types';
|
||||
|
||||
import React from 'react';
|
||||
import { withCalls } from '@polkadot/react-api';
|
||||
@ -15,6 +16,10 @@ import SubmitCandidacy from './SubmitCandidacy';
|
||||
import Summary from './Summary';
|
||||
import Vote from './Vote';
|
||||
|
||||
interface Props extends ComponentProps {
|
||||
bestNumber?: BlockNumber;
|
||||
}
|
||||
|
||||
const NULL_INFO: DerivedElectionsInfo = {
|
||||
candidates: [],
|
||||
candidateCount: createType('u32'),
|
||||
@ -23,10 +28,13 @@ const NULL_INFO: DerivedElectionsInfo = {
|
||||
termDuration: createType('BlockNumber')
|
||||
};
|
||||
|
||||
function Overview ({ electionsInfo = NULL_INFO }: Props): React.ReactElement<Props> {
|
||||
function Overview ({ bestNumber, electionsInfo = NULL_INFO }: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<>
|
||||
<Summary electionsInfo={electionsInfo} />
|
||||
<Summary
|
||||
bestNumber={bestNumber}
|
||||
electionsInfo={electionsInfo}
|
||||
/>
|
||||
<Button.Group>
|
||||
<SubmitCandidacy electionsInfo={electionsInfo} />
|
||||
<Button.Or />
|
||||
@ -40,5 +48,8 @@ function Overview ({ electionsInfo = NULL_INFO }: Props): React.ReactElement<Pro
|
||||
export default withCalls<Props>(
|
||||
['derive.elections.info', {
|
||||
propName: 'electionsInfo'
|
||||
}],
|
||||
['derive.chain.bestNumber', {
|
||||
propName: 'bestNumber'
|
||||
}]
|
||||
)(Overview);
|
||||
|
||||
@ -23,6 +23,7 @@ export interface BalanceActiveType {
|
||||
available?: boolean;
|
||||
bonded?: boolean | BN[];
|
||||
redeemable?: boolean;
|
||||
reserved?: boolean;
|
||||
total?: boolean;
|
||||
unlocking?: boolean;
|
||||
}
|
||||
@ -49,10 +50,11 @@ interface Props extends BareProps, I18nProps {
|
||||
withValidatorPrefs?: boolean | ValidatorPrefsType;
|
||||
}
|
||||
|
||||
const DEFAULT_BALANCES = {
|
||||
const DEFAULT_BALANCES: BalanceActiveType = {
|
||||
available: true,
|
||||
bonded: true,
|
||||
redeemable: true,
|
||||
reserved: true,
|
||||
total: true,
|
||||
unlocking: true
|
||||
};
|
||||
@ -207,6 +209,12 @@ function renderBalances (props: Props): React.ReactNode {
|
||||
<div className='result'>{formatBalance(balances_all.availableBalance)}</div>
|
||||
</>
|
||||
)}
|
||||
{balanceDisplay.reserved && balances_all.reservedBalance && balances_all.reservedBalance.gtn(0) && (
|
||||
<>
|
||||
<Label label={t('reserved')} />
|
||||
<div className='result'>{formatBalance(balances_all.reservedBalance)}</div>
|
||||
</>
|
||||
)}
|
||||
{balanceDisplay.bonded && (ownBonded.gtn(0) || otherBonded.length !== 0) && (
|
||||
<>
|
||||
<Label label={t('bonded')} />
|
||||
|
||||
@ -5,14 +5,17 @@
|
||||
|
||||
import { ApiProps } from '@polkadot/react-api/types';
|
||||
import { I18nProps } from '@polkadot/react-components/types';
|
||||
import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
||||
import { AccountId, AccountIndex, Address, Balance } from '@polkadot/types/interfaces';
|
||||
import { Codec } from '@polkadot/types/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { withCalls, withMulti } from '@polkadot/react-api';
|
||||
import BaseIdentityIcon from '@polkadot/react-identicon';
|
||||
import { Bytes, Option } from '@polkadot/types';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
import { u8aToString } from '@polkadot/util';
|
||||
|
||||
import AddressInfo, { BalanceActiveType, ValidatorPrefsType } from './AddressInfo';
|
||||
import { classes, getAddressName, getAddressTags, toShortAddress } from './util';
|
||||
@ -26,6 +29,7 @@ export interface Props extends I18nProps, RowProps {
|
||||
isContract?: boolean;
|
||||
isValid?: boolean;
|
||||
label?: string;
|
||||
nicks_nameOf?: Option<[Bytes, Balance] & Codec>;
|
||||
value: AccountId | AccountIndex | Address | string | null;
|
||||
withAddressOrName?: boolean;
|
||||
withBalance?: boolean | BalanceActiveType;
|
||||
@ -45,13 +49,16 @@ class AddressRow extends Row<ApiProps & Props, State> {
|
||||
this.state = this.createState();
|
||||
}
|
||||
|
||||
public static getDerivedStateFromProps ({ accounts_idAndIndex = [], defaultName, type, value }: Props, prevState: State): State | null {
|
||||
public static getDerivedStateFromProps ({ accounts_idAndIndex = [], defaultName, nicks_nameOf, type, value }: Props, prevState: State): State | null {
|
||||
const [_accountId] = accounts_idAndIndex;
|
||||
const accountId = _accountId || value;
|
||||
const address = accountId
|
||||
? accountId.toString()
|
||||
: DEFAULT_ADDR;
|
||||
const name = getAddressName(address, type, false, defaultName || '<unknown>') || '';
|
||||
const nickName = nicks_nameOf && nicks_nameOf.isSome
|
||||
? u8aToString(nicks_nameOf.unwrap()[0])
|
||||
: undefined;
|
||||
const name = nickName || getAddressName(address, type, false, defaultName || '<unknown>') || '';
|
||||
const tags = getAddressTags(address, type);
|
||||
const state: Partial<State> = { tags };
|
||||
let hasChanged = false;
|
||||
@ -146,7 +153,7 @@ class AddressRow extends Row<ApiProps & Props, State> {
|
||||
}
|
||||
|
||||
private renderAccountIndex (): React.ReactNode {
|
||||
const { accounts_idAndIndex = [], withIndex } = this.props;
|
||||
const { accounts_idAndIndex = [], withIndex = true } = this.props;
|
||||
const [, accountIndex] = accounts_idAndIndex;
|
||||
|
||||
if (!accountIndex || !withIndex) {
|
||||
@ -273,10 +280,14 @@ export {
|
||||
|
||||
export default withMulti(
|
||||
styled(AddressRow as React.ComponentClass<Props & ApiProps, State>)`
|
||||
${styles}
|
||||
${styles},
|
||||
.ui--Row-accountId+.ui--Row-accountIndex {
|
||||
margin-top: -0.25rem;
|
||||
}
|
||||
`,
|
||||
translate,
|
||||
withCalls<Props>(
|
||||
['derive.accounts.idAndIndex', { paramName: 'value' }]
|
||||
['derive.accounts.idAndIndex', { paramName: 'value' }],
|
||||
['query.nicks.nameOf', { paramName: 'value' }]
|
||||
)
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user