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
This commit is contained in:
Thibaut Sardan 2019-05-22 15:38:44 +02:00 committed by GitHub
parent 8402e26b77
commit 797c12be3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 1138 additions and 696 deletions

View File

@ -0,0 +1,352 @@
// Copyright 2017-2019 @polkadot/app-staking 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 { ActionStatus } from '@polkadot/ui-app/Status/types';
import { I18nProps } from './types';
import { Button as SUIB, Popup } from 'semantic-ui-react';
import React from 'react';
import styled from 'styled-components';
import { AddressSummary, Available, Balance, Bonded, CryptoType, Nonce, Unlocking } from '@polkadot/ui-app';
import keyring from '@polkadot/ui-keyring';
import Backup from './modals/Backup';
import ChangePass from './modals/ChangePass';
import Forgetting from './modals/Forgetting';
import translate from './translate';
type Props = I18nProps & {
address: string
};
type State = {
isBackupOpen: boolean,
isForgetOpen: boolean,
isPasswordOpen: boolean
};
const Wrapper = styled.article`
position: relative;
flex: 1 1;
min-width: 24%;
max-width: 24%;
justify-content: space-around;
.accounts--Account-buttons {
text-align: right;
margin-bottom: 2em;
}
.ui--AddressSummary {
justify-content: space-around;
}
.ui--AddressSummary-base {
flex: 1;
padding: 0;
}
.ui--AddressSummary-children {
flex: 1;
display: flex;
align-items: flex-start;
justify-content: flex-end;
}
.account--Account-balances {
display: grid;
grid-column-gap: .5em;
color: #4e4e4e;
opacity: 1;
}
.label-available,
.label-balance,
.label-bonded,
.label-cryptotype,
.label-locked,
.label-nonce,
.label-redeemable {
grid-column: 1;
text-align: right;
}
.result-available,
.result-balance,
.result-bonded,
.result-cryptotype,
.result-locked,
.result-nonce,
.result-redeemable {
grid-column: 2;
}
.accounts--Account-buttons > button {
margin: .2em;
}
@media (max-width: 2060px) {
min-width: 32%;
max-width: 32%;
}
@media (max-width: 1580px) {
min-width: 49%;
max-width: 49%;
}
@media (max-width: 1100px) {
min-width: 100%;
max-width: 100%;
}
`;
class Account extends React.PureComponent<Props> {
state: State;
constructor (props: Props) {
super(props);
this.state = {
isBackupOpen: false,
isForgetOpen: false,
isPasswordOpen: false
};
}
render () {
const { address } = this.props;
return (
<Wrapper className='overview--Account'>
{this.renderModals()}
<AddressSummary
value={address}
identIconSize={96}
isEditable
withBalance={false}
withNonce={false}
withTags
>
<div className='account--Account-expand'>
{this.renderButtons()}
<div className='account--Account-balances'>
{this.renderTotal()}
{this.renderAvailable()}
{this.renderBonded()}
{this.renderUnlocking()}
<br/>
{this.renderNonce()}
{this.renderCryptoType()}
</div>
</div>
</AddressSummary>
</Wrapper>
);
}
private renderAvailable () {
const { address, t } = this.props;
return (
<Available
className='accounts--Account-balances-available'
label={t('available')}
params={address}
/>
);
}
private renderBonded () {
const { address, t } = this.props;
return (
<Bonded
className='accounts--Account-balances-bonded'
label={t('bonded')}
params={address}
/>
);
}
private renderCryptoType () {
const { address, t } = this.props;
return (
<CryptoType
accountId={address}
className='accounts--Account-details-crypto'
label={t('crypto type')}
/>
);
}
private renderModals () {
const { address } = this.props;
const { isBackupOpen, isForgetOpen, isPasswordOpen } = this.state;
if (!address) {
return null;
}
const modals = [];
if (isBackupOpen) {
modals.push(
<Backup
key='modal-backup-account'
onClose={this.toggleBackup}
address={address}
/>
);
}
if (isForgetOpen) {
modals.push(
<Forgetting
address={address}
doForget={this.onForget}
key='modal-forget-account'
onClose={this.toggleForget}
/>
);
}
if (isPasswordOpen) {
modals.push(
<ChangePass
address={address}
key='modal-change-pass'
onClose={this.togglePass}
/>
);
}
return modals;
}
private toggleBackup = (): void => {
const { isBackupOpen } = this.state;
this.setState({
isBackupOpen: !isBackupOpen
});
}
private toggleForget = (): void => {
const { isForgetOpen } = this.state;
this.setState({
isForgetOpen: !isForgetOpen
});
}
private togglePass = (): void => {
const { isPasswordOpen } = this.state;
this.setState({
isPasswordOpen: !isPasswordOpen
});
}
private onForget = (): void => {
const { address, t } = this.props;
if (!address) {
return;
}
const status = {
account: address,
action: 'forget'
} as ActionStatus;
try {
keyring.forgetAccount(address);
status.status = 'success';
status.message = t('account forgotten');
} catch (error) {
status.status = 'error';
status.message = error.message;
}
}
private renderNonce () {
const { address, t } = this.props;
return (
<Nonce
className='accounts--Account-details-nonce'
params={address}
label={t('transactions')}
/>
);
}
private renderTotal () {
const { address, t } = this.props;
return (
<Balance
className='accounts--Account-balances-balance'
label={t('total')}
params={address}
/>
);
}
private renderUnlocking () {
const { address } = this.props;
return (
<Unlocking
className='accounts--Account-balances-unlocking'
params={address}
/>
);
}
private renderButtons () {
// FIXME: The <Popup /> event trigger on='hover' does not work together with the ui-app'
// <Button /> component. That's why the original Semantic UI component is being used here.
return (
<div className='accounts--Account-buttons'>
<Popup
content='Delete this account'
trigger={
<SUIB
negative
onClick={this.toggleForget}
icon='trash'
size='small'
/>
}
wide='very'
/>
<Popup
content='Create a backup file for this account'
trigger={
<SUIB
icon='cloud download'
onClick={this.toggleBackup}
size='small'
/>
}
/>
<Popup
content="Change this account's password"
trigger={
<SUIB
icon='key'
onClick={this.togglePass}
size='small'
/>
}
/>
</div>
);
}
}
export default translate(Account);

View File

@ -1,408 +0,0 @@
// Copyright 2017-2019 @polkadot/app-accounts 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 { KeyringPair } from '@polkadot/keyring/types';
import { I18nProps } from '@polkadot/ui-app/types';
import { ActionStatus } from '@polkadot/ui-app/Status/types';
import { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import { ComponentProps } from './types';
import React from 'react';
import { AddressSummary, Button, Dropdown, Input, InputAddress, InputTags } from '@polkadot/ui-app';
import keyring from '@polkadot/ui-keyring';
import uiSettings from '@polkadot/ui-settings';
import Backup from './modals/Backup';
import ChangePass from './modals/ChangePass';
import Forgetting from './modals/Forgetting';
import translate from './translate';
type Props = ComponentProps & I18nProps & {
allAccounts?: SubjectInfo
};
type State = {
current: KeyringPair | null,
editedName: string,
isBackupOpen: boolean,
isEdited: boolean,
isForgetOpen: boolean,
isPasswordOpen: boolean,
tags: Array<string>
};
class Editor extends React.PureComponent<Props, State> {
state: State;
constructor (props: Props) {
super(props);
this.state = this.createState(null);
}
render () {
return (
<div className='accounts--Editor'>
{this.renderModals()}
{this.renderData()}
{this.renderButtons()}
</div>
);
}
renderButtons () {
const { t } = this.props;
const { current, isEdited } = this.state;
if (!current || current.getMeta().isTesting) {
return null;
}
return (
<Button.Group>
<Button
isNegative
onClick={this.toggleForget}
label={t('Forget')}
/>
<Button.Group.Divider />
<Button
isDisabled={isEdited}
onClick={this.toggleBackup}
label={t('Backup')}
/>
<Button.Or />
<Button
isDisabled={isEdited}
onClick={this.togglePass}
label={t('Change Password')}
/>
<Button.Group.Divider />
<Button
isDisabled={!isEdited}
onClick={this.onDiscard}
label={t('Reset')}
/>
<Button.Or />
<Button
isDisabled={!isEdited}
isPrimary
onClick={this.onCommit}
label={t('Save')}
/>
</Button.Group>
);
}
renderData () {
const { t } = this.props;
const { current, editedName } = this.state;
const address = current
? current.address()
: undefined;
const type = current
? current.type
: 'ed25519';
const isTesting = current
? current.getMeta().isTesting
: false;
return (
<div className='ui--grid'>
<AddressSummary
className='shrink'
value={address || ''}
/>
<div className='grow'>
<div className='ui--row'>
<InputAddress
className='full'
help={t('Select the account you wish to edit.')}
hideAddress
isInput={false}
label={t('account')}
onChange={this.onChangeAccount}
type='account'
value={address}
/>
</div>
<div className='ui--row'>
<Input
className='full'
help={t('Name given to this account. You can edit it. To use the account to validate or nominate, it is a good practice to append the function of the account in the name, e.g "name_you_want - stash".')}
isDisabled={isTesting}
isEditable={!isTesting}
label={t('name')}
onChange={this.onChangeName}
value={editedName}
/>
</div>
<div className='ui--row'>
<Dropdown
defaultValue={type}
help={t('Cryptography used to create this account. It cannot be changed after the account creation. Note that a stash account must use ed25519.')}
isDisabled
label={t('keypair crypto type')}
options={uiSettings.availableCryptos}
/>
</div>
{this.renderTags()}
</div>
</div>
);
}
renderTags () {
const { t } = this.props;
const { current, tags } = this.state;
const showTags = current
? !current.getMeta().isTesting
: true;
if (!showTags) {
return null;
}
return (
<div className='ui--row'>
<InputTags
help={t('Additional user-specified tags that can be used to identify the account. Tags can be used for categorization and filtering.')}
label={t('user-defined tags')}
onChange={this.onChangeTags}
value={tags}
/>
</div>
);
}
renderModals () {
const { onStatusChange } = this.props;
const { current, isBackupOpen, isForgetOpen, isPasswordOpen } = this.state;
if (!current) {
return null;
}
const address = current.address();
const modals = [];
if (isBackupOpen) {
modals.push(
<Backup
key='modal-backup-account'
onClose={this.toggleBackup}
onStatusChange={onStatusChange}
pair={current}
/>
);
}
if (isForgetOpen) {
modals.push(
<Forgetting
address={address}
doForget={this.onForget}
key='modal-forget-account'
onClose={this.toggleForget}
/>
);
}
if (isPasswordOpen) {
modals.push(
<ChangePass
account={current}
key='modal-change-pass'
onClose={this.togglePass}
onStatusChange={onStatusChange}
/>
);
}
return modals;
}
createState (current: KeyringPair | null): State {
const meta = current
? current.getMeta()
: { name: '', tags: [] };
return {
current,
editedName: meta.name || '',
isBackupOpen: false,
isEdited: false,
isForgetOpen: false,
isPasswordOpen: false,
tags: meta.tags || []
};
}
nextState (newState: State = {} as State): void {
this.setState(
(prevState: State): State => {
let { current = prevState.current, editedName = prevState.editedName, tags = prevState.tags } = newState;
const previous = prevState.current || { address: () => undefined };
let isEdited = false;
if (current) {
const meta = current.getMeta();
if (current.address() !== previous.address()) {
editedName = meta.name || '';
tags = meta.tags || [];
} else if (editedName !== meta.name) {
isEdited = true;
}
} else {
editedName = '';
}
return {
current,
editedName,
isBackupOpen: false,
isEdited,
isForgetOpen: false,
isPasswordOpen: false,
tags
} as State;
}
);
}
onChangeAccount = (accountId?: string): void => {
const current = accountId
? keyring.getPair(accountId)
: null;
this.nextState({ current } as State);
}
onChangeName = (editedName: string): void => {
this.nextState({ editedName } as State);
}
onChangeTags = (tags: Array<string>): void => {
this.setState({ isEdited: true, tags });
}
onCommit = (): void => {
const { onStatusChange, t } = this.props;
const { current, editedName, tags } = this.state;
if (!current) {
return;
}
const status = {
account: current.address(),
action: 'edit'
} as ActionStatus;
try {
keyring.saveAccountMeta(current, {
name: editedName,
tags,
whenEdited: Date.now()
});
status.status = current.getMeta().name === editedName ? 'success' : 'error';
status.message = t('account edited');
} catch (error) {
status.status = 'error';
status.message = error.message;
console.error(error);
}
onStatusChange(status);
this.nextState({} as State);
}
onDiscard = (): void => {
const { current } = this.state;
if (!current) {
return;
}
const meta = current.getMeta();
this.nextState({
editedName: meta.name,
tags: meta.tags || []
} as State);
}
toggleBackup = (): void => {
this.setState(
({ isBackupOpen }: State) => ({
isBackupOpen: !isBackupOpen
})
);
}
toggleForget = (): void => {
this.setState(
({ isForgetOpen }: State) => ({
isForgetOpen: !isForgetOpen
})
);
}
togglePass = (): void => {
this.setState(
({ current, isPasswordOpen }: State) => {
if (!current) {
return null;
}
// NOTE We re-get the account from the keyring, if changed it will load the
// new instance (this is not quite obvious...)
return {
current: keyring.getPair(current.publicKey()),
isPasswordOpen: !isPasswordOpen
};
}
);
}
onForget = (): void => {
const { onStatusChange, t } = this.props;
const { current } = this.state;
if (!current) {
return;
}
this.setState(
this.createState(null),
() => {
const status = {
account: current.address(),
action: 'forget'
} as ActionStatus;
try {
keyring.forgetAccount(
current.address()
);
status.status = 'success';
status.message = t('account forgotten');
} catch (error) {
status.status = 'error';
status.message = error.message;
}
onStatusChange(status);
}
);
}
}
export default translate(Editor);

View File

@ -0,0 +1,65 @@
// Copyright 2017-2019 @polkadot/app-staking 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 { ComponentProps } from './types';
import { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import React from 'react';
import styled from 'styled-components';
import accountObservable from '@polkadot/ui-keyring/observable/accounts';
import { withMulti, withObservable } from '@polkadot/ui-api';
import Account from './Account';
type Props = ComponentProps & {
accounts?: SubjectInfo[]
};
const Wrapper = styled.div`
.accounts {
display: flex;
flex-wrap: wrap;
.spacer {
flex: 1 1;
margin: .25rem;
padding: 1rem 1.5rem;
}
}
`;
class Overview extends React.PureComponent<Props> {
constructor (props: Props) {
super(props);
}
render () {
const { accounts } = this.props;
if (!accounts || Object.keys(accounts).length === 0) {
return null;
}
return (
<Wrapper>
<div className='accounts'>
{Object.keys(accounts).map((address) => {
return (
<Account
address={address}
key={address}
/>
);
})}
<div className='spacer' />
</div>
</Wrapper>
);
}
}
export default withMulti(
Overview,
withObservable(accountObservable.subject, { propName: 'accounts' })
);

View File

@ -9,4 +9,4 @@
.accounts--Creator-advanced {
margin-top: 1rem;
}
}

View File

@ -3,21 +3,21 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { AppProps, I18nProps } from '@polkadot/ui-app/types';
import { TabItem } from '@polkadot/ui-app/Tabs';
import { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import { ComponentProps, LocationProps } from './types';
import './index.css';
import { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import React from 'react';
import { Route, Switch } from 'react-router';
import accountObservable from '@polkadot/ui-keyring/observable/accounts';
import { HelpOverlay, Tabs } from '@polkadot/ui-app';
import { TabItem } from '@polkadot/ui-app/Tabs';
import { withMulti, withObservable } from '@polkadot/ui-api';
import './index.css';
import basicMd from './md/basic.md';
import Creator from './Creator';
import Editor from './Editor';
import Overview from './Overview';
import Restore from './Restore';
import translate from './translate';
import Vanity from './Vanity';
@ -39,15 +39,15 @@ class AccountsApp extends React.PureComponent<Props, State> {
const { allAccounts = {}, t } = props;
const baseState = Object.keys(allAccounts).length !== 0
? AccountsApp.showEditState()
: AccountsApp.hideEditState();
? AccountsApp.showVanityState()
: AccountsApp.hideVanityState();
this.state = {
...baseState,
tabs: [
{
name: 'edit',
text: t('Edit account')
name: 'overview',
text: t('Overview')
},
{
hasParams: true,
@ -66,17 +66,18 @@ class AccountsApp extends React.PureComponent<Props, State> {
};
}
static showEditState () {
static showVanityState () {
return {
hidden: []
};
}
static hideEditState () {
static hideVanityState () {
// Hide vanity as well - since the route order and matching changes, the
// /create/:seed route become problematic, so don't allow that option
return {
hidden: ['edit', 'vanity']
hidden: ['vanity']
};
}
@ -86,11 +87,11 @@ class AccountsApp extends React.PureComponent<Props, State> {
if (hidden.length === 0) {
return hasAddresses
? null
: AccountsApp.hideEditState();
: AccountsApp.hideVanityState();
}
return hasAddresses
? AccountsApp.showEditState()
? AccountsApp.showVanityState()
: null;
}
@ -114,13 +115,7 @@ class AccountsApp extends React.PureComponent<Props, State> {
<Route path={`${basePath}/create`} render={renderCreator} />
<Route path={`${basePath}/restore`} render={this.renderComponent(Restore)} />
<Route path={`${basePath}/vanity`} render={this.renderComponent(Vanity)} />
<Route
render={
hidden.includes('edit')
? renderCreator
: this.renderComponent(Editor)
}
/>
<Route render={this.renderComponent(Overview)} />
</Switch>
</main>
);

View File

@ -2,7 +2,6 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringPair } from '@polkadot/keyring/types';
import { I18nProps } from '@polkadot/ui-app/types';
import FileSaver from 'file-saver';
@ -14,9 +13,8 @@ import keyring from '@polkadot/ui-keyring';
import translate from '../translate';
type Props = I18nProps & {
onStatusChange: (status: ActionStatus) => void,
onClose: () => void,
pair: KeyringPair
address: string
};
type State = {
@ -68,7 +66,7 @@ class Backup extends React.PureComponent<Props, State> {
}
private renderContent () {
const { pair, t } = this.props;
const { address, t } = this.props;
const { isPassValid, password } = this.state;
return (
@ -79,7 +77,7 @@ class Backup extends React.PureComponent<Props, State> {
<Modal.Content className='app--account-Backup-content'>
<AddressRow
isInline
value={pair.address()}
value={address}
>
<p>{t('An encrypted backup file will be created once you have pressed the "Download" button. This can be used to re-import your account on any other machine.')}</p>
<p>{t('Save this backup file in a secure location. Additionally, the password associated with this account is needed together with this backup file in order to restore your account.')}</p>
@ -100,10 +98,10 @@ class Backup extends React.PureComponent<Props, State> {
}
private doBackup = (): void => {
const { onClose, onStatusChange, pair, t } = this.props;
const { onClose, address, t } = this.props;
const { password } = this.state;
if (!pair) {
if (!address) {
return;
}
@ -112,14 +110,15 @@ class Backup extends React.PureComponent<Props, State> {
} as ActionStatus;
try {
const json = keyring.backupAccount(pair, password);
const addressKeyring = address && keyring.getPair(address);
const json = addressKeyring && keyring.backupAccount(addressKeyring, password);
const blob = new Blob([JSON.stringify(json)], { type: 'application/json; charset=utf-8' });
status.account = pair.address();
status.account = address;
status.status = blob ? 'success' : 'error';
status.message = t('account backed up');
FileSaver.saveAs(blob, `${pair.address()}.json`);
FileSaver.saveAs(blob, `${address}.json`);
} catch (error) {
this.setState({ isPassValid: false });
console.error(error);
@ -129,8 +128,6 @@ class Backup extends React.PureComponent<Props, State> {
return;
}
onStatusChange(status);
onClose();
}

View File

@ -2,7 +2,6 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringPair } from '@polkadot/keyring/types';
import { I18nProps } from '@polkadot/ui-app/types';
import React from 'react';
@ -13,9 +12,8 @@ import keyring from '@polkadot/ui-keyring';
import translate from '../translate';
type Props = I18nProps & {
account: KeyringPair,
onClose: () => void,
onStatusChange: (status: ActionStatus) => void
address: string,
onClose: () => void
};
type State = {
@ -71,7 +69,7 @@ class ChangePass extends React.PureComponent<Props, State> {
}
private renderContent () {
const { account, t } = this.props;
const { address, t } = this.props;
const { isNewValid, isOldValid, newPass, oldPass } = this.state;
return (
@ -82,7 +80,7 @@ class ChangePass extends React.PureComponent<Props, State> {
<Modal.Content>
<AddressRow
isInline
value={account.address()}
value={address}
>
<p>{t('This will apply to any future use of this account as stored on this browser. Ensure that you securely store this new password and that it is strong and unique to the account.')}</p>
<div>
@ -111,44 +109,52 @@ class ChangePass extends React.PureComponent<Props, State> {
}
private doChange = (): void => {
const { account, onClose, onStatusChange, t } = this.props;
const { address, onClose, t } = this.props;
const { newPass, oldPass } = this.state;
const status = {
action: 'changePassword'
} as ActionStatus;
try {
if (!account.isLocked()) {
account.lock();
const account = address && keyring.getPair(address);
if (!account) {
status.message = t(`No keypair found for this address ${address}`);
return;
}
account.decodePkcs8(oldPass);
} catch (error) {
this.setState({ isOldValid: false });
try {
if (!account.isLocked()) {
account.lock();
}
account.decodePkcs8(oldPass);
} catch (error) {
this.setState({ isOldValid: false });
status.message = error.message;
return;
}
try {
keyring.encryptAccount(account, newPass);
status.account = address;
status.status = 'success';
status.message = t('password changed');
} catch (error) {
this.setState({ isNewValid: false });
status.status = 'error';
status.message = error.message;
return;
}
} catch (error) {
status.message = error.message;
return;
}
try {
keyring.encryptAccount(account, newPass);
status.account = account.address();
status.status = 'success';
status.message = t('password changed');
} catch (error) {
this.setState({ isNewValid: false });
status.status = 'error';
status.message = error.message;
return;
}
onStatusChange(status);
onClose();
}
@ -167,6 +173,7 @@ class ChangePass extends React.PureComponent<Props, State> {
}
private validatePass (password: string): boolean {
return keyring.isPassValid(password);
}
}

View File

@ -17,6 +17,7 @@ type Props = I18nProps & {
class Forgetting extends React.PureComponent<Props> {
render () {
return (
<Modal
className='accounts--Forgetting-Modal'

View File

@ -4,10 +4,21 @@
import { AppProps } from '@polkadot/ui-app/types';
import { WithTranslation } from 'react-i18next';
export type LocationProps = {
match: {
params: { [index: string]: any }
}
};
export type BareProps = {
className?: string,
style?: {
[index: string]: any
}
};
export type I18nProps = BareProps & WithTranslation;
export type ComponentProps = AppProps & LocationProps;

View File

@ -97,7 +97,6 @@ class Address extends React.PureComponent<Props, State> {
value={stashId}
withBalance={false}
withBonded
withCopy={false}
withNonce={false}
>
{this.renderKeys()}

View File

@ -116,7 +116,6 @@
}
}
@media (min-width: 1281px) {
.ui--AddressSummary {
display: flex;
justify-content: space-between;
@ -126,7 +125,6 @@
min-width: 0;
}
}
}
@media (max-width: 1280px) {
.staking--Account {

View File

@ -144,7 +144,6 @@ class Transfer extends React.PureComponent<Props, State> {
<div className={`transfer--Transfer-address ui--media-${media}`}>
<AddressSummary
value={accountId}
withCopy={false}
/>
</div>
);

View File

@ -52,8 +52,10 @@ export default class AddressMini extends React.PureComponent<Props> {
size={24}
value={address}
/>
{this.renderBalance()}
{this.renderBonded()}
<div className='ui--AddressMini-balances'>
{this.renderBalance()}
{this.renderBonded()}
</div>
</div>
);
}

View File

@ -21,10 +21,15 @@ class AddressRow extends AddressSummary {
<div className='ui--AddressRow-base'>
{this.renderIcon('ui--AddressRow-icon', identIconSize)}
<div className='ui--AddressRow-details'>
{this.renderAddress()}
{this.renderBalance()}
{this.renderBonded()}
{this.renderNonce()}
<div className='ui--AddressSummary-data'>
{this.renderName()}
{this.renderAddress()}
</div>
<div className='ui--AddressSummary-balances'>
{this.renderBalance()}
{this.renderBonded()}
{this.renderNonce()}
</div>
</div>
</div>
{this.renderChildren()}

View File

@ -2,21 +2,24 @@
// 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 } from '@polkadot/types';
import { I18nProps } from './types';
import BN from 'bn.js';
import { Label } from 'semantic-ui-react';
import React from 'react';
import { AccountId, AccountIndex, Address } from '@polkadot/types';
import { Nonce } from '@polkadot/ui-reactive';
import { withCalls } from '@polkadot/ui-api';
import BaseIdentityIcon from '@polkadot/ui-identicon';
import { Button, Input, InputTags } from '@polkadot/ui-app';
import keyring from '@polkadot/ui-keyring';
import { withCalls } from '@polkadot/ui-api';
import AvailableDisplay from './Available';
import { classes, getAddrName, toShortAddress } from './util';
import BalanceDisplay from './Balance';
import BondedDisplay from './Bonded';
import { classes, getAddrName, toShortAddress } from './util';
import CopyButton from './CopyButton';
import IdentityIcon from './IdentityIcon';
import NonceDisplay from './Nonce';
import translate from './translate';
import UnlockingDisplay from './Unlocking';
@ -28,6 +31,7 @@ export type Props = I18nProps & {
defaultName?: string,
extraInfo?: React.ReactNode,
identIconSize?: number,
isEditable?: boolean,
isInline?: boolean,
isShort?: boolean,
session_validators?: Array<AccountId>,
@ -35,16 +39,48 @@ export type Props = I18nProps & {
withAvailable?: boolean,
withBalance?: boolean,
withBonded?: boolean,
withCopy?: boolean,
withIcon?: boolean,
withIndex?: boolean,
withNonce?: boolean,
withTags?: boolean,
withUnlocking?: boolean
};
type State = {
isEditingName: boolean
isEditingTags: boolean
name: string
tags: string[]
};
const DEFAULT_ADDR = '5'.padEnd(16, 'x');
class AddressSummary extends React.PureComponent<Props> {
class AddressSummary extends React.PureComponent<Props, State> {
state: State;
constructor (props: Props) {
super(props);
this.state = this.createState();
}
createState () {
const { accounts_idAndIndex = [], defaultName, value } = this.props;
const [_accountId] = accounts_idAndIndex;
const accountId = _accountId || value;
const address = accountId
? accountId.toString()
: DEFAULT_ADDR;
const name = getAddrName(address, false, defaultName) || '';
const tags = this.getAddressTags(address);
return {
isEditingName: false,
isEditingTags: false,
name,
tags: tags
};
}
render () {
const { accounts_idAndIndex = [], className, isInline, style } = this.props;
const [accountId, accountIndex] = accounts_idAndIndex;
@ -57,78 +93,119 @@ class AddressSummary extends React.PureComponent<Props> {
>
<div className='ui--AddressSummary-base'>
{this.renderIcon()}
{this.renderAccountId()}
{this.renderAccountIndex()}
{this.renderAvailable()}
{this.renderBalance()}
{this.renderBonded()}
{this.renderNonce()}
{this.renderUnlocking()}
<div className='ui--AddressSummary-data'>
{this.renderName()}
{this.renderAddress()}
{this.renderAccountIndex()}
</div>
<div className='ui--AddressSummary-balances'>
{this.renderAvailable()}
{this.renderBalance()}
{this.renderBonded()}
{this.renderNonce()}
{this.renderUnlocking()}
</div>
{this.renderTags()}
</div>
{this.renderChildren()}
</div>
);
}
protected renderAddress () {
const { defaultName, isShort = true, value } = this.props;
if (!value) {
return null;
protected getAddressTags (address: string): Array<string> {
try {
if (keyring.getAccount(address).isValid()) {
const addressKeyring = address && keyring.getPair(address);
return addressKeyring && addressKeyring.getMeta().tags || [];
}
} catch (error) {
// all-ok, we have empty fallbacks
}
const address = value.toString();
const name = getAddrName(address, false, defaultName);
return (
<div className='ui--AddressSummary-data'>
<div className='ui--AddressSummary-name'>
{name}
</div>
<div className='ui--AddressSummary-accountId'>
{
isShort
? toShortAddress(address)
: value
}
</div>
</div>
);
return [];
}
protected renderAccountId () {
const { accounts_idAndIndex = [], defaultName, isShort = true, value } = this.props;
const [_accountId, accountIndex] = accounts_idAndIndex;
const accountId = _accountId || value;
protected renderAddress () {
const { isShort = true, value } = this.props;
if (!accountId && accountIndex) {
return null;
}
const address = accountId
? accountId.toString()
const address = value
? value.toString()
: DEFAULT_ADDR;
const name = getAddrName(address, false, defaultName);
const addrElem = isShort
? (
<CopyButton
isAddress
value={address}
>
<span>{toShortAddress(address)}</span>
</CopyButton>
)
: address;
? (
<CopyButton
isAddress
value={address}
>
<span>{toShortAddress(address)}</span>
</CopyButton>
)
: address;
return (
<div className='ui--AddressSummary-data'>
<>
<div className='ui--AddressSummary-name'>
{name}
</div>
<div className='ui--AddressSummary-accountId'>
{addrElem}
</div>
</div>
</>
);
}
protected renderName () {
const { isEditable } = this.props;
const { isEditingName, name } = this.state;
const resultingDom = isEditingName ?
<>
<Input
autoFocus
defaultValue={name}
className='full'
onBlur={this.saveName}
onChange={this.onChangeName}
onEnter={this.saveName}
withLabel={false}
/>
</>
:
<div
className={classes('ui--AddressSummary-name', isEditable && 'editable')}
onClick={isEditable ? this.toggleNameEditor : undefined}
>
{name}
{isEditable && this.renderEditIcon(this.toggleNameEditor)}
</div>;
return resultingDom;
}
protected onChangeName = (name: string) => {
this.setState({ name });
}
protected onChangeTags = (tags: string[]) => {
this.setState({ tags : tags });
}
protected renderAvailable () {
const { accounts_idAndIndex = [], t, value, withAvailable } = this.props;
const [_accountId] = accounts_idAndIndex;
const accountId = _accountId || value;
if (!withAvailable || !accountId) {
return null;
}
return (
<AvailableDisplay
className='ui--AddressSummary-available'
label={t('available ')}
params={accountId}
/>
);
}
@ -140,15 +217,10 @@ class AddressSummary extends React.PureComponent<Props> {
return null;
}
const address = accountIndex.toString();
return (
<div className='ui--AddressSummary-data'>
<div className='ui--AddressSummary-name'></div>
<div className='ui--AddressSummary-accountIndex'>
{address}
{accountIndex.toString()}
</div>
</div>
);
}
@ -190,37 +262,30 @@ class AddressSummary extends React.PureComponent<Props> {
);
}
protected renderAvailable () {
const { accounts_idAndIndex = [], t, value, withAvailable } = this.props;
const [_accountId] = accounts_idAndIndex;
const accountId = _accountId || value;
protected renderChildren () {
const { children } = this.props;
if (!withAvailable || !accountId) {
if (!children || (Array.isArray(children) && children.length === 0)) {
return null;
}
return (
<AvailableDisplay
className='ui--AddressSummary-available'
label={t('available ')}
params={accountId}
/>
<div className='ui--AddressSummary-children'>
{children}
</div>
);
}
protected renderUnlocking () {
const { accounts_idAndIndex = [], value, withUnlocking } = this.props;
const [_accountId] = accounts_idAndIndex;
const accountId = _accountId || value;
if (!withUnlocking || !accountId) {
return null;
}
protected renderEditIcon (callback: () => void) {
return (
<UnlockingDisplay
className='ui--AddressSummary-available'
params={accountId}
<Button
className='editButton'
onClick={callback}
icon='edit'
size='mini'
isPrimary
key='unlock'
/>
);
}
@ -260,28 +325,124 @@ class AddressSummary extends React.PureComponent<Props> {
}
return (
<Nonce
<NonceDisplay
className='ui--AddressSummary-nonce'
params={accountId.toString()}
>
{t(' transactions')}
</Nonce>
label={t('transactions ')}
params={accountId}
/>
);
}
protected renderChildren () {
const { children } = this.props;
protected renderSaveIcon (callback: () => void) {
return (
<Button
className='saveButton'
onClick={callback}
icon='save'
size='small'
isPrimary
key='save'
/>
);
}
if (!children || (Array.isArray(children) && children.length === 0)) {
protected renderTags () {
const { isEditingTags, tags } = this.state;
const { isEditable, withTags = false } = this.props;
if (!withTags) {
return null;
}
const resultingDom = isEditingTags ?
<>
<InputTags
className='ui--AddressSummary-tags-input'
onBlur={this.saveTags}
onChange={this.onChangeTags}
onClose={this.saveTags}
openOnFocus
defaultValue = {tags}
searchInput={{ autoFocus: true }}
value={tags}
withLabel={false}
/>
</>
:
<div
className={classes('ui--AddressSummary-tags', isEditable && 'editable')}
onClick={isEditable ? this.toggleTagsEditor : undefined}
>
{
!tags.length
? <span>add tags</span>
: tags.map((tag) => {
return (
<Label key={tag} size='tiny' color='grey'>
{tag}
</Label>
);
})
}
{isEditable && this.renderEditIcon(this.toggleTagsEditor)}
</div>;
return resultingDom;
}
protected renderUnlocking () {
const { accounts_idAndIndex = [], value, withUnlocking } = this.props;
const [_accountId] = accounts_idAndIndex;
const accountId = _accountId || value;
if (!withUnlocking || !accountId) {
return null;
}
return (
<div className='ui--AddressSummary-children'>
{children}
</div>
<UnlockingDisplay
className='ui--AddressSummary-available'
params={accountId}
/>
);
}
protected saveName = () => {
const { value } = this.props;
const { name } = this.state;
const trimmedName = name.trim();
// Save only if the name was changed or if it's no empty.
if (trimmedName && value) {
const currentKeyring = keyring.getPair(value.toString());
currentKeyring && keyring.saveAccountMeta(currentKeyring, { name: trimmedName, whenEdited: Date.now() });
this.toggleNameEditor();
}
}
protected saveTags = () => {
const { value } = this.props;
const { tags } = this.state;
if (value) {
const currentKeyring = keyring.getPair(value.toString());
currentKeyring && keyring.saveAccountMeta(currentKeyring, { tags, whenEdited: Date.now() });
this.toggleTagsEditor();
}
}
protected toggleNameEditor = () => {
const { value } = this.props;
if (value && keyring.getPair(value.toString())) {
this.setState({ isEditingName : !this.state.isEditingName });
}
}
protected toggleTagsEditor = () => {
this.setState({ isEditingTags : !this.state.isEditingTags });
}
}
export {

View File

@ -12,8 +12,7 @@ import { classes } from './util';
export type Props = BareProps & {
label?: string,
params?: AccountId | AccountIndex | Address | string | Uint8Array | null,
withLabel?: boolean
params?: AccountId | AccountIndex | Address | string | Uint8Array | null
};
export default class AvailableDisplay extends React.PureComponent<Props> {

View File

@ -33,6 +33,7 @@ class CopyButtonInner extends React.PureComponent<InnerProps> {
return (
<div className={className}>
{children}
<CopyToClipboard
onCopy={this.onCopy}
text={value}
@ -46,7 +47,6 @@ class CopyButtonInner extends React.PureComponent<InnerProps> {
style={style}
/>
</CopyToClipboard>
{children}
</div>
);
}

View File

@ -0,0 +1,35 @@
// Copyright 2017-2019 @polkadot/ui-app 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 } from '@polkadot/types';
import { BareProps } from './types';
import React from 'react';
import keyring from '@polkadot/ui-keyring';
import { classes } from './util';
type Props = BareProps & {
accountId: AccountId | AccountIndex | Address | string | Uint8Array | null,
label?: string
};
export default class CryptoType extends React.PureComponent<Props> {
render () {
const { accountId, className, label = '' } = this.props;
const current = accountId
? keyring.getPair(accountId.toString())
: null;
const type = current
? current.type
: 'ed25519';
return (
<>
<span className={classes('ui--CryptoType label-cryptotype', className)}>{label}</span>
<span className={classes('ui--CryptoType result-cryptotype', className)}>{type}</span>
</>
);
}
}

View File

@ -23,11 +23,14 @@ type Props<Option> = BareProps & {
isMultiple?: boolean,
label?: React.ReactNode,
onAdd?: (value: any) => void,
onBlur?: () => void,
onChange?: (value: any) => void,
onClose?: () => void,
onSearch?: (filteredOptions: Array<any>, query: string) => Array<Option>,
options: Array<Option>,
placeholder?: string,
renderLabel?: (item: any) => any,
searchInput?: {autoFocus: boolean},
transform?: (value: any) => any,
value?: any,
withEllipsis?: boolean,
@ -61,7 +64,7 @@ export default class Dropdown<Option> extends React.PureComponent<Props<Option>>
}
render () {
const { allowAdd = false, className, defaultValue, dropdownClassName, help, isButton, isDisabled, isError, isMultiple, label, onSearch, options, placeholder, renderLabel, style, withEllipsis, withLabel, value } = this.props;
const { allowAdd = false, className, defaultValue, dropdownClassName, help, isButton, isDisabled, isError, isMultiple, label, onSearch, options, placeholder, renderLabel, searchInput, style, withEllipsis, withLabel, value } = this.props;
const dropdown = (
<SUIDropdown
allowAdditions={allowAdd}
@ -73,11 +76,14 @@ export default class Dropdown<Option> extends React.PureComponent<Props<Option>>
floating={isButton}
multiple={isMultiple}
onAddItem={this.onAddItem}
onBlur={this.onBlur}
onChange={this.onChange}
onClose={this.onClose}
options={options}
placeholder={placeholder}
renderLabel={renderLabel}
search={!!onSearch || allowAdd}
searchInput={searchInput}
selection
value={
isUndefined(value)
@ -113,6 +119,12 @@ export default class Dropdown<Option> extends React.PureComponent<Props<Option>>
onAdd && onAdd(value);
}
private onBlur = (): void => {
const { onBlur } = this.props;
onBlur && onBlur();
}
private onChange = (_: React.SyntheticEvent<HTMLElement>, { value }: DropdownProps): void => {
const { onChange, transform } = this.props;
@ -122,4 +134,10 @@ export default class Dropdown<Option> extends React.PureComponent<Props<Option>>
: value
);
}
private onClose = (): void => {
const { onClose } = this.props;
onClose && onClose();
}
}

View File

@ -30,7 +30,7 @@ type Props = BareProps & {
name?: string,
onEnter?: () => void,
onChange?: (value: string) => void,
onBlur?: (event: React.KeyboardEvent<Element>) => void,
onBlur?: () => void,
onKeyDown?: (event: React.KeyboardEvent<Element>) => void,
onKeyUp?: (event: React.KeyboardEvent<Element>) => void,
onKeyPress?: (event: React.KeyboardEvent<Element>) => void,
@ -131,6 +131,7 @@ export default class Input extends React.PureComponent<Props, State> {
maxLength={maxLength}
min={min}
name={name || this.state.name}
onBlur={this.onBlur}
onChange={this.onChange}
onKeyDown={this.onKeyDown}
onKeyUp={this.onKeyUp}
@ -174,6 +175,14 @@ export default class Input extends React.PureComponent<Props, State> {
}
}
private onBlur = (): void => {
const { onBlur } = this.props;
if (onBlur) {
onBlur();
}
}
private onKeyUp = (event: React.KeyboardEvent<Element>): void => {
const { onEnter, onKeyUp } = this.props;

View File

@ -22,9 +22,14 @@ type Props = BareProps & {
isDisabled?: boolean,
isError?: boolean,
label?: React.ReactNode,
onBlur?: () => void;
onChange?: (value: Array<string>) => void,
onClose?: () => void;
openOnFocus?: boolean;
placeholder?: string,
value?: Array<string>
searchInput?: {autoFocus: boolean},
value?: Array<string>,
withLabel?: boolean
};
type State = {
@ -49,12 +54,13 @@ export default class InputTags extends React.PureComponent<Props> {
};
render () {
const { defaultValue, help, isDisabled, isError, label, onChange, placeholder, value } = this.props;
const { className, defaultValue, help, isDisabled, isError, label, onBlur, onChange, onClose, placeholder, searchInput, value, withLabel } = this.props;
const { options } = this.state;
return (
<Dropdown
allowAdd={!isDisabled}
className={className}
defaultValue={defaultValue}
help={help}
isDisabled={isDisabled}
@ -62,10 +68,14 @@ export default class InputTags extends React.PureComponent<Props> {
isMultiple
label={label}
onAdd={this.onAdd}
onBlur={onBlur}
onChange={onChange}
onClose={onClose}
options={options}
placeholder={placeholder}
searchInput={searchInput}
value={value}
withLabel={withLabel}
/>
);
}

View File

@ -0,0 +1,35 @@
// Copyright 2017-2019 @polkadot/ui-app 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 { BareProps } from './types';
import React from 'react';
import { AccountId, AccountIndex, Address } from '@polkadot/types';
import { Nonce } from '@polkadot/ui-reactive';
import { classes } from './util';
export type Props = BareProps & {
label?: string,
params?: AccountId | AccountIndex | Address | string | Uint8Array | null
};
export default class NonceDisplay extends React.PureComponent<Props> {
render () {
const { className, label, params, style } = this.props;
if (!params) {
return null;
}
return (
<Nonce
className={classes('ui--Nonce', className)}
label={label}
params={params.toString()}
style={style}
/>
);
}
}

View File

@ -5,13 +5,16 @@
export { default as AddressMini } from './AddressMini';
export { default as AddressRow } from './AddressRow';
export { default as AddressSummary } from './AddressSummary';
export { default as Available } from './Available';
export { default as Balance } from './Balance';
export { default as Bonded } from './Bonded';
export { default as Bubble } from './Bubble';
export { default as Button } from './Button';
export { default as Call } from './Call';
export { default as CardSummary } from './CardSummary';
export { default as Chart } from './Chart';
export { default as CopyButton } from './CopyButton';
export { default as CryptoType } from './CryptoType';
export { default as Dropdown } from './Dropdown';
export { default as Editor } from './Editor';
export { default as Event } from './Event';
@ -34,6 +37,7 @@ export { default as InputTags } from './InputTags';
export { default as Labelled } from './Labelled';
export { default as Menu } from './Menu';
export { default as Modal } from './Modal';
export { default as Nonce } from './Nonce';
export { default as Output } from './Output';
export { default as Password } from './Password';
export { default as Progress } from './Progress';
@ -42,6 +46,8 @@ export { default as Static } from './Static';
export { default as Status } from './Status';
export { default as SummaryBox } from './SummaryBox';
export { default as Tabs } from './Tabs';
export { default as Tooltip } from './Tooltip';
export { default as TxButton } from './TxButton';
export { default as Unlocking } from './Unlocking';
export { default as media } from './media';

View File

@ -94,4 +94,11 @@ article {
margin: 0;
padding: 0;
}
&:not(:hover) {
.ui.button {
background: #eee !important;
color: #555 !important;
}
}
}

View File

@ -68,14 +68,6 @@ header .ui--Button-Group {
margin-left: 0.5rem;
margin-right: 0;
}
.ui--Balance,
.ui--Bonded {
font-size: 0.75rem;
margin-right: 2.25rem;
margin-top: -0.5rem;
text-align: right;
}
}
.ui--AddressMini-address {
@ -84,7 +76,9 @@ header .ui--Button-Group {
}
&.withName {
text-align: right;
text-transform: uppercase;
min-width: 4em;
}
}
@ -98,13 +92,64 @@ header .ui--Button-Group {
.ui--AddressSummary {
padding: 0 1em;
/* text-align: left; */
white-space: nowrap
}
.ui--AddressSummary-available > button.ui.icon.withDrawUnbonded {
button.ui.icon.withDrawUnbonded {
padding: 0.3em;
margin-left: 0.4em;
margin-left: 0.3em;
color: #2e86ab;
background: none !important;
&:hover {
color: #fff !important;
background-color: #2e86ab !important;
}
}
.result-locked > i {
margin-left: .3em
}
.overview--Account:hover button.ui.icon.editButton,
.overview--Account:hover button.ui.icon.editButton {
visibility: visible;
}
.overview--Account button.ui.icon.editButton,
.overview--Account button.ui.icon.editButton {
visibility: hidden;
}
.ui--AddressSummary-name.editable > button.ui.icon.editButton,
.ui--AddressSummary-tags.editable > button.ui.icon.editButton {
padding: 0em .3em .3em .3em;
color: #2e86ab;
background: none;
/*trick to let the button in the flow but keep the content centered regardless*/
margin-left: -2em;
position: relative;
right: -2.3em;
}
.ui--AddressSummary-tags.editable {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.ui--AddressSummary-tags.editable > span {
border: 1px #00000052 solid;
border-radius: .5em;
border-style: dashed;
color: grey;
font-size: x-small;
padding: .1em 0.3em 0.1em 0.3em;
margin-top: .2em;
}
.ui--AddressSummary-tags.editable > div.label {
margin-top:.3em
}
.ui--AddressSummary-base {
@ -130,6 +175,15 @@ header .ui--Button-Group {
.ui--AddressSummary-children {
display: block;
}
.ui--AddressRow-details {
text-align: left;
white-space: nowrap;
}
.ui--AddressSummary-balances>span {
text-align: left;
}
}
.ui--AddressSummary .rx--updated {
@ -145,25 +199,57 @@ header .ui--Button-Group {
display: block
}
.ui--Balance,
.ui--AddressSummary-balance,
.ui--AddressSummary-bonded,
.ui--AddressSummary-nonce {
font-weight: 100;
opacity: 0.75;
}
.ui--Bonded {
opacity: 1;
color: green;
}
.ui--AddressSummary-data+.ui--AddressSummary-balance,
.ui--AddressSummary-data+.ui--AddressSummary-bonded,
.ui--AddressSummary-data+.ui--AddressSummary-nonce {
padding-top: 0.5em;
}
.ui--AddressSummary-balances {
display: grid;
grid-column-gap: 1em;
}
.ui--AddressMini-balances {
display: grid;
}
.label-available,
.label-balance,
.label-bonded,
.label-cryptotype,
.label-locked,
.label-nonce,
.label-redeemable {
grid-column: 1;
text-align: right;
opacity: 0.7;
}
.result-available,
.result-balance,
.result-bonded,
.result-locked,
.result-redeemable {
grid-column: 2;
text-align: left;
}
.result-nonce,
.result-cryptotype {
text-align: left;
opacity: 0.7;
}
.ui--AddressMini-balances .ui--Bonded.result-bonded,
.ui--AddressMini-balances .ui--Bonded {
font-size: .75rem;
margin-right: 2.25rem;
margin-top: -.5rem;
text-align: right;
}
.ui--AddressSummary-balance.rx--updated,
.ui--AddressSummary-nonce.rx--updated {
opacity: 1;
@ -184,7 +270,6 @@ header .ui--Button-Group {
.ui--AddressSummary-accountId,
.ui--AddressSummary-accountIndex {
display: inline-block;
font-family: monospace;
font-size: 1.5em;
padding: 0;
@ -195,6 +280,18 @@ header .ui--Button-Group {
font-style: italic;
}
.ui--AddressSummary-data .ui--Input input {
height: 1em;
text-align: center;
text-transform: uppercase;
margin-top: -.3em;
margin-bottom: -.35em;
}
.ui--AddressSummary-tags-input {
margin-bottom: -1.4em;
}
.ui--Bubble.ui.label {
font-weight: normal;
margin: 0.25rem;
@ -240,6 +337,9 @@ header .ui--Button-Group {
cursor: copy !important;
margin-left: 0.25rem !important;
margin-right: 0.25rem !important;
position: relative;
margin-left: -3em!important;
right: -3.3em;
}
.ui--DropdownLinked.ui--row {

View File

@ -2,12 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { BareProps, CallProps } from '@polkadot/ui-api/types';
import { AccountId, AccountIndex, Address } from '@polkadot/types';
import { BareProps, CallProps } from '@polkadot/ui-api/types';
import { DerivedBalances } from '@polkadot/api-derive/types';
import { formatBalance } from '@polkadot/util';
import React from 'react';
import { formatBalance } from '@polkadot/util';
import { withCalls } from '@polkadot/ui-api';
type Props = BareProps & CallProps & {
@ -18,21 +18,22 @@ type Props = BareProps & CallProps & {
};
export class AvailableDisplay extends React.PureComponent<Props> {
render () {
const { balances_all, children, className, label = '', style } = this.props;
const { balances_all, children, className, label = '' } = this.props;
return (
<div
className={className}
style={style}
>
{label}{
balances_all ?
formatBalance(balances_all.availableBalance) :
'0'
}{children}
</div>
<>
<span className={className + ' label-available'}>
{label}
</span>
<span className={className + ' result-available'}>
{
balances_all ?
formatBalance(balances_all.availableBalance) :
'0'
}
</span>{children}
</>
);
}
}

View File

@ -20,19 +20,24 @@ type Props = BareProps & CallProps & {
export class BalanceDisplay extends React.PureComponent<Props> {
render () {
const { children, className, label = '', style, balances_all } = this.props;
const { children, className, label = '', balances_all } = this.props;
return (
<div
className={className}
style={style}
>
{label}{
balances_all
<>
<span
className={`${className} label-balance`}
>
{label}
</span>
<span
className={`${className} result-balance`}
>
{balances_all
? formatBalance(balances_all.freeBalance)
: '0'
}{children}
</div>
}
</span>{children}
</>
);
}
}

View File

@ -19,7 +19,7 @@ type Props = BareProps & CallProps & {
export class BondedDisplay extends React.PureComponent<Props> {
render () {
const { children, className, label = '', style, staking_ledger } = this.props;
const { children, className, label = '', staking_ledger } = this.props;
if (!staking_ledger || staking_ledger.isNone) {
return null;
@ -28,16 +28,19 @@ export class BondedDisplay extends React.PureComponent<Props> {
const { active: bonded } = staking_ledger.unwrap();
return (
<div
className={className}
style={style}
>
{label}{
bonded
? formatBalance(bonded)
: '0'
}{children}
</div>
<>
<span className={className + ' label-bonded'}>
{label}
</span>
<span className={className + ' result-bonded'}>
{
bonded
? formatBalance(bonded)
: '0'
}
</span>
{children}
</>
);
}
}

View File

@ -3,12 +3,12 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { BareProps, CallProps } from '@polkadot/ui-api/types';
import { Index } from '@polkadot/types';
import BN from 'bn.js';
import React from 'react';
import { Index } from '@polkadot/types';
import { withCalls } from '@polkadot/ui-api';
import { formatNumber } from '@polkadot/util';
import { withCalls } from '@polkadot/ui-api';
type Props = BareProps & CallProps & {
callOnResult?: (accountNonce: BN) => void,
@ -20,19 +20,21 @@ type Props = BareProps & CallProps & {
export class Nonce extends React.PureComponent<Props> {
render () {
const { children, className, label = '', style, system_accountNonce } = this.props;
const { children, className, label = '', system_accountNonce } = this.props;
return (
<div
className={className}
style={style}
>
{label}{
system_accountNonce
? formatNumber(system_accountNonce)
: '0'
}{children}
</div>
<>
<span className={className + ' label-nonce'}>
{label}
</span>
<span className={className + ' result-nonce'}>
{
system_accountNonce
? formatNumber(system_accountNonce)
: '0'
}
</span>{children}
</>
);
}
}

View File

@ -4,12 +4,13 @@
import { AccountId, AccountIndex, Address, BlockNumber, Option, StakingLedger, UnlockChunk } from '@polkadot/types';
import { BareProps, CallProps } from '@polkadot/ui-api/types';
import BN from 'bn.js';
import { formatBalance } from '@polkadot/util';
import { I18nProps } from '@polkadot/ui-app/types';
import React from 'react';
import { formatBalance } from '@polkadot/util';
import { Icon, Tooltip, TxButton } from '@polkadot/ui-app';
import { I18nProps } from '@polkadot/ui-app/types';
import translate from '@polkadot/ui-app/translate';
import { TxButton } from '@polkadot/ui-app';
import { withCalls } from '@polkadot/ui-api';
type Props = BareProps & CallProps & I18nProps & {
@ -22,7 +23,22 @@ type Props = BareProps & CallProps & I18nProps & {
unlockings?: Array<UnlockChunk>
};
export class UnlockingDisplay extends React.PureComponent<Props> {
type State = {
tooltipOpen: boolean
};
export class UnlockingDisplay extends React.PureComponent<Props, State> {
constructor (props: Props) {
super(props);
this.state = {
tooltipOpen: false
};
}
toggleTooltip () {
const { tooltipOpen } = this.state;
this.setState({ tooltipOpen: !tooltipOpen });
}
render () {
const { unlockings } = this.props;
@ -63,7 +79,8 @@ export class UnlockingDisplay extends React.PureComponent<Props> {
}
private renderLocked () {
const { className, controllerId, style, t, unlockings } = this.props;
const { className, controllerId, t, unlockings } = this.props;
const { tooltipOpen } = this.state;
if (!unlockings || !controllerId) return null;
// select the Unlockchunks that can't be unlocked yet.
@ -74,25 +91,40 @@ export class UnlockingDisplay extends React.PureComponent<Props> {
return (
<>
{groupedUnlockings && Object.keys(groupedUnlockings).map(eraString => (
<div
className={className}
style={style}
key={eraString}
>
{t('locked {{balance}} ({{remaining}} blocks left)', {
replace: {
balance: formatBalance(groupedUnlockings[eraString]),
remaining: this.remainingBlocks(new BlockNumber(eraString))
}
})}
</div>
<React.Fragment key={eraString}>
<span
className={className + ' label-locked'}
>
{t('locked')}
</span>
<span
className={className + ' result-locked'}
>
{formatBalance(groupedUnlockings[eraString])}
<Icon
name='info circle'
data-tip
data-for={'controlled-trigger' + eraString}
onMouseOver={() => this.toggleTooltip()}
onMouseOut={() => this.toggleTooltip()}
/>
{tooltipOpen && (
<Tooltip trigger={'controlled-trigger' + eraString}>
{t('{{remaining}} blocks left', {
replace: {
remaining: this.remainingBlocks(new BlockNumber(eraString))
}
})}
</Tooltip>)}
</span>
</React.Fragment>
))}
</>
);
}
private renderUnlockableSum () {
const { className, controllerId, style, t, unlockings } = this.props;
const { className, controllerId, t, unlockings } = this.props;
if (!unlockings || !unlockings[0] || !controllerId) return null;
@ -104,27 +136,23 @@ export class UnlockingDisplay extends React.PureComponent<Props> {
).value;
return (unlockableSum.gtn(0) ?
<div
className={className}
style={style}
key='unlockable'
>
{t('unlockable {{unlockableSum}}',{
replace: {
unlockableSum: formatBalance(unlockableSum)
}
})}
<TxButton
accountId={controllerId.toString()}
className='withDrawUnbonded'
icon='lock'
size='small'
isPrimary
key='unlock'
params={[]}
tx='staking.withdrawUnbonded'
/>
</div>
<>
<span className={className + ' label-redeemable'}>
{t('redeemable')}
</span>
<span className={className + ' result-redeemable'}>
{formatBalance(unlockableSum)}<TxButton
accountId={controllerId.toString()}
className='withDrawUnbonded'
icon='lock'
size='small'
isPrimary
key='unlock'
params={[]}
tx='staking.withdrawUnbonded'
/>
</span>
</>
: null
);
}