From f547f8f0b1a0ece6b8e6dc0a0c4d93e6ed3a4771 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sun, 27 Jan 2019 22:33:29 +0100 Subject: [PATCH] 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 --- packages/app-123code/src/AccountSelector.tsx | 6 +- packages/app-123code/src/index.css | 3 +- packages/app-accounts/src/Vanity/index.tsx | 13 +-- packages/app-explorer/src/Query.tsx | 21 ++-- packages/app-explorer/src/Summary.tsx | 2 +- packages/app-extrinsics/src/Account.tsx | 96 ------------------- packages/app-extrinsics/src/Extrinsic.tsx | 20 ++-- packages/app-extrinsics/src/Nonce.tsx | 41 -------- .../app-extrinsics/src/Params/Account.tsx | 50 ---------- .../app-extrinsics/src/Params/Extrinsic.tsx | 7 +- packages/app-extrinsics/src/Params/index.ts | 2 - packages/app-extrinsics/src/Selection.tsx | 58 +++++------ packages/app-extrinsics/src/index.tsx | 5 +- packages/app-storage/src/Query.tsx | 28 +----- .../app-storage/src/Selection/Modules.tsx | 12 +-- packages/app-storage/src/Selection/Raw.tsx | 6 +- packages/app-storage/src/index.css | 4 + packages/app-toolbox/src/Rpc/Selection.tsx | 2 + packages/app-toolbox/src/Rpc/index.tsx | 16 ++-- packages/app-transfer/src/Transfer.tsx | 33 +++---- packages/app-transfer/src/index.css | 2 +- packages/ui-app/src/CardSummary.tsx | 5 +- .../src/InputExtrinsic/SelectMethod.tsx | 36 +++---- .../src/InputExtrinsic/SelectSection.tsx | 18 ++-- packages/ui-app/src/InputExtrinsic/index.tsx | 44 +++++---- packages/ui-app/src/InputRpc/SelectMethod.tsx | 18 ++-- .../ui-app/src/InputRpc/SelectSection.tsx | 18 ++-- packages/ui-app/src/InputRpc/index.tsx | 42 ++++---- .../ui-app/src/InputStorage/SelectKey.tsx | 22 ++--- .../ui-app/src/InputStorage/SelectSection.tsx | 18 ++-- packages/ui-app/src/InputStorage/index.tsx | 42 ++++---- packages/ui-app/src/Labelled.tsx | 16 ++-- packages/ui-app/src/index.tsx | 2 +- packages/ui-app/src/styles/components.css | 46 +++++++-- packages/ui-app/src/styles/form.css | 10 +- packages/ui-app/src/styles/semantic.css | 6 +- packages/ui-app/src/util/toShortAddress.ts | 4 +- packages/ui-params/src/Param/Account.tsx | 2 +- packages/ui-params/src/Param/Amount.tsx | 2 +- packages/ui-params/src/Param/Bool.tsx | 2 +- packages/ui-params/src/Param/Vote.tsx | 2 +- .../ui-params/src/Param/VoteThreshold.tsx | 2 +- packages/ui-params/src/Params.css | 6 +- packages/ui-reactive/src/Balance.tsx | 2 +- packages/ui-reactive/src/Nonce.tsx | 2 +- .../src/{Fees => Checks}/Proposal.tsx | 0 .../src/{Fees => Checks}/Transfer.tsx | 0 .../src/{Fees => Checks}/constants.ts | 3 + .../ui-signer/src/{Fees => Checks}/index.tsx | 51 +++++----- .../ui-signer/src/{Fees => Checks}/types.ts | 0 packages/ui-signer/src/Transaction.tsx | 23 ++--- packages/ui-signer/src/Unlock.tsx | 21 ++-- 52 files changed, 337 insertions(+), 555 deletions(-) delete mode 100644 packages/app-extrinsics/src/Account.tsx delete mode 100644 packages/app-extrinsics/src/Nonce.tsx delete mode 100644 packages/app-extrinsics/src/Params/Account.tsx rename packages/ui-signer/src/{Fees => Checks}/Proposal.tsx (100%) rename packages/ui-signer/src/{Fees => Checks}/Transfer.tsx (100%) rename packages/ui-signer/src/{Fees => Checks}/constants.ts (87%) rename packages/ui-signer/src/{Fees => Checks}/index.tsx (88%) rename packages/ui-signer/src/{Fees => Checks}/types.ts (100%) diff --git a/packages/app-123code/src/AccountSelector.tsx b/packages/app-123code/src/AccountSelector.tsx index 5e6000891e..88ad55fcc6 100644 --- a/packages/app-123code/src/AccountSelector.tsx +++ b/packages/app-123code/src/AccountSelector.tsx @@ -24,7 +24,7 @@ export default class AccountSelector extends React.PureComponent {
@@ -33,10 +33,10 @@ export default class AccountSelector extends React.PureComponent { - + - +
diff --git a/packages/app-123code/src/index.css b/packages/app-123code/src/index.css index bca7379b58..968f4c3282 100644 --- a/packages/app-123code/src/index.css +++ b/packages/app-123code/src/index.css @@ -7,7 +7,8 @@ .template--column { box-sizing: border-box; - flex: 1 1; + flex: 1; + min-width: 0; } } diff --git a/packages/app-accounts/src/Vanity/index.tsx b/packages/app-accounts/src/Vanity/index.tsx index 3d41855aeb..93c5c3c754 100644 --- a/packages/app-accounts/src/Vanity/index.tsx +++ b/packages/app-accounts/src/Vanity/index.tsx @@ -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 { 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} /> - ); } diff --git a/packages/app-explorer/src/Query.tsx b/packages/app-explorer/src/Query.tsx index 490d52549c..52ce2fdbd1 100644 --- a/packages/app-explorer/src/Query.tsx +++ b/packages/app-explorer/src/Query.tsx @@ -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 {
-
+
+
diff --git a/packages/app-explorer/src/Summary.tsx b/packages/app-explorer/src/Summary.tsx index f1efbcf8b0..2d3084fcc0 100644 --- a/packages/app-explorer/src/Summary.tsx +++ b/packages/app-explorer/src/Summary.tsx @@ -23,7 +23,7 @@ class Summary extends React.PureComponent { style={style} >
- + diff --git a/packages/app-extrinsics/src/Account.tsx b/packages/app-extrinsics/src/Account.tsx deleted file mode 100644 index 70eea28bff..0000000000 --- a/packages/app-extrinsics/src/Account.tsx +++ /dev/null @@ -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 { - state: State; - - constructor (props: Props) { - super(props); - - this.state = { - accountId: props.defaultValue - }; - } - - render () { - const { defaultValue, isDisabled, isError, isInput, label, type, withLabel } = this.props; - - return ( -
-
- -
- {this.renderBalance()} -
- ); - } - - private renderBalance (): React.ReactNode { - const { t, withLabel } = this.props; - const { accountId } = this.state; - - if (!accountId) { - return null; - } - - return ( - - - - ); - } - - private onChange = (accountId: string): void => { - const { onChange } = this.props; - - if (accountId) { - this.setState({ accountId }, () => { - onChange && onChange(accountId); - }); - } - } -} - -export default translate(Account); diff --git a/packages/app-extrinsics/src/Extrinsic.tsx b/packages/app-extrinsics/src/Extrinsic.tsx index a7b200ccf2..e315a3027c 100644 --- a/packages/app-extrinsics/src/Extrinsic.tsx +++ b/packages/app-extrinsics/src/Extrinsic.tsx @@ -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 { } 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 (
@@ -59,12 +58,12 @@ class ExtrinsicDisplay extends React.PureComponent { isDisabled={isDisabled} isError={isError} isPrivate={isPrivate} - labelMethod={labelMethod} - labelSection={labelSection} + label={label} onChange={this.onChangeMethod} withLabel={withLabel} /> { 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; diff --git a/packages/app-extrinsics/src/Nonce.tsx b/packages/app-extrinsics/src/Nonce.tsx deleted file mode 100644 index c099497f6d..0000000000 --- a/packages/app-extrinsics/src/Nonce.tsx +++ /dev/null @@ -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 { - render () { - const { label, callOnResult, value } = this.props; - - if (!value) { - return null; - } - - return ( -
- - - -
- ); - } -} diff --git a/packages/app-extrinsics/src/Params/Account.tsx b/packages/app-extrinsics/src/Params/Account.tsx deleted file mode 100644 index d23fae1527..0000000000 --- a/packages/app-extrinsics/src/Params/Account.tsx +++ /dev/null @@ -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 { - render () { - const { className, defaultValue: { value }, isDisabled, isError, label, style, withLabel } = this.props; - const defaultValue = (value as string); - - return ( - - ); - } - - 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 - }); - } -} diff --git a/packages/app-extrinsics/src/Params/Extrinsic.tsx b/packages/app-extrinsics/src/Params/Extrinsic.tsx index 2bc789a2fd..4cb3f5fbd2 100644 --- a/packages/app-extrinsics/src/Params/Extrinsic.tsx +++ b/packages/app-extrinsics/src/Params/Extrinsic.tsx @@ -33,12 +33,7 @@ class ExtrinsicDisplay extends React.PureComponent { isDisabled={isDisabled} isError={isError} isPrivate={isPrivate} - labelMethod={t('{{label}} (extrinsic)', { - replace: { - label - } - })} - labelSection={t('{{label}} (section)', { + label={t('{{label}} (extrinsic)', { replace: { label } diff --git a/packages/app-extrinsics/src/Params/index.ts b/packages/app-extrinsics/src/Params/index.ts index 70c61ca7a5..3187ae1088 100644 --- a/packages/app-extrinsics/src/Params/index.ts +++ b/packages/app-extrinsics/src/Params/index.ts @@ -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 }; diff --git a/packages/app-extrinsics/src/Selection.tsx b/packages/app-extrinsics/src/Selection.tsx index acfbe6e3bd..58fa88c320 100644 --- a/packages/app-extrinsics/src/Selection.tsx +++ b/packages/app-extrinsics/src/Selection.tsx @@ -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 { return (
- - + + + + + + +
+ -
); } @@ -163,24 +161,6 @@ class Query extends React.PureComponent { return buttons; } - private renderInputs () { - const { inputs } = this.state; - - if (inputs.length === 0) { - return ( -
:
- ); - } - - return ( - <> -
(
- {inputs} -
):
- - ); - } - private keyToName (key: Uint8Array | StorageFunction): string { if (isU8a(key)) { const u8a = Compact.stripLengthPrefix(key); diff --git a/packages/app-storage/src/Selection/Modules.tsx b/packages/app-storage/src/Selection/Modules.tsx index 1182a1fc0e..e4ae119877 100644 --- a/packages/app-storage/src/Selection/Modules.tsx +++ b/packages/app-storage/src/Selection/Modules.tsx @@ -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 { render () { const { t } = this.props; - const { isValid, key, params } = this.state; + const { isValid, key: { method, section }, params } = this.state; return (
- +
); } diff --git a/packages/app-storage/src/Selection/Raw.tsx b/packages/app-storage/src/Selection/Raw.tsx index ae1aada78b..b5a039e202 100644 --- a/packages/app-storage/src/Selection/Raw.tsx +++ b/packages/app-storage/src/Selection/Raw.tsx @@ -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 { onChange={this.onChangeKey} /> - +
); } diff --git a/packages/app-storage/src/index.css b/packages/app-storage/src/index.css index 0cc84723ca..5305681422 100644 --- a/packages/app-storage/src/index.css +++ b/packages/app-storage/src/index.css @@ -27,6 +27,10 @@ .storage--actionrow { display: flex; + + .button { + margin-bottom: 0.5rem; + } } .storage--actionrow-value { diff --git a/packages/app-toolbox/src/Rpc/Selection.tsx b/packages/app-toolbox/src/Rpc/Selection.tsx index 197bcec6c7..6a61fb6326 100644 --- a/packages/app-toolbox/src/Rpc/Selection.tsx +++ b/packages/app-toolbox/src/Rpc/Selection.tsx @@ -51,10 +51,12 @@ class Selection extends React.PureComponent {
{this.renderAccount()} diff --git a/packages/app-toolbox/src/Rpc/index.tsx b/packages/app-toolbox/src/Rpc/index.tsx index 47297d08a8..f320a54575 100644 --- a/packages/app-toolbox/src/Rpc/index.tsx +++ b/packages/app-toolbox/src/Rpc/index.tsx @@ -19,16 +19,12 @@ export default class RpcApp extends React.PureComponent { render () { return ( - {({ txqueue, queueRpc }: QueueProps) => [ - , - - ]} + {({ txqueue, queueRpc }: QueueProps) => ( + <> + + + + )} ); } diff --git a/packages/app-transfer/src/Transfer.tsx b/packages/app-transfer/src/Transfer.tsx index 12b225cd75..6b1ccf21d7 100644 --- a/packages/app-transfer/src/Transfer.tsx +++ b/packages/app-transfer/src/Transfer.tsx @@ -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 { return (
-
-
- -
-
- -
-
{this.renderAddress(accountId)}
+ + - { className={classes('ui--CardSummary', className)} style={style} > - +
{children}{ progress && !progress.hideValue && ( diff --git a/packages/ui-app/src/InputExtrinsic/SelectMethod.tsx b/packages/ui-app/src/InputExtrinsic/SelectMethod.tsx index 1cf7e90d9b..8848583c8c 100644 --- a/packages/ui-app/src/InputExtrinsic/SelectMethod.tsx +++ b/packages/ui-app/src/InputExtrinsic/SelectMethod.tsx @@ -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 { +export default class SelectMethod extends React.PureComponent { 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 { api.tx[value.section][method]; return ( - + ); } } - -export default translate(SelectMethod); diff --git a/packages/ui-app/src/InputExtrinsic/SelectSection.tsx b/packages/ui-app/src/InputExtrinsic/SelectSection.tsx index 4e528a4943..d8eecca007 100644 --- a/packages/ui-app/src/InputExtrinsic/SelectSection.tsx +++ b/packages/ui-app/src/InputExtrinsic/SelectSection.tsx @@ -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 { +export default class SelectSection extends React.PureComponent { 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 ( ); } } - -export default translate(SelectSection); diff --git a/packages/ui-app/src/InputExtrinsic/index.tsx b/packages/ui-app/src/InputExtrinsic/index.tsx index 0c0f33957d..2326f6bcbb 100644 --- a/packages/ui-app/src/InputExtrinsic/index.tsx +++ b/packages/ui-app/src/InputExtrinsic/index.tsx @@ -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 { } 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 (
- - + > +
+ + +
+
); } diff --git a/packages/ui-app/src/InputRpc/SelectMethod.tsx b/packages/ui-app/src/InputRpc/SelectMethod.tsx index 995f72e565..1ee4c5cc5b 100644 --- a/packages/ui-app/src/InputRpc/SelectMethod.tsx +++ b/packages/ui-app/src/InputRpc/SelectMethod.tsx @@ -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 { +export default class SelectMethod extends React.PureComponent { 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 { ); } } - -export default translate(SelectMethod); diff --git a/packages/ui-app/src/InputRpc/SelectSection.tsx b/packages/ui-app/src/InputRpc/SelectSection.tsx index 11c8c5b51a..0f11184985 100644 --- a/packages/ui-app/src/InputRpc/SelectSection.tsx +++ b/packages/ui-app/src/InputRpc/SelectSection.tsx @@ -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 { +export default class SelectSection extends React.PureComponent { 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 ( ); } } - -export default translate(SelectSection); diff --git a/packages/ui-app/src/InputRpc/index.tsx b/packages/ui-app/src/InputRpc/index.tsx index 087978f33b..2acb31d2b9 100644 --- a/packages/ui-app/src/InputRpc/index.tsx +++ b/packages/ui-app/src/InputRpc/index.tsx @@ -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 { } render () { - const { className, labelMethod, labelSection, style, withLabel } = this.props; + const { className, label, style, withLabel } = this.props; const { optionsMethod, optionsSection, value } = this.state; return (
- - + > +
+ + +
+
); } diff --git a/packages/ui-app/src/InputStorage/SelectKey.tsx b/packages/ui-app/src/InputStorage/SelectKey.tsx index d41f96e33f..b6da548999 100644 --- a/packages/ui-app/src/InputStorage/SelectKey.tsx +++ b/packages/ui-app/src/InputStorage/SelectKey.tsx @@ -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 { 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 { ); } } -export default withMulti( - SelectKey, - translate, - withApi -); +export default withApi(SelectKey); diff --git a/packages/ui-app/src/InputStorage/SelectSection.tsx b/packages/ui-app/src/InputStorage/SelectSection.tsx index 3be03a8887..a7a7128768 100644 --- a/packages/ui-app/src/InputStorage/SelectSection.tsx +++ b/packages/ui-app/src/InputStorage/SelectSection.tsx @@ -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 { +export default class SelectSection extends React.PureComponent { 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 ( ); } } - -export default translate(SelectSection); diff --git a/packages/ui-app/src/InputStorage/index.tsx b/packages/ui-app/src/InputStorage/index.tsx index 88ac745f93..415af79d8b 100644 --- a/packages/ui-app/src/InputStorage/index.tsx +++ b/packages/ui-app/src/InputStorage/index.tsx @@ -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 { } render () { - const { className, labelMethod, labelSection, style, withLabel } = this.props; + const { className, label, style, withLabel } = this.props; const { optionsMethod, optionsSection, value } = this.state; return (
- - + > +
+ + +
+
); } diff --git a/packages/ui-app/src/Labelled.tsx b/packages/ui-app/src/Labelled.tsx index f41b14cf27..fadb440b7d 100644 --- a/packages/ui-app/src/Labelled.tsx +++ b/packages/ui-app/src/Labelled.tsx @@ -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 { 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 { return (
{ withLabel - ? + ?
{label}
: null } - {children} +
+ {children} +
); } diff --git a/packages/ui-app/src/index.tsx b/packages/ui-app/src/index.tsx index 6983e6ff1e..5cc1ad3f22 100644 --- a/packages/ui-app/src/index.tsx +++ b/packages/ui-app/src/index.tsx @@ -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'; diff --git a/packages/ui-app/src/styles/components.css b/packages/ui-app/src/styles/components.css index 87715c8584..faf8f78bc0 100644 --- a/packages/ui-app/src/styles/components.css +++ b/packages/ui-app/src/styles/components.css @@ -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 { diff --git a/packages/ui-app/src/styles/form.css b/packages/ui-app/src/styles/form.css index d899ebe36b..9dfdd04f68 100644 --- a/packages/ui-app/src/styles/form.css +++ b/packages/ui-app/src/styles/form.css @@ -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; -} diff --git a/packages/ui-app/src/styles/semantic.css b/packages/ui-app/src/styles/semantic.css index 26937460af..bcfc455540 100644 --- a/packages/ui-app/src/styles/semantic.css +++ b/packages/ui-app/src/styles/semantic.css @@ -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, diff --git a/packages/ui-app/src/util/toShortAddress.ts b/packages/ui-app/src/util/toShortAddress.ts index 296480bedd..02320cf30d 100644 --- a/packages/ui-app/src/util/toShortAddress.ts +++ b/packages/ui-app/src/util/toShortAddress.ts @@ -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; } diff --git a/packages/ui-params/src/Param/Account.tsx b/packages/ui-params/src/Param/Account.tsx index f307574fdd..5f015190e4 100644 --- a/packages/ui-params/src/Param/Account.tsx +++ b/packages/ui-params/src/Param/Account.tsx @@ -21,7 +21,7 @@ export default class Account extends React.PureComponent { style={style} > { style={style} > { style={style} > { style={style} > { style={style} > { } } -export default withCall('query.balances.freeBalance', { paramName: 'value' })(BalanceDisplay); +export default withCall('query.balances.freeBalance')(BalanceDisplay); diff --git a/packages/ui-reactive/src/Nonce.tsx b/packages/ui-reactive/src/Nonce.tsx index 2bb1342e40..4dc375d42c 100644 --- a/packages/ui-reactive/src/Nonce.tsx +++ b/packages/ui-reactive/src/Nonce.tsx @@ -34,4 +34,4 @@ class Nonce extends React.PureComponent { } } -export default withCall('query.system.accountNonce', { paramName: 'value' })(Nonce); +export default withCall('query.system.accountNonce')(Nonce); diff --git a/packages/ui-signer/src/Fees/Proposal.tsx b/packages/ui-signer/src/Checks/Proposal.tsx similarity index 100% rename from packages/ui-signer/src/Fees/Proposal.tsx rename to packages/ui-signer/src/Checks/Proposal.tsx diff --git a/packages/ui-signer/src/Fees/Transfer.tsx b/packages/ui-signer/src/Checks/Transfer.tsx similarity index 100% rename from packages/ui-signer/src/Fees/Transfer.tsx rename to packages/ui-signer/src/Checks/Transfer.tsx diff --git a/packages/ui-signer/src/Fees/constants.ts b/packages/ui-signer/src/Checks/constants.ts similarity index 87% rename from packages/ui-signer/src/Fees/constants.ts rename to packages/ui-signer/src/Checks/constants.ts index 2446baa5fd..4c80930f00 100644 --- a/packages/ui-signer/src/Fees/constants.ts +++ b/packages/ui-signer/src/Checks/constants.ts @@ -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; diff --git a/packages/ui-signer/src/Fees/index.tsx b/packages/ui-signer/src/Checks/index.tsx similarity index 88% rename from packages/ui-signer/src/Fees/index.tsx rename to packages/ui-signer/src/Checks/index.tsx index c7b368d4a2..c832d94c57 100644 --- a/packages/ui-signer/src/Fees/index.tsx +++ b/packages/ui-signer/src/Checks/index.tsx @@ -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 { - 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 { 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 { extraWarn, hasAvailable, isRemovable, - isReserved + isReserved, + overLimit }; } @@ -118,19 +118,19 @@ class FeeDisplay extends React.PureComponent { 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 { ? undefined :
{t('The account does not have the required funds available for this transaction with the current provided values')}
} + { + overLimit + ?
{t(`This transaction will be rejected by the node as it is greater than the maximum size of ${MAX_SIZE_MB}MB`)}>
+ : undefined + } {this.renderTransfer()} {this.renderProposal()} { diff --git a/packages/ui-signer/src/Fees/types.ts b/packages/ui-signer/src/Checks/types.ts similarity index 100% rename from packages/ui-signer/src/Fees/types.ts rename to packages/ui-signer/src/Checks/types.ts diff --git a/packages/ui-signer/src/Transaction.tsx b/packages/ui-signer/src/Transaction.tsx index 34e1860c14..888f0ba319 100644 --- a/packages/ui-signer/src/Transaction.tsx +++ b/packages/ui-signer/src/Transaction.tsx @@ -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 { return null; } - const { method, section } = Method.findFunction(extrinsic.callIndex); + const { meta, method, section } = Method.findFunction(extrinsic.callIndex); return ( <> {section}.{method} +
{meta.documentation.join(' ')}
-
-
-
- {this.renderAccount()} - {children} -
- - {this.renderFees()} -
+ +
+ {this.renderAccount()} + {children}
+ {this.renderChecks()} ); @@ -67,7 +64,7 @@ class Transaction extends React.PureComponent { ); } - private renderFees () { + private renderChecks () { const { value: { accountId, extrinsic, isUnsigned } } = this.props; if (isUnsigned) { @@ -75,7 +72,7 @@ class Transaction extends React.PureComponent { } return ( - diff --git a/packages/ui-signer/src/Unlock.tsx b/packages/ui-signer/src/Unlock.tsx index 4fea909aa9..ac04cb7f22 100644 --- a/packages/ui-signer/src/Unlock.tsx +++ b/packages/ui-signer/src/Unlock.tsx @@ -52,18 +52,15 @@ class Unlock extends React.PureComponent { return (
-
- -
+
); }