Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions packages/react-components/src/AddressInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import styled from 'styled-components';
import { formatBalance, formatNumber, isObject } from '@polkadot/util';
import { Icon, Tooltip, TxButton } from '@polkadot/react-components';
import { withCalls, withMulti } from '@polkadot/react-api';
import { useAccounts } from '@polkadot/react-hooks';
import { FormatBalance } from '@polkadot/react-query';

import CryptoType from './CryptoType';
Expand Down Expand Up @@ -224,7 +225,7 @@ function renderValidatorPrefs ({ stakingInfo, t, withValidatorPrefs = false }: P
);
}

function renderBalances (props: Props): React.ReactNode {
function renderBalances (props: Props, allAccounts: string[]): React.ReactNode {
const { balancesAll, stakingInfo, t, withBalance = true } = props;
const balanceDisplay = withBalance === true
? DEFAULT_BALANCES
Expand All @@ -235,6 +236,7 @@ function renderBalances (props: Props): React.ReactNode {
}

const [ownBonded, otherBonded] = calcBonded(stakingInfo, balanceDisplay.bonded);
const controllerId = stakingInfo?.controllerId?.toString();

return (
<>
Expand All @@ -256,7 +258,7 @@ function renderBalances (props: Props): React.ReactNode {
/>
</>
)}
{balancesAll && balanceDisplay.vested && balancesAll.isVesting && (
{balanceDisplay.vested && balancesAll?.isVesting && (
<>
<Label label={t('vested')} />
<FormatBalance
Expand All @@ -265,7 +267,7 @@ function renderBalances (props: Props): React.ReactNode {
/>
</>
)}
{balancesAll && balanceDisplay.locked && balancesAll.lockedBalance && balancesAll.lockedBalance.gtn(0) && (
{balanceDisplay.locked && balancesAll?.lockedBalance?.gtn(0) && (
<>
<Label label={t('locked')} />
<FormatBalance
Expand All @@ -274,7 +276,7 @@ function renderBalances (props: Props): React.ReactNode {
/>
</>
)}
{balancesAll && balanceDisplay.reserved && balancesAll.reservedBalance && balancesAll.reservedBalance.gtn(0) && (
{balanceDisplay.reserved && balancesAll?.reservedBalance?.gtn(0) && (
<>
<Label label={t('reserved')} />
<FormatBalance
Expand All @@ -298,16 +300,16 @@ function renderBalances (props: Props): React.ReactNode {
</FormatBalance>
</>
)}
{balanceDisplay.redeemable && stakingInfo && stakingInfo.redeemable && stakingInfo.redeemable.gtn(0) && (
{balanceDisplay.redeemable && stakingInfo?.redeemable?.gtn(0) && (
<>
<Label label={t('redeemable')} />
<FormatBalance
className='result'
value={stakingInfo.redeemable}
>
{stakingInfo.controllerId && (
{controllerId && allAccounts.includes(controllerId) && (
<TxButton
accountId={stakingInfo.controllerId.toString()}
accountId={controllerId}
className='icon-button'
icon='lock'
size='small'
Expand All @@ -321,7 +323,7 @@ function renderBalances (props: Props): React.ReactNode {
</FormatBalance>
</>
)}
{balanceDisplay.unlocking && stakingInfo && stakingInfo.unlocking && (
{balanceDisplay.unlocking && stakingInfo?.unlocking && (
<>
<Label label={t('unbonding')} />
<div className='result'>
Expand All @@ -334,12 +336,13 @@ function renderBalances (props: Props): React.ReactNode {
}

function AddressInfo (props: Props): React.ReactElement<Props> {
const { allAccounts } = useAccounts();
const { className, children, extraInfo, stakingInfo, t, withHexSessionId, withRewardDestination } = props;

return (
<div className={className}>
<div className='column'>
{renderBalances(props)}
{renderBalances(props, allAccounts)}
{withHexSessionId && (
<>
<Label label={t('session keys')} />
Expand Down