Render AddressRow balances from AddressInfo (#1259)
* Render AddressRow balances from AddressInfo * Extract BalanceActiveType * Filtering around AddressSummary children
This commit is contained in:
parent
7251ece4b0
commit
6ef01c0024
@ -79,7 +79,7 @@ class Address extends React.PureComponent<Props, State> {
|
|||||||
const isAuthor = [address, controllerId, stashId].includes(lastAuthor);
|
const isAuthor = [address, controllerId, stashId].includes(lastAuthor);
|
||||||
const bonded = stakers && !stakers.own.isZero()
|
const bonded = stakers && !stakers.own.isZero()
|
||||||
? [stakers.own, stakers.total.sub(stakers.own)]
|
? [stakers.own, stakers.total.sub(stakers.own)]
|
||||||
: undefined;
|
: true;
|
||||||
|
|
||||||
if ((filter === 'hasNominators' && !this.hasNominators())
|
if ((filter === 'hasNominators' && !this.hasNominators())
|
||||||
|| (filter === 'noNominators' && this.hasNominators())
|
|| (filter === 'noNominators' && this.hasNominators())
|
||||||
@ -92,15 +92,14 @@ class Address extends React.PureComponent<Props, State> {
|
|||||||
return (
|
return (
|
||||||
<article key={stashId || controllerId}>
|
<article key={stashId || controllerId}>
|
||||||
<AddressRow
|
<AddressRow
|
||||||
bonded={bonded}
|
|
||||||
buttons={this.renderKeys()}
|
buttons={this.renderKeys()}
|
||||||
defaultName={defaultName}
|
defaultName={defaultName}
|
||||||
value={stashId}
|
value={stashId}
|
||||||
withBonded
|
withBalance={{ bonded }}
|
||||||
>
|
>
|
||||||
{this.renderNominators()}
|
{this.renderNominators()}
|
||||||
{this.renderOffline()}
|
|
||||||
</AddressRow>
|
</AddressRow>
|
||||||
|
{this.renderOffline()}
|
||||||
{
|
{
|
||||||
isAuthor && stashId
|
isAuthor && stashId
|
||||||
? <div className='blockNumber'>#{lastBlock}</div>
|
? <div className='blockNumber'>#{lastBlock}</div>
|
||||||
|
|||||||
@ -5,8 +5,11 @@
|
|||||||
import { BareProps } from '@polkadot/ui-app/types';
|
import { BareProps } from '@polkadot/ui-app/types';
|
||||||
import { SideBarTransition, SIDEBAR_TRANSITION_DURATION, SIDEBAR_MENU_THRESHOLD } from './constants';
|
import { SideBarTransition, SIDEBAR_TRANSITION_DURATION, SIDEBAR_MENU_THRESHOLD } from './constants';
|
||||||
|
|
||||||
import React from 'react';
|
// this is disabled, Chrome + WASM memory leak makes it slow & laggy. If enabled
|
||||||
|
// we also need to export the default as hot(Apps) (last line)
|
||||||
// import { hot } from 'react-hot-loader/root';
|
// import { hot } from 'react-hot-loader/root';
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
import store from 'store';
|
import store from 'store';
|
||||||
import { ThemeProvider } from 'styled-components';
|
import { ThemeProvider } from 'styled-components';
|
||||||
import Signer from '@polkadot/ui-signer';
|
import Signer from '@polkadot/ui-signer';
|
||||||
@ -176,4 +179,4 @@ class Apps extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Apps; // hot(Apps);
|
export default Apps;
|
||||||
|
|||||||
@ -187,6 +187,9 @@ function createWebpack ({ alias = {}, context, name = 'index' }) {
|
|||||||
isProd
|
isProd
|
||||||
? null
|
? null
|
||||||
: new WebpackPluginServe({
|
: new WebpackPluginServe({
|
||||||
|
hmr: false, // switch off, Chrome WASM memory leak
|
||||||
|
liveReload: false, // explict off, overrides hmr
|
||||||
|
progress: false, // since we have hmr off, disable
|
||||||
port: 3000,
|
port: 3000,
|
||||||
static: path.join(process.cwd(), '/build')
|
static: path.join(process.cwd(), '/build')
|
||||||
})
|
})
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
import { DerivedBalances, DerivedStaking } from '@polkadot/api-derive/types';
|
import { DerivedBalances, DerivedStaking } from '@polkadot/api-derive/types';
|
||||||
import { BareProps, I18nProps } from './types';
|
import { BareProps, I18nProps } from './types';
|
||||||
|
|
||||||
|
import BN from 'bn.js';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { formatBalance, formatNumber } from '@polkadot/util';
|
import { formatBalance, formatNumber } from '@polkadot/util';
|
||||||
@ -15,13 +16,27 @@ import translate from './translate';
|
|||||||
import CryptoType from './CryptoType';
|
import CryptoType from './CryptoType';
|
||||||
import Label from './Label';
|
import Label from './Label';
|
||||||
|
|
||||||
|
// true to display, or (for bonded) provided values [own, ...all extras]
|
||||||
|
export type BalanceActiveType = {
|
||||||
|
available?: boolean,
|
||||||
|
bonded?: boolean | Array<BN>,
|
||||||
|
free?: boolean,
|
||||||
|
redeemable?: boolean,
|
||||||
|
unlocking?: boolean
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CryptoActiveType = {
|
||||||
|
crypto?: boolean,
|
||||||
|
nonce?: boolean
|
||||||
|
};
|
||||||
|
|
||||||
type Props = BareProps & I18nProps & {
|
type Props = BareProps & I18nProps & {
|
||||||
balances_all?: DerivedBalances,
|
balances_all?: DerivedBalances,
|
||||||
children?: React.ReactNode,
|
children?: React.ReactNode,
|
||||||
staking_info?: DerivedStaking,
|
staking_info?: DerivedStaking,
|
||||||
value: string,
|
value: string,
|
||||||
withBalance?: boolean | { available?: boolean, bonded?: boolean, free?: boolean, redeemable?: boolean, unlocking?: boolean },
|
withBalance?: boolean | BalanceActiveType,
|
||||||
withExtended?: boolean | { crypto?: boolean, nonce?: boolean }
|
withExtended?: boolean | CryptoActiveType
|
||||||
};
|
};
|
||||||
|
|
||||||
// <AddressInfo
|
// <AddressInfo
|
||||||
@ -76,12 +91,7 @@ class AddressInfo extends React.PureComponent<Props> {
|
|||||||
<div className='result'>{formatBalance(balances_all.availableBalance)}</div>
|
<div className='result'>{formatBalance(balances_all.availableBalance)}</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{balanceDisplay.bonded && staking_info && staking_info.stakingLedger && staking_info.accountId.eq(staking_info.stashId) && (
|
{balanceDisplay.bonded && this.renderBonded(balanceDisplay.bonded)}
|
||||||
<>
|
|
||||||
<Label label={t('bonded')} />
|
|
||||||
<div className='result'>{formatBalance(staking_info.stakingLedger.active)}</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{balanceDisplay.redeemable && staking_info && staking_info.redeemable && staking_info.redeemable.gtn(0) && (
|
{balanceDisplay.redeemable && staking_info && staking_info.redeemable && staking_info.redeemable.gtn(0) && (
|
||||||
<>
|
<>
|
||||||
<Label label={t('redeemable')} />
|
<Label label={t('redeemable')} />
|
||||||
@ -103,6 +113,33 @@ class AddressInfo extends React.PureComponent<Props> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// either true (filtered above already) or [own, ...all extras]
|
||||||
|
private renderBonded (bonded: true | Array<BN>) {
|
||||||
|
const { staking_info, t } = this.props;
|
||||||
|
let value = undefined;
|
||||||
|
|
||||||
|
if (Array.isArray(bonded)) {
|
||||||
|
// Get the sum of all extra values (if available)
|
||||||
|
const extras = bonded.filter((value, index) => index !== 0);
|
||||||
|
const extra = extras.reduce((total, value) => total.add(value), new BN(0)).gtn(0)
|
||||||
|
? `(+${extras.map((bonded) => formatBalance(bonded)).join(', ')})`
|
||||||
|
: '';
|
||||||
|
|
||||||
|
value = `${formatBalance(bonded[0])} ${extra}`;
|
||||||
|
} else if (staking_info && staking_info.stakingLedger && staking_info.accountId.eq(staking_info.stashId)) {
|
||||||
|
value = formatBalance(staking_info.stakingLedger.active);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
|
? (
|
||||||
|
<>
|
||||||
|
<Label label={t('bonded')} />
|
||||||
|
<div className='result'>{value}</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
: undefined;
|
||||||
|
}
|
||||||
|
|
||||||
private renderExtended () {
|
private renderExtended () {
|
||||||
const { balances_all, t, value, withExtended } = this.props;
|
const { balances_all, t, value, withExtended } = this.props;
|
||||||
const extendedDisplay = withExtended === true
|
const extendedDisplay = withExtended === true
|
||||||
|
|||||||
@ -9,9 +9,11 @@ import { classes } from './util';
|
|||||||
import { AddressSummary, Props } from './AddressSummary';
|
import { AddressSummary, Props } from './AddressSummary';
|
||||||
import translate from './translate';
|
import translate from './translate';
|
||||||
|
|
||||||
|
const DEFAULT_ICON_SIZE = 64;
|
||||||
|
|
||||||
class AddressRow extends AddressSummary {
|
class AddressRow extends AddressSummary {
|
||||||
render () {
|
render () {
|
||||||
const { className, style, identIconSize = 64, isInline, value, withIndex } = this.props;
|
const { className, style, identIconSize = DEFAULT_ICON_SIZE, isInline, value, withIndex } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@ -27,12 +29,7 @@ class AddressRow extends AddressSummary {
|
|||||||
{this.renderAddress()}
|
{this.renderAddress()}
|
||||||
{this.renderAccountIndex(withIndex)}
|
{this.renderAccountIndex(withIndex)}
|
||||||
</div>
|
</div>
|
||||||
<div className='ui--AddressSummary-balances'>
|
{this.renderBalances()}
|
||||||
{this.renderAvailable()}
|
|
||||||
{this.renderBalance()}
|
|
||||||
{this.renderBonded()}
|
|
||||||
{this.renderNonce()}
|
|
||||||
</div>
|
|
||||||
{this.renderTags()}
|
{this.renderTags()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -13,19 +13,15 @@ import { Button, Input, InputTags } from '@polkadot/ui-app';
|
|||||||
import BaseIdentityIcon from '@polkadot/ui-identicon';
|
import BaseIdentityIcon from '@polkadot/ui-identicon';
|
||||||
import keyring from '@polkadot/ui-keyring';
|
import keyring from '@polkadot/ui-keyring';
|
||||||
|
|
||||||
import AvailableDisplay from './Available';
|
import AddressInfo, { BalanceActiveType } from './AddressInfo';
|
||||||
import BalanceDisplay from './Balance';
|
|
||||||
import BondedDisplay from './Bonded';
|
|
||||||
import { classes, getAddrName, getAddrTags, toShortAddress } from './util';
|
|
||||||
import CopyButton from './CopyButton';
|
import CopyButton from './CopyButton';
|
||||||
import IdentityIcon from './IdentityIcon';
|
import IdentityIcon from './IdentityIcon';
|
||||||
import LinkPolkascan from './LinkPolkascan';
|
import LinkPolkascan from './LinkPolkascan';
|
||||||
import NonceDisplay from './Nonce';
|
|
||||||
import translate from './translate';
|
import translate from './translate';
|
||||||
|
import { classes, getAddrName, getAddrTags, toShortAddress } from './util';
|
||||||
|
|
||||||
export type Props = I18nProps & {
|
export type Props = I18nProps & {
|
||||||
accounts_idAndIndex?: [AccountId?, AccountIndex?],
|
accounts_idAndIndex?: [AccountId?, AccountIndex?],
|
||||||
balance?: BN | Array<BN>,
|
|
||||||
bonded?: BN | Array<BN>,
|
bonded?: BN | Array<BN>,
|
||||||
buttons?: React.ReactNode,
|
buttons?: React.ReactNode,
|
||||||
children?: React.ReactNode,
|
children?: React.ReactNode,
|
||||||
@ -37,13 +33,10 @@ export type Props = I18nProps & {
|
|||||||
isShort?: boolean,
|
isShort?: boolean,
|
||||||
session_validators?: Array<AccountId>,
|
session_validators?: Array<AccountId>,
|
||||||
value: AccountId | AccountIndex | Address | string | null,
|
value: AccountId | AccountIndex | Address | string | null,
|
||||||
withAvailable?: boolean,
|
withBalance?: boolean | BalanceActiveType,
|
||||||
withBalance?: boolean,
|
|
||||||
withBonded?: boolean,
|
|
||||||
withExplorer?: boolean,
|
withExplorer?: boolean,
|
||||||
withIcon?: boolean,
|
withIcon?: boolean,
|
||||||
withIndex?: boolean,
|
withIndex?: boolean,
|
||||||
withNonce?: boolean,
|
|
||||||
withTags?: boolean
|
withTags?: boolean
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -115,12 +108,7 @@ class AddressSummary extends React.PureComponent<Props, State> {
|
|||||||
{this.renderAddress()}
|
{this.renderAddress()}
|
||||||
{this.renderAccountIndex(withIndex)}
|
{this.renderAccountIndex(withIndex)}
|
||||||
</div>
|
</div>
|
||||||
<div className='ui--AddressSummary-balances'>
|
{this.renderBalances()}
|
||||||
{this.renderAvailable()}
|
|
||||||
{this.renderBalance()}
|
|
||||||
{this.renderBonded()}
|
|
||||||
{this.renderNonce()}
|
|
||||||
</div>
|
|
||||||
{this.renderTags()}
|
{this.renderTags()}
|
||||||
</div>
|
</div>
|
||||||
{this.renderChildren()}
|
{this.renderChildren()}
|
||||||
@ -234,23 +222,6 @@ class AddressSummary extends React.PureComponent<Props, State> {
|
|||||||
this.setState({ tags });
|
this.setState({ tags });
|
||||||
}
|
}
|
||||||
|
|
||||||
protected renderAvailable () {
|
|
||||||
const { accounts_idAndIndex = [], t, withAvailable } = this.props;
|
|
||||||
const [accountId] = accounts_idAndIndex;
|
|
||||||
|
|
||||||
if (!withAvailable || !accountId) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<AvailableDisplay
|
|
||||||
className='ui--AddressSummary-available'
|
|
||||||
label={<label>{t('available')}</label>}
|
|
||||||
params={accountId}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected renderAccountIndex (withIndex?: boolean) {
|
protected renderAccountIndex (withIndex?: boolean) {
|
||||||
const { accounts_idAndIndex = [] } = this.props;
|
const { accounts_idAndIndex = [] } = this.props;
|
||||||
const [, accountIndex] = accounts_idAndIndex;
|
const [, accountIndex] = accounts_idAndIndex;
|
||||||
@ -266,8 +237,8 @@ class AddressSummary extends React.PureComponent<Props, State> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected renderBalance () {
|
protected renderBalances () {
|
||||||
const { accounts_idAndIndex = [], balance, t, withBalance } = this.props;
|
const { accounts_idAndIndex = [], withBalance } = this.props;
|
||||||
const [accountId] = accounts_idAndIndex;
|
const [accountId] = accounts_idAndIndex;
|
||||||
|
|
||||||
if (!withBalance || !accountId) {
|
if (!withBalance || !accountId) {
|
||||||
@ -275,37 +246,25 @@ class AddressSummary extends React.PureComponent<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BalanceDisplay
|
<div className='ui--AddressSummary-balances'>
|
||||||
balance={balance}
|
<AddressInfo
|
||||||
className='ui--AddressSummary-balance'
|
value={accountId}
|
||||||
label={<label>{t('total')}</label>}
|
withBalance={withBalance}
|
||||||
params={accountId}
|
/>
|
||||||
/>
|
</div>
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected renderBonded () {
|
|
||||||
const { accounts_idAndIndex = [], bonded, t, withBonded } = this.props;
|
|
||||||
const [accountId] = accounts_idAndIndex;
|
|
||||||
|
|
||||||
if (!withBonded || !accountId) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<BondedDisplay
|
|
||||||
bonded={bonded}
|
|
||||||
className='ui--AddressSummary-bonded'
|
|
||||||
label={<label>{t('bonded')}</label>}
|
|
||||||
params={accountId}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected renderChildren () {
|
protected renderChildren () {
|
||||||
const { children } = this.props;
|
const { children } = this.props;
|
||||||
|
// we need children, or when an array, at least 1 non-empty value
|
||||||
|
const hasChildren = !children
|
||||||
|
? false
|
||||||
|
: Array.isArray(children)
|
||||||
|
? children.filter((child) => child).length !== 0
|
||||||
|
: true;
|
||||||
|
|
||||||
if (!children || (Array.isArray(children) && children.length === 0)) {
|
if (!hasChildren) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,23 +311,6 @@ class AddressSummary extends React.PureComponent<Props, State> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected renderNonce () {
|
|
||||||
const { t, withNonce } = this.props;
|
|
||||||
const { address } = this.state;
|
|
||||||
|
|
||||||
if (!withNonce || !address) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<NonceDisplay
|
|
||||||
className='ui--AddressSummary-nonce'
|
|
||||||
label={<label>{t('transactions')}</label>}
|
|
||||||
params={address}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected renderSaveIcon (callback: () => void) {
|
protected renderSaveIcon (callback: () => void) {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@ -187,8 +187,19 @@ button.ui.icon.iconButton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ui--AddressSummary-balances>span {
|
.ui--AddressSummary-balances {
|
||||||
text-align: left;
|
.column {
|
||||||
|
display: block;
|
||||||
|
|
||||||
|
label,
|
||||||
|
.result {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
> span {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ui--AddressSummary-tags.editable {
|
.ui--AddressSummary-tags.editable {
|
||||||
@ -232,16 +243,6 @@ button.ui.icon.iconButton {
|
|||||||
padding-top: 0.5em;
|
padding-top: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ui--AddressSummary-balances {
|
|
||||||
display: grid;
|
|
||||||
grid-column-gap: 1em;
|
|
||||||
|
|
||||||
label {
|
|
||||||
display: inline-block;
|
|
||||||
margin-right: 0.5rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.ui--AddressMini-balances {
|
.ui--AddressMini-balances {
|
||||||
display: grid;
|
display: grid;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user