ghost-portal/packages/ui-reactive/src/Bonded.tsx
Thibaut Sardan 797c12be3c
Account overview (#1163)
* starting point

* show all accounts

* edit and save a name but remains ugly

* actually don't use deriveStateFromProps

* fix AdressRow

* indentation

* upperCase

* bring back the index

* trim input

* change edition l&f

* lint

* cater for small screens

* address comments

* lint and alphabetical order

* allow viewing and editing tags

* better UX when tag editing and styling for no tags

* nonce refactoring and show balances

* crypto type

* styling balances

* use css grid

* fix address row and creator

* with buttons

* button styling

* locked tooltip

* edit button always visible

* nits cleanup

* lint

* address comments

* try to prevent jump on editing

* no jump when no tags

* tweak for tag jump

* forgot the useless spacer

* align AddressSummary childre top right

* fix key warning and nits

* CSS stuff to align things

* Fix merge gone wrong
2019-05-22 15:38:44 +02:00

57 lines
1.5 KiB
TypeScript

// Copyright 2017-2019 @polkadot/ui-reactive authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, AccountIndex, Address, Option, StakingLedger } from '@polkadot/types';
import { BareProps, CallProps } from '@polkadot/ui-api/types';
import React from 'react';
import { withCalls } from '@polkadot/ui-api';
import { formatBalance } from '@polkadot/util';
type Props = BareProps & CallProps & {
children?: React.ReactNode,
params?: AccountId | AccountIndex | Address | string | Uint8Array | null,
label?: string,
staking_ledger?: Option<StakingLedger>
};
export class BondedDisplay extends React.PureComponent<Props> {
render () {
const { children, className, label = '', staking_ledger } = this.props;
if (!staking_ledger || staking_ledger.isNone) {
return null;
}
const { active: bonded } = staking_ledger.unwrap();
return (
<>
<span className={className + ' label-bonded'}>
{label}
</span>
<span className={className + ' result-bonded'}>
{
bonded
? formatBalance(bonded)
: '0'
}
</span>
{children}
</>
);
}
}
export default withCalls<Props>(
['query.staking.bonded', {
paramName: 'params',
propName: 'controllerId',
transform: (value) =>
value.unwrapOr(null)
}],
['query.staking.ledger', { paramName: 'controllerId' }]
)(BondedDisplay);