Rework labelled layouts (#654)

* Rework labelled layouts

* Adjust storage output display

* Minor adjustments

* Linting cleanups

* Remove unused injected ia8n

* Minor adjustments

* Force Param re-render, fix Nonce params

* Text updates

* Expand Params key
This commit is contained in:
Jaco Greeff 2019-01-27 22:33:29 +01:00 committed by GitHub
parent f52761afa2
commit f547f8f0b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 337 additions and 555 deletions

View File

@ -24,7 +24,7 @@ export default class AccountSelector extends React.PureComponent<Props, State> {
<section className='template--AccountSelector template--2-columns'>
<InputAddress
className='template--column'
label='my default account to transact from'
label='my default account'
onChange={this.onChange}
type='account'
/>
@ -33,10 +33,10 @@ export default class AccountSelector extends React.PureComponent<Props, State> {
<AccountIndex value={accountId} />
</Bubble>
<Bubble color='yellow' icon='adjust' label='balance'>
<Balance value={accountId} />
<Balance params={[accountId]} />
</Bubble>
<Bubble color='yellow' icon='target' label='transactions'>
<Nonce value={accountId} />
<Nonce params={[accountId]} />
</Bubble>
</div>
</section>

View File

@ -7,7 +7,8 @@
.template--column {
box-sizing: border-box;
flex: 1 1;
flex: 1;
min-width: 0;
}
}

View File

@ -8,7 +8,7 @@ import { Generator$Matches, Generator$Result } from '../vanitygen/types';
import './index.css';
import React from 'react';
import { Button, Dropdown, Input, Static } from '@polkadot/ui-app/index';
import { Button, Dropdown, Input } from '@polkadot/ui-app/index';
import generator from '../vanitygen';
import matchRegex from '../vanitygen/regex';
@ -118,23 +118,18 @@ class VanityApp extends React.PureComponent<Props, State> {
className='medium'
isDisabled={isRunning}
isError={!isMatchValid}
label={t('generate address containing (? wildcard)')}
label={t('generate address with ? as a wildcard')}
onChange={this.onChangeMatch}
value={match}
/>
<Dropdown
className='small'
className='medium'
isDisabled={isRunning}
label={t('case sensitive match')}
label={t('perform a case sensitive search/match')}
options={BOOL_OPTIONS}
onChange={this.onChangeCase}
value={withCase}
/>
<Static
className='small'
label={t('exact offset')}
value={t('No')}
/>
</div>
);
}

View File

@ -5,7 +5,7 @@
import { I18nProps } from '@polkadot/ui-app/types';
import React from 'react';
import { Button, Input, Labelled } from '@polkadot/ui-app/index';
import { Button, Input } from '@polkadot/ui-app/index';
import { isHex } from '@polkadot/util';
import translate from './translate';
@ -31,21 +31,20 @@ class Query extends React.PureComponent<Props, State> {
<header>
<div className='ui--row'>
<div className='small' />
<div className='storage--Query-actionrow medium'>
<div className='storage--actionrow medium'>
<Input
className='storage--Query-actionrow-hash'
className='storage--actionrow-value'
isError={!isValid && hash.length !== 0}
placeholder={t('block hash to query')}
onChange={this.setHash}
withLabel={false}
/>
<Button
icon='play'
isDisabled={!isValid}
isPrimary
onClick={this.onQuery}
/>
<Labelled className='storage--Query-actionrow-button'>
<Button
icon='play'
isDisabled={!isValid}
isPrimary
onClick={this.onQuery}
/>
</Labelled>
</div>
</div>
</header>

View File

@ -23,7 +23,7 @@ class Summary extends React.PureComponent<Props> {
style={style}
>
<section>
<CardSummary label={t('target time')}>
<CardSummary label={t('target')}>
<TimePeriod />
</CardSummary>
<CardSummary label={t('last block')}>

View File

@ -1,96 +0,0 @@
// Copyright 2017-2019 @polkadot/app-extrinsics 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 { KeyringOption$Type } from '@polkadot/ui-keyring/options/types';
import { I18nProps } from '@polkadot/ui-app/types';
import React from 'react';
import { InputAddress, Labelled } from '@polkadot/ui-app/index';
import { Balance } from '@polkadot/ui-reactive/index';
import translate from './translate';
type Props = I18nProps & {
defaultValue?: string,
isDisabled?: boolean,
isError?: boolean,
isInput?: boolean,
label: string,
onChange?: (accountId: string) => void,
type?: KeyringOption$Type,
withLabel?: boolean
};
type State = {
accountId?: string
};
class Account extends React.PureComponent<Props, State> {
state: State;
constructor (props: Props) {
super(props);
this.state = {
accountId: props.defaultValue
};
}
render () {
const { defaultValue, isDisabled, isError, isInput, label, type, withLabel } = this.props;
return (
<div className='extrinsics--Account ui--row'>
<div className='large'>
<InputAddress
defaultValue={defaultValue}
isDisabled={isDisabled}
isError={isError}
isInput={isInput}
label={label}
onChange={this.onChange}
placeholder='0x...'
type={type}
withLabel={withLabel}
/>
</div>
{this.renderBalance()}
</div>
);
}
private renderBalance (): React.ReactNode {
const { t, withLabel } = this.props;
const { accountId } = this.state;
if (!accountId) {
return null;
}
return (
<Labelled
className='small'
label={t('with an available balance of')}
withLabel={withLabel}
>
<Balance
className='ui disabled dropdown selection'
params={accountId}
/>
</Labelled>
);
}
private onChange = (accountId: string): void => {
const { onChange } = this.props;
if (accountId) {
this.setState({ accountId }, () => {
onChange && onChange(accountId);
});
}
}
}
export default translate(Account);

View File

@ -23,8 +23,7 @@ type Props = BareProps & ApiProps & {
isDisabled?: boolean,
isError?: boolean,
isPrivate?: boolean,
labelMethod?: string,
labelSection?: string,
label?: React.ReactNode,
onChange: (method?: Method) => void,
withLabel?: boolean
};
@ -49,8 +48,8 @@ class ExtrinsicDisplay extends React.PureComponent<Props, State> {
}
render () {
const { defaultValue, isDisabled, isError, isPrivate, labelMethod, labelSection, withLabel } = this.props;
const { params } = this.state;
const { defaultValue, isDisabled, isError, isPrivate, label, withLabel } = this.props;
const { methodfn: { method, section }, params } = this.state;
return (
<div className='extrinsics--Extrinsic'>
@ -59,12 +58,12 @@ class ExtrinsicDisplay extends React.PureComponent<Props, State> {
isDisabled={isDisabled}
isError={isError}
isPrivate={isPrivate}
labelMethod={labelMethod}
labelSection={labelSection}
label={label}
onChange={this.onChangeMethod}
withLabel={withLabel}
/>
<Params
key={`${section}.${method}:params` /* force re-render on change */}
onChange={this.onChangeValues}
overrides={paramComponents}
params={params}
@ -79,10 +78,11 @@ class ExtrinsicDisplay extends React.PureComponent<Props, State> {
const { methodfn, params, values } = this.state;
const isValid = values.reduce((isValid, value) =>
isValid &&
!isUndefined(value) &&
!isUndefined(value.value) &&
value.isValid, params.length === values.length);
isValid &&
!isUndefined(value) &&
!isUndefined(value.value) &&
value.isValid, params.length === values.length
);
let method;

View File

@ -1,41 +0,0 @@
// Copyright 2017-2019 @polkadot/app-extrinsics 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 BN from 'bn.js';
import { BareProps } from '@polkadot/ui-app/types';
import React from 'react';
import { Labelled } from '@polkadot/ui-app/index';
import RxNonce from '@polkadot/ui-reactive/Nonce';
type Props = BareProps & {
callOnResult: (value: BN) => void,
label: string,
value?: string
};
export default class Nonce extends React.PureComponent<Props> {
render () {
const { label, callOnResult, value } = this.props;
if (!value) {
return null;
}
return (
<div className='ui--row'>
<Labelled
className='small'
label={label}
>
<RxNonce
className='ui disabled dropdown selection'
callOnResult={callOnResult}
params={value}
/>
</Labelled>
</div>
);
}
}

View File

@ -1,50 +0,0 @@
// Copyright 2017-2019 @polkadot/app-extrinsics 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 { Props } from '@polkadot/ui-params/types';
import React from 'react';
import keyring from '@polkadot/ui-keyring';
import BaseAccount from '../Account';
export default class Account extends React.PureComponent<Props> {
render () {
const { className, defaultValue: { value }, isDisabled, isError, label, style, withLabel } = this.props;
const defaultValue = (value as string);
return (
<BaseAccount
className={className}
defaultValue={defaultValue}
isDisabled={isDisabled}
isError={isError}
isInput
label={label}
onChange={this.onChange}
style={style}
withLabel={withLabel}
/>
);
}
onChange = (value: string): void => {
const { onChange } = this.props;
let isValid = false;
try {
keyring.decodeAddress(value);
isValid = true;
} catch (err) {
console.error(err);
}
onChange && onChange({
isValid,
value
});
}
}

View File

@ -33,12 +33,7 @@ class ExtrinsicDisplay extends React.PureComponent<Props> {
isDisabled={isDisabled}
isError={isError}
isPrivate={isPrivate}
labelMethod={t('{{label}} (extrinsic)', {
replace: {
label
}
})}
labelSection={t('{{label}} (section)', {
label={t('{{label}} (extrinsic)', {
replace: {
label
}

View File

@ -4,12 +4,10 @@
import { ComponentMap } from '@polkadot/ui-params/types';
import Account from './Account';
import Call from './Call';
import Proposal from './Proposal';
const components: ComponentMap = {
'AccountId': Account,
'Call': Call,
'Proposal': Proposal
};

View File

@ -4,23 +4,19 @@
import BN from 'bn.js';
import { I18nProps } from '@polkadot/ui-app/types';
import { QueueTx$ExtrinsicAdd, ActionStatus } from '@polkadot/ui-app/Status/types';
import { QueueTx$ExtrinsicAdd } from '@polkadot/ui-app/Status/types';
import { ApiProps } from '@polkadot/ui-api/types';
import React from 'react';
import { Method } from '@polkadot/types';
import { Button } from '@polkadot/ui-app/index';
import { Button, InputAddress, Labelled } from '@polkadot/ui-app/index';
import { withApi, withMulti } from '@polkadot/ui-api/index';
import { Balance, Nonce } from '@polkadot/ui-reactive/index';
import Account from './Account';
import ExtrinsicDisplay from './Extrinsic';
import Nonce from './Nonce';
import Extrinsic from './Extrinsic';
import translate from './translate';
const MAX_TRANSACTION_SIZE = 10 * 24 * 24;
type Props = ApiProps & I18nProps & {
onStatusChange: (status: ActionStatus) => void,
queueExtrinsic: QueueTx$ExtrinsicAdd
};
@ -49,22 +45,37 @@ class Selection extends React.PureComponent<Props, State> {
return (
<div className='extrinsics--Selection'>
<Account
isInput={false}
<InputAddress
label={t('using the selected account')}
onChange={this.onChangeSender}
type='account'
/>
<ExtrinsicDisplay
<div className='ui--row'>
<Labelled
className='medium'
label={t('with an account balance')}
>
<Balance
className='ui disabled dropdown selection'
params={accountId}
/>
</Labelled>
<Labelled
className='medium'
label={t('with a transaction nonce')}
>
<Nonce
className='ui disabled dropdown selection'
callOnResult={this.onChangeNonce}
params={accountId}
/>
</Labelled>
</div>
<Extrinsic
defaultValue={defaultExtrinsic}
labelMethod={t('submit the following extrinsic')}
label={t('submit the following extrinsic')}
onChange={this.onChangeExtrinsic}
/>
<Nonce
label={t('with an index')}
callOnResult={this.onChangeNonce}
value={accountId}
/>
<Button.Group>
<Button
isDisabled={!isValid}
@ -116,7 +127,7 @@ class Selection extends React.PureComponent<Props, State> {
}
private onQueue (isUnsigned: boolean): void {
const { api, queueExtrinsic, onStatusChange } = this.props;
const { api, queueExtrinsic } = this.props;
const { method, isValid, accountId } = this.state;
if (!isValid || !method) {
@ -126,20 +137,11 @@ class Selection extends React.PureComponent<Props, State> {
const fn = Method.findFunction(method.callIndex);
const extrinsic = api.tx[fn.section][fn.method](...method.args);
if (extrinsic.toU8a().length > MAX_TRANSACTION_SIZE) {
onStatusChange({
action: fn.section + '.' + fn.method,
status: 'error',
message: 'Warning: This transaction will likely be rejected by the network as it is greater \
than the maximum size of ' + MAX_TRANSACTION_SIZE / (24 * 24) + 'MB'
});
}
queueExtrinsic({
accountId: isUnsigned
? undefined
: accountId,
extrinsic: extrinsic,
extrinsic,
isUnsigned
});
}

View File

@ -22,8 +22,7 @@ type Props = AppProps & I18nProps & {
class ExtrinsicsApp extends React.PureComponent<Props> {
render () {
const { accountAll, onStatusChange, t } = this.props;
const { accountAll, t } = this.props;
if (!accountAll || !Object.keys(accountAll).length) {
return (
@ -40,7 +39,7 @@ class ExtrinsicsApp extends React.PureComponent<Props> {
<main className='extrinsics--App'>
<QueueConsumer>
{({ queueExtrinsic }: QueueProps) => (
<Selection onStatusChange={onStatusChange} queueExtrinsic={queueExtrinsic} />
<Selection queueExtrinsic={queueExtrinsic} />
)}
</QueueConsumer>
</main>

View File

@ -110,23 +110,21 @@ class Query extends React.PureComponent<Props, State> {
className='storage--actionrow-value'
label={
<div className='ui--Param-text'>
<div className='ui--Param-text name'>{this.keyToName(key)}</div>
{this.renderInputs()}
<div className='ui--Param-text'>{
{this.keyToName(key)}: {
isU8a(key)
? 'Data'
: key.meta.type.toString()
}</div>
}
</div>
}
>
<Component />
</Labelled>
<Labelled className='storage--actionrow-buttons'>
<div className='storage--actionrow-buttons'>
<div className='container'>
{this.renderButtons()}
</div>
</Labelled>
</div>
</div>
);
}
@ -163,24 +161,6 @@ class Query extends React.PureComponent<Props, State> {
return buttons;
}
private renderInputs () {
const { inputs } = this.state;
if (inputs.length === 0) {
return (
<div className='ui--Param-text name'>:</div>
);
}
return (
<>
<div className='ui--Param-text name'>(</div>
{inputs}
<div className='ui--Param-text name'>):</div>
</>
);
}
private keyToName (key: Uint8Array | StorageFunction): string {
if (isU8a(key)) {
const u8a = Compact.stripLengthPrefix(key);

View File

@ -10,7 +10,7 @@ import { ApiProps } from '@polkadot/ui-api/types';
import { PartialModuleQuery } from '../types';
import React from 'react';
import { Button, InputStorage, Labelled } from '@polkadot/ui-app/index';
import { Button, InputStorage } from '@polkadot/ui-app/index';
import Params from '@polkadot/ui-params/index';
import { withApi, withMulti } from '@polkadot/ui-api/index';
import { isUndefined } from '@polkadot/util';
@ -48,30 +48,30 @@ class Modules extends React.PureComponent<Props, State> {
render () {
const { t } = this.props;
const { isValid, key, params } = this.state;
const { isValid, key: { method, section }, params } = this.state;
return (
<section className='storage--actionrow'>
<div className='storage--actionrow-value'>
<InputStorage
defaultValue={this.defaultValue}
labelSection={t('query state section')}
label={t('selected state query')}
onChange={this.onChangeKey}
/>
<Params
key={`${key.section}.${key.method}`}
key={`${section}.${method}:params` /* force re-render on change */}
onChange={this.onChangeParams}
params={params}
/>
</div>
<Labelled className='storage--actionrow-buttons'>
<div className='storage--actionrow-buttons'>
<Button
icon='plus'
isDisabled={!isValid}
isPrimary
onClick={this.onAdd}
/>
</Labelled>
</div>
</section>
);
}

View File

@ -6,7 +6,7 @@ import { I18nProps } from '@polkadot/ui-app/types';
import { PartialRawQuery } from '../types';
import React from 'react';
import { Button, Input, Labelled } from '@polkadot/ui-app/index';
import { Button, Input } from '@polkadot/ui-app/index';
import translate from '../translate';
import { u8aToU8a } from '@polkadot/util';
@ -46,14 +46,14 @@ class Raw extends React.PureComponent<Props, State> {
onChange={this.onChangeKey}
/>
</div>
<Labelled className='storage--actionrow-buttons'>
<div className='storage--actionrow-buttons'>
<Button
icon='plus'
isDisabled={!isValid}
isPrimary
onClick={this.onAdd}
/>
</Labelled>
</div>
</section>
);
}

View File

@ -27,6 +27,10 @@
.storage--actionrow {
display: flex;
.button {
margin-bottom: 0.5rem;
}
}
.storage--actionrow-value {

View File

@ -51,10 +51,12 @@ class Selection extends React.PureComponent<Props, State> {
<section className='rpc--Selection'>
<InputRpc
defaultValue={defaultMethod}
label={t('call the selected endpoint')}
onChange={this.onChangeMethod}
/>
{this.renderAccount()}
<Params
key={`${rpc.section}.${rpc.method}:params` /* force re-render on change */}
onChange={this.onChangeValues}
params={params}
/>

View File

@ -19,16 +19,12 @@ export default class RpcApp extends React.PureComponent<Props> {
render () {
return (
<QueueConsumer>
{({ txqueue, queueRpc }: QueueProps) => [
<Selection
key='add'
queueRpc={queueRpc}
/>,
<Results
key='results'
queue={txqueue}
/>
]}
{({ txqueue, queueRpc }: QueueProps) => (
<>
<Selection queueRpc={queueRpc} />
<Results queue={txqueue} />
</>
)}
</QueueConsumer>
);
}

View File

@ -13,7 +13,7 @@ import { AddressSummary, InputAddress, InputBalance } from '@polkadot/ui-app/ind
import { withApi, withMulti } from '@polkadot/ui-api/index';
import { QueueConsumer } from '@polkadot/ui-app/Status/Context';
import keyring from '@polkadot/ui-keyring';
import FeeDisplay from '@polkadot/ui-signer/Fees';
import Checks from '@polkadot/ui-signer/Checks';
import Submit from './Submit';
import translate from './translate';
@ -51,33 +51,26 @@ class Transfer extends React.PureComponent<Props, State> {
return (
<div className='transfer--Transfer'>
<div className='ui--row'>
<div className='medium'>
<InputAddress
label={t('transfer from my account')}
onChange={this.onChangeFrom}
type='account'
/>
</div>
<div className='medium'>
<InputAddress
label={t('to the recipient address')}
onChange={this.onChangeTo}
type='all'
/>
</div>
</div>
<div className='transfer--Transfer-info'>
{this.renderAddress(accountId)}
<div className='transfer--Transfer-data'>
<InputAddress
label={t('from my source account')}
onChange={this.onChangeFrom}
type='account'
/>
<InputAddress
label={t('with a recipient of')}
onChange={this.onChangeTo}
type='all'
/>
<InputBalance
autoFocus
isError={!hasAvailable}
label={t('send a value of')}
label={t('transfer a value of')}
onChange={this.onChangeAmount}
/>
<FeeDisplay
className='medium'
<Checks
accountId={accountId}
extrinsic={extrinsic}
onChange={this.onChangeFees}

View File

@ -4,7 +4,6 @@
.transfer--Transfer-address {
flex: 0 1;
padding: 2em 0;
.ui--AddressSummary {
text-align: center;
@ -17,6 +16,7 @@
.transfer--Transfer-data {
flex: 1 1;
min-width: 0;
}
.transfer--Transfer-info {

View File

@ -57,7 +57,10 @@ export default class CardSummary extends React.PureComponent<Props> {
className={classes('ui--CardSummary', className)}
style={style}
>
<Labelled label={label}>
<Labelled
isSmall
label={label}
>
<div className='ui--CardSummary-large'>
{children}{
progress && !progress.hideValue && (

View File

@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { MethodFunction } from '@polkadot/types/Method';
import { I18nProps } from '../types';
import { BareProps } from '../types';
import { DropdownOptions } from '../util/types';
import React from 'react';
@ -11,21 +11,18 @@ import ApiPromise from '@polkadot/api/promise';
import Dropdown from '../Dropdown';
import classes from '../util/classes';
import translate from '../translate';
type Props = I18nProps & {
type Props = BareProps & {
api: ApiPromise,
isError?: boolean,
label?: string,
onChange: (value: MethodFunction) => void,
options: DropdownOptions,
value: MethodFunction,
withLabel?: boolean
value: MethodFunction
};
class SelectMethod extends React.PureComponent<Props> {
export default class SelectMethod extends React.PureComponent<Props> {
render () {
const { api, className, isError, label = '', onChange, options, style, t, value, withLabel } = this.props;
const { api, className, isError, onChange, options, style, value } = this.props;
if (!options.length) {
return null;
@ -35,19 +32,16 @@ class SelectMethod extends React.PureComponent<Props> {
api.tx[value.section][method];
return (
<Dropdown
className={classes('ui--DropdownLinked-Items', className)}
isError={isError}
label={label || t('with the extrinsic')}
onChange={onChange}
options={options}
style={style}
transform={transform}
value={value.method}
withLabel={withLabel}
/>
<Dropdown
className={classes('ui--DropdownLinked-Items', className)}
isError={isError}
onChange={onChange}
options={options}
style={style}
transform={transform}
value={value.method}
withLabel={false}
/>
);
}
}
export default translate(SelectMethod);

View File

@ -3,43 +3,37 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { MethodFunction } from '@polkadot/types/Method';
import { I18nProps } from '../types';
import { BareProps } from '../types';
import { DropdownOptions } from '../util/types';
import React from 'react';
import Dropdown from '../Dropdown';
import classes from '../util/classes';
import translate from '../translate';
type Props = I18nProps & {
type Props = BareProps & {
defaultValue?: string,
isError?: boolean,
label?: string,
onChange: (value: string) => void,
options: DropdownOptions,
value: MethodFunction,
withLabel?: boolean
value: MethodFunction
};
class SelectSection extends React.PureComponent<Props> {
export default class SelectSection extends React.PureComponent<Props> {
render () {
const { className, defaultValue, isError, label = '', onChange, options, style, t, value, withLabel } = this.props;
const { className, defaultValue, isError, onChange, options, style, value } = this.props;
return (
<Dropdown
className={classes('ui--DropdownLinked-Sections', className)}
defaultValue={defaultValue}
isError={isError}
label={label || t('from extrinsic section')}
onChange={onChange}
options={options}
style={style}
value={value.section}
withLabel={withLabel}
withLabel={false}
/>
);
}
}
export default translate(SelectSection);

View File

@ -12,7 +12,7 @@ import './InputExtrinsic.css';
import React from 'react';
import { withApi, withMulti } from '@polkadot/ui-api/index';
import classes from '../util/classes';
import Labelled from '../Labelled';
import translate from '../translate';
import SelectMethod from './SelectMethod';
import SelectSection from './SelectSection';
@ -24,8 +24,7 @@ type Props = ApiProps & I18nProps & {
isDisabled?: boolean,
isError?: boolean,
isPrivate?: boolean,
labelMethod?: string,
labelSection?: string,
label: React.ReactNode,
onChange: (value: MethodFunction) => void,
withLabel?: boolean
};
@ -55,31 +54,34 @@ class InputExtrinsic extends React.PureComponent<Props, State> {
}
render () {
const { api, className, labelMethod, labelSection, style, withLabel } = this.props;
const { api, className, label, style, withLabel } = this.props;
const { optionsMethod, optionsSection, value } = this.state;
return (
<div
className={classes('ui--DropdownLinked', 'ui--row', className)}
className={className}
style={style}
>
<SelectSection
className='small'
label={labelSection}
onChange={this.onSectionChange}
options={optionsSection}
value={value}
<Labelled
label={label}
withLabel={withLabel}
/>
<SelectMethod
api={api}
className='large'
label={labelMethod}
onChange={this.onKeyChange}
options={optionsMethod}
value={value}
withLabel={withLabel}
/>
>
<div className=' ui--DropdownLinked ui--row'>
<SelectSection
className='small'
onChange={this.onSectionChange}
options={optionsSection}
value={value}
/>
<SelectMethod
api={api}
className='large'
onChange={this.onKeyChange}
options={optionsMethod}
value={value}
/>
</div>
</Labelled>
</div>
);
}

View File

@ -4,7 +4,7 @@
import { RpcMethod } from '@polkadot/jsonrpc/types';
import { DropdownOptions } from '../util/types';
import { I18nProps } from '../types';
import { BareProps } from '../types';
import React from 'react';
@ -12,20 +12,17 @@ import map from '@polkadot/jsonrpc';
import Dropdown from '../Dropdown';
import classes from '../util/classes';
import translate from '../translate';
type Props = I18nProps & {
type Props = BareProps & {
isError?: boolean,
label?: string,
onChange: (value: RpcMethod) => void,
options: DropdownOptions,
value: RpcMethod,
withLabel?: boolean
value: RpcMethod
};
class SelectMethod extends React.PureComponent<Props> {
export default class SelectMethod extends React.PureComponent<Props> {
render () {
const { className, isError, label = '', onChange, options, style, t, value, withLabel } = this.props;
const { className, isError, onChange, options, style, value } = this.props;
if (!options.length) {
return null;
@ -38,16 +35,13 @@ class SelectMethod extends React.PureComponent<Props> {
<Dropdown
className={classes('ui--DropdownLinked-Items', className)}
isError={isError}
label={label || t('with method name')}
onChange={onChange}
options={options}
style={style}
transform={transform}
value={value.method}
withLabel={withLabel}
withLabel={false}
/>
);
}
}
export default translate(SelectMethod);

View File

@ -4,42 +4,36 @@
import { RpcMethod } from '@polkadot/jsonrpc/types';
import { DropdownOptions } from '../util/types';
import { I18nProps } from '../types';
import { BareProps } from '../types';
import React from 'react';
import Dropdown from '../Dropdown';
import classes from '../util/classes';
import translate from '../translate';
type Props = I18nProps & {
type Props = BareProps & {
defaultValue?: string,
isError?: boolean,
label?: string,
onChange: (value: string) => void,
options: DropdownOptions,
value: RpcMethod,
withLabel?: boolean
value: RpcMethod
};
class SelectSection extends React.PureComponent<Props> {
export default class SelectSection extends React.PureComponent<Props> {
render () {
const { className, defaultValue, isError, label, onChange, options, style, t, value, withLabel } = this.props;
const { className, defaultValue, isError, onChange, options, style, value } = this.props;
return (
<Dropdown
className={classes('ui--DropdownLinked-Sections', className)}
defaultValue={defaultValue}
isError={isError}
label={label || t('rpc area')}
onChange={onChange}
options={options}
style={style}
value={value.section}
withLabel={withLabel}
withLabel={false}
/>
);
}
}
export default translate(SelectSection);

View File

@ -13,7 +13,7 @@ import '../InputExtrinsic/InputExtrinsic.css';
import React from 'react';
import map from '@polkadot/jsonrpc';
import classes from '../util/classes';
import Labelled from '../Labelled';
import translate from '../translate';
import SelectMethod from './SelectMethod';
import SelectSection from './SelectSection';
@ -23,8 +23,7 @@ import sectionOptions from './options/section';
type Props = I18nProps & {
defaultValue: RpcMethod,
isError?: boolean,
labelMethod?: string,
labelSection?: string,
label: React.ReactNode,
onChange?: (value: RpcMethod) => void,
withLabel?: boolean
};
@ -51,30 +50,33 @@ class InputRpc extends React.PureComponent<Props, State> {
}
render () {
const { className, labelMethod, labelSection, style, withLabel } = this.props;
const { className, label, style, withLabel } = this.props;
const { optionsMethod, optionsSection, value } = this.state;
return (
<div
className={classes('ui--DropdownLinked', 'ui--row', className)}
className={className}
style={style}
>
<SelectSection
className='small'
label={labelSection}
onChange={this.onSectionChange}
options={optionsSection}
value={value}
<Labelled
label={label}
withLabel={withLabel}
/>
<SelectMethod
className='large'
label={labelMethod}
onChange={this.onMethodChange}
options={optionsMethod}
value={value}
withLabel={withLabel}
/>
>
<div className=' ui--DropdownLinked ui--row'>
<SelectSection
className='small'
onChange={this.onSectionChange}
options={optionsSection}
value={value}
/>
<SelectMethod
className='large'
onChange={this.onMethodChange}
options={optionsMethod}
value={value}
/>
</div>
</Labelled>
</div>
);
}

View File

@ -4,28 +4,25 @@
import { ApiProps } from '@polkadot/ui-api/types';
import { DropdownOptions } from '../util/types';
import { I18nProps } from '../types';
import { BareProps } from '../types';
import React from 'react';
import { StorageFunction } from '@polkadot/types/StorageKey';
import { withApi, withMulti } from '@polkadot/ui-api/index';
import { withApi } from '@polkadot/ui-api/index';
import Dropdown from '../Dropdown';
import classes from '../util/classes';
import translate from '../translate';
type Props = ApiProps & I18nProps & {
type Props = ApiProps & BareProps & {
isError?: boolean,
label?: string,
onChange: (value: StorageFunction) => void,
options: DropdownOptions,
value: StorageFunction,
withLabel?: boolean
value: StorageFunction
};
class SelectKey extends React.PureComponent<Props> {
render () {
const { api, className, isError, label = '', onChange, options, style, t, value, withLabel } = this.props;
const { api, className, isError, onChange, options, style, value } = this.props;
if (!options.length) {
return null;
@ -38,20 +35,15 @@ class SelectKey extends React.PureComponent<Props> {
<Dropdown
className={classes('ui--DropdownLinked-Items', className)}
isError={isError}
label={label || t('with state key')}
onChange={onChange}
options={options}
style={style}
transform={transform}
value={value.method}
withLabel={withLabel}
withLabel={false}
/>
);
}
}
export default withMulti(
SelectKey,
translate,
withApi
);
export default withApi(SelectKey);

View File

@ -4,42 +4,36 @@
import { StorageFunction } from '@polkadot/types/StorageKey';
import { DropdownOptions } from '../util/types';
import { I18nProps } from '../types';
import { BareProps } from '../types';
import React from 'react';
import Dropdown from '../Dropdown';
import classes from '../util/classes';
import translate from '../translate';
type Props = I18nProps & {
type Props = BareProps & {
defaultValue?: StorageFunction,
isError?: boolean,
label?: string,
onChange: (value: string) => void,
options: DropdownOptions,
value: StorageFunction,
withLabel?: boolean
value: StorageFunction
};
class SelectSection extends React.PureComponent<Props> {
export default class SelectSection extends React.PureComponent<Props> {
render () {
const { className, defaultValue, isError, label, onChange, options, style, t, value: { section }, withLabel } = this.props;
const { className, defaultValue, isError, onChange, options, style, value: { section } } = this.props;
return (
<Dropdown
className={classes('ui--DropdownLinked-Sections', className)}
defaultValue={defaultValue}
isError={isError}
label={label || t('state section')}
onChange={onChange}
options={options}
style={style}
value={section}
withLabel={withLabel}
withLabel={false}
/>
);
}
}
export default translate(SelectSection);

View File

@ -14,7 +14,7 @@ import '../InputExtrinsic/InputExtrinsic.css';
import React from 'react';
import { withApi, withMulti } from '@polkadot/ui-api/index';
import classes from '../util/classes';
import Labelled from '../Labelled';
import translate from '../translate';
import SelectKey from './SelectKey';
import SelectSection from './SelectSection';
@ -24,8 +24,7 @@ import sectionOptions from './options/section';
type Props = ApiProps & I18nProps & {
defaultValue: StorageFunction,
isError?: boolean,
labelMethod?: string,
labelSection?: string,
label: React.ReactNode,
onChange?: (value: StorageFunction) => void,
withLabel?: boolean
};
@ -52,30 +51,33 @@ class InputStorage extends React.PureComponent<Props, State> {
}
render () {
const { className, labelMethod, labelSection, style, withLabel } = this.props;
const { className, label, style, withLabel } = this.props;
const { optionsMethod, optionsSection, value } = this.state;
return (
<div
className={classes('ui--DropdownLinked', 'ui--row', className)}
className={className}
style={style}
>
<SelectSection
className='small'
label={labelSection}
onChange={this.onSectionChange}
options={optionsSection}
value={value}
<Labelled
label={label}
withLabel={withLabel}
/>
<SelectKey
className='large'
label={labelMethod}
onChange={this.onKeyChange}
options={optionsMethod}
value={value}
withLabel={withLabel}
/>
>
<div className=' ui--DropdownLinked ui--row'>
<SelectSection
className='small'
onChange={this.onSectionChange}
options={optionsSection}
value={value}
/>
<SelectKey
className='large'
onChange={this.onKeyChange}
options={optionsMethod}
value={value}
/>
</div>
</Labelled>
</div>
);
}

View File

@ -5,14 +5,14 @@
import { BareProps } from './types';
import React from 'react';
import Label from 'semantic-ui-react/dist/commonjs/elements/Label/Label';
import classes from './util/classes';
type Props = BareProps & {
isHidden?: boolean,
label?: any,
children: any, // node?
isSmall?: boolean,
label?: React.ReactNode,
children: React.ReactNode,
withLabel?: boolean
};
@ -22,7 +22,7 @@ const defaultLabel: any = (// node?
export default class Labelled extends React.PureComponent<Props> {
render () {
const { className, children, isHidden = false, label = defaultLabel, style, withLabel = true } = this.props;
const { className, children, isSmall, isHidden, label = defaultLabel, style, withLabel = true } = this.props;
if (isHidden) {
return null;
@ -30,15 +30,17 @@ export default class Labelled extends React.PureComponent<Props> {
return (
<div
className={classes('ui--Labelled', className)}
className={classes('ui--Labelled', isSmall ? 'label-small' : '', className)}
style={style}
>
{
withLabel
? <Label>{label}</Label>
? <div className='ui--label'>{label}</div>
: null
}
{children}
<div className='ui--Labelled-content'>
{children}
</div>
</div>
);
}

View File

@ -29,10 +29,10 @@ export { default as Icon } from './Icon';
export { default as IdentityIcon } from './IdentityIcon';
export { default as Input } from './Input';
export { default as InputAddress } from './InputAddress';
export { default as InputBalance } from './InputBalance';
export { default as InputError } from './InputError';
export { default as InputExtrinsic } from './InputExtrinsic';
export { default as InputFile } from './InputFile';
export { default as InputBalance } from './InputBalance';
export { default as InputNumber } from './InputNumber';
export { default as InputRpc } from './InputRpc';
export { default as InputStorage } from './InputStorage';

View File

@ -5,13 +5,13 @@
@import './partials/_variables.css';
.ui--output {
background: #f9f9f9;
background: #fefefe;
border-radius: 4px;
border: 1px solid #f5f5f5;
border: 1px dashed #eee;
box-sizing: border-box;
line-height: 1em;
line-height: 1rem;
margin-bottom: 0.5em;
padding: 0.75em 1em;
padding: .75rem 1rem;
position: relative;
word-wrap: break-word;
}
@ -110,7 +110,7 @@ header .ui--Button-Group {
.ui--AddressSummary.invalid {
filter: grayscale(100);
opacity: 0.45;
opacity: 0.5;
}
.ui--AddressSummary-icon {
@ -120,7 +120,7 @@ header .ui--Button-Group {
.ui--Balance,
.ui--AddressSummary-balance,
.ui--AddressSummary-nonce {
opacity: 0.45;
opacity: 0.5;
}
.ui--AddressSummary-balance {
@ -266,8 +266,42 @@ header .ui--Button-Group {
}
}
.ui--label {
box-sizing: border-box;
font-size: 1rem;
font-weight: normal;
margin-bottom: 0.5rem;
opacity: 0.75;
padding-right: 0.5rem;
}
.ui--Labelled {
align-items: center;
display: flex;
flex: 1 1;
text-align: left;
&.label-small {
display: block;
> .ui--label {
margin-bottom: 0;
min-width: 0;
padding-right: 0;
}
}
> .ui--Labelled-content {
box-sizing: border-box;
flex: 1 1;
min-width: 0;
}
> .ui--label {
flex: 0 0 15rem;
min-width: 15rem;
text-align: right;
}
}
.ui--Static {

View File

@ -46,6 +46,7 @@ article.ui--hoverable {
flex-direction: row;
justify-content: flex-start;
text-align: left;
min-width: 0;
}
.ui--grid > div,
@ -99,12 +100,3 @@ article.ui--hoverable {
.ui--row > div.thirty3 {
flex: 0 33.33%;
}
.ui--row > div.full,
.ui--row > div.large,
.ui--row > div.medium,
.ui--row > div.small,
.ui--row > div.sixty6,
.ui--row > div.thirty3 {
padding: 0 0.25rem;
}

View File

@ -23,7 +23,7 @@
.ui.dropdown {
&.disabled {
background: #fdfdfd;
background: #fefefe;
/* border-color: transparent; */
border-color: #eee;
border-style: dashed;
@ -57,7 +57,7 @@
opacity: 1;
input {
background: #fdfdfd;
background: #fefefe;
border-color: #eee;
/* border-color: transparent; */
border-style: dashed;
@ -93,7 +93,7 @@
}
.ui.modal {
background: #fdfdfd;
background: #fafafa;
> .actions,
> .content,

View File

@ -7,7 +7,7 @@ import { AccountId, AccountIndex, Address } from '@polkadot/types';
export default function toShortAddress (_address?: AccountId | AccountIndex | Address | string | null): string {
const address = (_address || '').toString();
return (address.length > 15)
? `${address.slice(0, 7)}…${address.slice(-7)}`
return (address.length > 13)
? `${address.slice(0, 6)}…${address.slice(-6)}`
: address;
}

View File

@ -21,7 +21,7 @@ export default class Account extends React.PureComponent<Props> {
style={style}
>
<InputAddress
className={isDisabled ? 'full' : 'large'}
className='full'
defaultValue={defaultValue}
isDisabled={isDisabled}
isError={isError}

View File

@ -30,7 +30,7 @@ export default class Amount extends React.PureComponent<Props> {
style={style}
>
<Input
className={isDisabled ? 'full' : 'small'}
className={isDisabled ? 'full' : 'medium'}
defaultValue={defaultValue}
isDisabled={isDisabled}
isError={isError}

View File

@ -27,7 +27,7 @@ export default class BoolParam extends React.PureComponent<Props> {
style={style}
>
<Dropdown
className={isDisabled ? 'full' : 'small'}
className={isDisabled ? 'full' : 'medium'}
defaultValue={defaultValue}
isDisabled={isDisabled}
isError={isError}

View File

@ -28,7 +28,7 @@ export default class Vote extends React.PureComponent<Props> {
style={style}
>
<Dropdown
className={isDisabled ? 'full' : 'small'}
className={isDisabled ? 'full' : 'medium'}
defaultValue={defaultValue}
isDisabled={isDisabled}
isError={isError}

View File

@ -38,7 +38,7 @@ export default class VoteThresholdParam extends React.PureComponent<Props> {
style={style}
>
<Dropdown
className={isDisabled ? 'full' : 'small'}
className={isDisabled ? 'full' : 'medium'}
defaultValue={defaultValue}
isDisabled={isDisabled}
isError={isError}

View File

@ -2,13 +2,17 @@
/* This software may be modified and distributed under the terms
/* of the Apache-2.0 license. See the LICENSE file for details. */
.ui--Params {
border-left: 0.25rem solid #f2f2f2;
}
.ui--Param-Address {
font-family: monospace;
}
.ui--Params-Content {
box-sizing: border-box;
padding-left: 1.5rem;
padding: 0 0 0 1.75rem;
}
.ui--Param-text {

View File

@ -34,4 +34,4 @@ class BalanceDisplay extends React.PureComponent<Props> {
}
}
export default withCall('query.balances.freeBalance', { paramName: 'value' })(BalanceDisplay);
export default withCall('query.balances.freeBalance')(BalanceDisplay);

View File

@ -34,4 +34,4 @@ class Nonce extends React.PureComponent<Props> {
}
}
export default withCall('query.system.accountNonce', { paramName: 'value' })(Nonce);
export default withCall('query.system.accountNonce')(Nonce);

View File

@ -19,3 +19,6 @@ export const ZERO_FEES = {
existentialDeposit: new BN(0),
transferFee: new BN(0)
} as DerivedFees;
export const MAX_SIZE_MB = 10;
export const MAX_SIZE_BYTES = MAX_SIZE_MB * 1024 * 1024;

View File

@ -17,7 +17,7 @@ import { compactToU8a } from '@polkadot/util';
import translate from '../translate';
import Proposal from './Proposal';
import Transfer from './Transfer';
import { ZERO_BALANCE, ZERO_FEES } from './constants';
import { MAX_SIZE_BYTES, MAX_SIZE_MB, ZERO_BALANCE, ZERO_FEES } from './constants';
type State = ExtraFees & {
allFees: BN,
@ -27,7 +27,8 @@ type State = ExtraFees & {
extSection?: string,
hasAvailable: boolean,
isRemovable: boolean,
isReserved: boolean
isReserved: boolean,
overLimit: boolean
};
type Props = I18nProps & {
@ -45,21 +46,18 @@ const LENGTH_ERA = 1;
const SIGNATURE_SIZE = LENGTH_PUBLICKEY + LENGTH_SIGNATURE + LENGTH_ERA;
class FeeDisplay extends React.PureComponent<Props, State> {
constructor (props: Props) {
super(props);
this.state = {
allFees: new BN(0),
allTotal: new BN(0),
allWarn: false,
extraAmount: new BN(0),
extraFees: new BN(0),
extraWarn: false,
hasAvailable: false,
isRemovable: false,
isReserved: false
};
}
state: State = {
allFees: new BN(0),
allTotal: new BN(0),
allWarn: false,
extraAmount: new BN(0),
extraFees: new BN(0),
extraWarn: false,
hasAvailable: false,
isRemovable: false,
isReserved: false,
overLimit: false
};
static getDerivedStateFromProps ({ accountId, balances_votingBalance = ZERO_BALANCE, extrinsic, balances_fees = ZERO_FEES, system_accountNonce = new BN(0) }: Props, prevState: State): State | null {
if (!accountId || !extrinsic) {
@ -93,6 +91,7 @@ class FeeDisplay extends React.PureComponent<Props, State> {
const isRemovable = balances_votingBalance.votingBalance.sub(allTotal).lte(balances_fees.existentialDeposit);
const isReserved = balances_votingBalance.freeBalance.isZero() && balances_votingBalance.reservedBalance.gtn(0);
const allWarn = extraWarn;
const overLimit = txLength >= MAX_SIZE_BYTES;
return {
allFees,
@ -105,7 +104,8 @@ class FeeDisplay extends React.PureComponent<Props, State> {
extraWarn,
hasAvailable,
isRemovable,
isReserved
isReserved,
overLimit
};
}
@ -118,19 +118,19 @@ class FeeDisplay extends React.PureComponent<Props, State> {
render () {
const { accountId, className, t } = this.props;
const { allFees, allTotal, allWarn, hasAvailable, isRemovable, isReserved } = this.state;
const { allFees, allTotal, allWarn, hasAvailable, isRemovable, isReserved, overLimit } = this.state;
if (!accountId) {
return null;
}
const feeClass = hasAvailable
? (
const feeClass = !hasAvailable || overLimit
? 'error'
: (
allWarn
? 'warning'
: 'normal'
)
: 'error';
);
// display all the errors, warning and information messages (in that order)
return (
@ -143,6 +143,11 @@ class FeeDisplay extends React.PureComponent<Props, State> {
? undefined
: <div><Icon name='ban' />{t('The account does not have the required funds available for this transaction with the current provided values')}</div>
}
{
overLimit
? <div><Icon name='ban' />{t(`This transaction will be rejected by the node as it is greater than the maximum size of ${MAX_SIZE_MB}MB`)}></div>
: undefined
}
{this.renderTransfer()}
{this.renderProposal()}
{

View File

@ -9,7 +9,7 @@ import React from 'react';
import { Method } from '@polkadot/types';
import { Call, InputAddress, Modal } from '@polkadot/ui-app/index';
import Fees from './Fees';
import Checks from './Checks';
import translate from './translate';
type Props = I18nProps & {
@ -25,24 +25,21 @@ class Transaction extends React.PureComponent<Props> {
return null;
}
const { method, section } = Method.findFunction(extrinsic.callIndex);
const { meta, method, section } = Method.findFunction(extrinsic.callIndex);
return (
<>
<Modal.Header>
{section}.{method}
<div className='ui--label'>{meta.documentation.join(' ')}</div>
</Modal.Header>
<Modal.Content className='ui--signer-Signer-Content'>
<div className='ui--signer-Signer-Decoded'>
<div className='expanded'>
<div className='ui--signer-Signer-children'>
{this.renderAccount()}
{children}
</div>
<Call value={extrinsic} />
{this.renderFees()}
</div>
<Call value={extrinsic} />
<div className='ui--signer-Signer-children'>
{this.renderAccount()}
{children}
</div>
{this.renderChecks()}
</Modal.Content>
</>
);
@ -67,7 +64,7 @@ class Transaction extends React.PureComponent<Props> {
);
}
private renderFees () {
private renderChecks () {
const { value: { accountId, extrinsic, isUnsigned } } = this.props;
if (isUnsigned) {
@ -75,7 +72,7 @@ class Transaction extends React.PureComponent<Props> {
}
return (
<Fees
<Checks
accountId={accountId}
extrinsic={extrinsic}
/>

View File

@ -52,18 +52,15 @@ class Unlock extends React.PureComponent<Props, State> {
return (
<div className='ui--signer-Signer-Unlock'>
<div className='ui--row'>
<Password
autoFocus={autoFocus}
className='medium'
isError={isError}
label={label || t('unlocked using the password')}
onChange={onChange}
onKeyDown={onKeyDown}
tabIndex={tabIndex}
value={password}
/>
</div>
<Password
autoFocus={autoFocus}
isError={isError}
label={label || t('unlocked using password')}
onChange={onChange}
onKeyDown={onKeyDown}
tabIndex={tabIndex}
value={password}
/>
</div>
);
}