diff --git a/packages/app-explorer/package.json b/packages/app-explorer/package.json index 1f70ab1862..fd0e7adc5c 100644 --- a/packages/app-explorer/package.json +++ b/packages/app-explorer/package.json @@ -11,9 +11,9 @@ "test": "jest --coverage" }, "devDependencies": { - "@polkadot/primitives": "^0.12.9", - "@polkadot/primitives-codec": "^0.12.9", - "@polkadot/primitives-json": "^0.12.9", + "@polkadot/primitives": "^0.13.8", + "@polkadot/primitives-codec": "^0.13.8", + "@polkadot/primitives-json": "^0.13.8", "@polkadot/ui-app": "^0.4.11", "@polkadot/util-crypto": "^0.19.6" } diff --git a/packages/app-extrinsics/package.json b/packages/app-extrinsics/package.json index 156901afc2..ca69e503e1 100644 --- a/packages/app-extrinsics/package.json +++ b/packages/app-extrinsics/package.json @@ -11,8 +11,8 @@ "test": "jest --coverage" }, "devDependencies": { - "@polkadot/extrinsics": "^0.12.9", - "@polkadot/extrinsics-codec": "^0.12.9", + "@polkadot/extrinsics": "^0.13.8", + "@polkadot/extrinsics-codec": "^0.13.8", "@polkadot/ui-app": "^0.4.11", "react-dropzone": "^4.2.9" } diff --git a/packages/app-extrinsics/src/Account.js b/packages/app-extrinsics/src/Account.js index cb0da18c87..bcb6d24948 100644 --- a/packages/app-extrinsics/src/Account.js +++ b/packages/app-extrinsics/src/Account.js @@ -20,7 +20,8 @@ type Props = I18nProps & { isInput?: boolean, label: string, onChange: (publicKey: Uint8Array) => void, - type?: KeyringOption$Type + type?: KeyringOption$Type, + withLabel?: boolean }; type State = { @@ -39,7 +40,7 @@ class Account extends React.PureComponent { } render (): React$Node { - const { className, defaultValue, isError, isInput, label, style, t, type } = this.props; + const { className, defaultValue, isError, isInput, label, style, t, type, withLabel } = this.props; const { publicKey } = this.state; return ( @@ -56,6 +57,7 @@ class Account extends React.PureComponent { onChange={this.onChange} placeholder='0x...' type={type} + withLabel={withLabel} /> { label={t('account.balance', { defaultValue: 'with an available balance of' })} + withLabel={withLabel} > this.setState(newState, () => { const { onChange } = this.props; const { extrinsic, values } = this.state; - const params = Object.values(extrinsic.params || {}); + const params = Object.values(extrinsic.params); const isValid = values.length === params.length && params.reduce((isValid, param, index) => isValid && diff --git a/packages/app-extrinsics/src/Params/Account.js b/packages/app-extrinsics/src/Params/Account.js index dcb9d1c148..a80f3aaf2f 100644 --- a/packages/app-extrinsics/src/Params/Account.js +++ b/packages/app-extrinsics/src/Params/Account.js @@ -15,17 +15,19 @@ type Props = BaseProps & { export default class Account extends React.PureComponent { render (): React$Node { - const { className, defaultValue, isError, label, style } = this.props; + const { className, defaultValue, isDisabled, isError, label, style, withLabel } = this.props; return ( ); } diff --git a/packages/app-extrinsics/src/Params/Call.js b/packages/app-extrinsics/src/Params/Call.js new file mode 100644 index 0000000000..5df2eb133a --- /dev/null +++ b/packages/app-extrinsics/src/Params/Call.js @@ -0,0 +1,31 @@ +// Copyright 2017-2018 Jaco Greeff +// This software may be modified and distributed under the terms +// of the ISC license. See the LICENSE file for details. +// @flow + +import type { Props } from '@polkadot/ui-app/Params/types'; + +import React from 'react'; + +import extrinsics from '@polkadot/extrinsics-substrate'; + +import Extrinsic from './Extrinsic'; + +const defaultValue = extrinsics.staking.methods.public.transfer; + +export default function Call ({ className, isDisabled, isError, index, label, onChange, style, withLabel }: Props): React$Node { + return ( + + ); +} diff --git a/packages/app-extrinsics/src/Params/Extrinsic.js b/packages/app-extrinsics/src/Params/Extrinsic.js new file mode 100644 index 0000000000..841e4d044d --- /dev/null +++ b/packages/app-extrinsics/src/Params/Extrinsic.js @@ -0,0 +1,62 @@ +// Copyright 2017-2018 Jaco Greeff +// This software may be modified and distributed under the terms +// of the ISC license. See the LICENSE file for details. +// @flow + +import type { Extrinsic } from '@polkadot/extrinsics/types'; +import type { Props as BaseProps } from '@polkadot/ui-app/Params/types'; +import type { I18nProps } from '@polkadot/ui-app/types'; +import type { EncodedMessage } from '../types'; + +import React from 'react'; + +import BaseExtrinsic from '../Extrinsic'; +import translate from '../translate'; + +type Props = BaseProps & I18nProps & { + defaultValue: Extrinsic, + isPrivate: boolean, + withLabel?: boolean, +}; + +class CExtrinsic extends React.PureComponent { + render (): React$Node { + const { className, defaultValue, isDisabled, isError, isPrivate, label, style, t, withLabel } = this.props; + + return ( + + ); + } + + onChange = ({ isValid, value }: EncodedMessage): void => { + const { index, onChange } = this.props; + + onChange(index, { + isValid, + value + }); + } +} + +export default translate(CExtrinsic); diff --git a/packages/app-extrinsics/src/Params/Proposal.js b/packages/app-extrinsics/src/Params/Proposal.js index cc58172b13..fc42e3f18b 100644 --- a/packages/app-extrinsics/src/Params/Proposal.js +++ b/packages/app-extrinsics/src/Params/Proposal.js @@ -3,57 +3,29 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { Props as BaseProps } from '@polkadot/ui-app/Params/types'; -import type { I18nProps } from '@polkadot/ui-app/types'; -import type { EncodedMessage } from '../types'; +import type { Props } from '@polkadot/ui-app/Params/types'; import React from 'react'; import extrinsics from '@polkadot/extrinsics-substrate'; -import Extrinsic from '../Extrinsic'; -import translate from '../translate'; - -type Props = BaseProps & I18nProps; +import Extrinsic from './Extrinsic'; const defaultValue = extrinsics.consensus.methods.private.setCode; -class Proposal extends React.PureComponent { - render (): React$Node { - const { className, isError, label, style, t } = this.props; - - return ( - - ); - } - - onChange = ({ isValid, value }: EncodedMessage): void => { - const { index, onChange } = this.props; - - onChange(index, { - isValid, - value - }); - } +export default function Proposal ({ className, isDisabled, isError, index, label, onChange, style, withLabel }: Props): React$Node { + return ( + + ); } - -export default translate(Proposal); diff --git a/packages/app-extrinsics/src/Params/index.js b/packages/app-extrinsics/src/Params/index.js index cd9cd8c7b5..c24c87ebf1 100644 --- a/packages/app-extrinsics/src/Params/index.js +++ b/packages/app-extrinsics/src/Params/index.js @@ -6,10 +6,12 @@ import type { ComponentMap } from '@polkadot/ui-app/Params/types'; import Account from './Account'; +import Call from './Call'; import Proposal from './Proposal'; -const components: ComponentMap = { +const components: $Shape = { 'AccountId': Account, + 'Call': Call, 'Proposal': Proposal }; diff --git a/packages/app-storage/src/Query/index.js b/packages/app-storage/src/Query.js similarity index 88% rename from packages/app-storage/src/Query/index.js rename to packages/app-storage/src/Query.js index dd8a851300..bbc5de439a 100644 --- a/packages/app-storage/src/Query/index.js +++ b/packages/app-storage/src/Query.js @@ -4,17 +4,17 @@ // @flow import type { I18nProps } from '@polkadot/ui-app/types'; -import type { StorageQuery } from '../types'; +import type { StorageQuery } from './types'; import React from 'react'; import Button from '@polkadot/ui-app/src/Button'; import Labelled from '@polkadot/ui-app/src/Labelled'; import typeToText from '@polkadot/ui-app/src/Params/typeToText'; +import valueToText from '@polkadot/ui-app/src/Params/valueToText'; import withStorageDiv from '@polkadot/ui-react-rx/with/storageDiv'; -import translate from '../translate'; -import format from './format'; +import translate from './translate'; type Props = I18nProps & { onRemove: (id: number) => void, @@ -38,7 +38,7 @@ class Query extends React.PureComponent { cache[id] = withStorageDiv(key, { params: values })( (value) => - format(key.type, value), + valueToText(key.type, value), { className: 'ui disabled dropdown selection' } ); } @@ -46,10 +46,9 @@ class Query extends React.PureComponent { return cache[id]; })(); const inputs = Object - .keys(key.params || {}) + .keys(key.params) .map((name, index) => { - // $FlowFixMe key.params exists - const formatted = format(key.params[name].type, params[index].value, 12); + const formatted = valueToText(key.params[name].type, params[index].value); return ( {name}={formatted} diff --git a/packages/app-storage/src/Query/format.js b/packages/app-storage/src/Query/format.js deleted file mode 100644 index 7d0713e050..0000000000 --- a/packages/app-storage/src/Query/format.js +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. -// @flow - -import type { Param$Type, Param$TypeArray } from '@polkadot/primitives/param'; - -import React from 'react'; - -// import IdentityIcon from '@polkadot/ui-react/IdentityIcon'; -import addressEncode from '@polkadot/util-keyring/address/encode'; -import u8aToBn from '@polkadot/util/u8a/toBn'; -import u8aToHexShort from '@polkadot/util/u8a/toHexShort'; -import isU8a from '@polkadot/util/is/u8a'; - -// flowlint-next-line unclear-type:off -export default function format (type: Param$Type | Param$TypeArray, value?: any, fontSize?: number = 14): any { - if (type === 'bool') { - return ( - {value - ? 'Yes' - : 'No' - } - ); - } - - if (!value) { - return ( - unknown - ); - } - - // FIXME: this is a hack, but just to get it going, we should be going through and decoding arrays properly - if (Array.isArray(type)) { - const u8a = (value: Uint8Array); - const length = u8aToBn(u8a.slice(0, 4), true).toNumber(); - const result = []; - let offset = 4; - - // FIXME: 32? Only for Hash & AccountId ... - for (let i = 0; i < length; i++, offset += 32) { - result.push(format(type[0], u8a.slice(offset, offset + 32), fontSize)); - } - - return result; - } - - if (type === 'AccountId') { - const address = addressEncode((value: Uint8Array)); - - // const size = Math.floor(fontSize + (fontSize / 14) * 18); - // - - return ( - {address} - ); - } - - if (isU8a(value)) { - return ( - {u8aToHexShort((value: Uint8Array), 256)} - ); - } - - return ( - {value.toString()} - ); -} diff --git a/packages/app-storage/src/Selection.js b/packages/app-storage/src/Selection.js index 59ee971ea7..bb0864513b 100644 --- a/packages/app-storage/src/Selection.js +++ b/packages/app-storage/src/Selection.js @@ -34,7 +34,8 @@ let id = -1; class Selection extends React.PureComponent { state: State = ({ - key: defaultValue + key: defaultValue, + params: [] }: $Shape); render (): React$Node { @@ -75,14 +76,13 @@ class Selection extends React.PureComponent { this.setState( (prevState: State) => { const { key = prevState.key, params = prevState.params } = newState; - const keyParams = Object.values(key.params || {}); - const valParams = params || []; - const isValid = valParams.length === keyParams.length && + const keyParams = Object.values(key.params); + const isValid = params.length === keyParams.length && keyParams.reduce((isValid, param, index) => isValid && - !isUndefined(valParams[index]) && - !isUndefined(valParams[index].value) && - valParams[index].isValid, true); + !isUndefined(params[index]) && + !isUndefined(params[index].value) && + params[index].isValid, true); return { isValid, diff --git a/packages/app-storage/src/index.css b/packages/app-storage/src/index.css index a1df60a200..2ea6d30b9a 100644 --- a/packages/app-storage/src/index.css +++ b/packages/app-storage/src/index.css @@ -20,9 +20,9 @@ opacity: 1; } -.storage--Query span+span { +/* .storage--Query span+span { margin-left: 0.5em; -} +} */ .storage--Query .storage--actionrow-value { padding: 0 0.25rem; diff --git a/packages/app-vanitygen/src/index.js b/packages/app-vanitygen/src/index.js index 67ef851bc5..cb420dd37e 100644 --- a/packages/app-vanitygen/src/index.js +++ b/packages/app-vanitygen/src/index.js @@ -67,7 +67,7 @@ class App extends React.PureComponent {
{ /> void, + onSearch?: (filteredOptions: Array<*>, query: string) => Array<*>, + options: Array<*>, // flowlint-next-line unclear-type:off - transform?: (value: any) => any + transform?: (value: any) => any, + value?: mixed, + withLabel?: boolean, }; type SUIEvent = { @@ -27,27 +32,24 @@ type SUIEvent = { export default class Dropdown extends React.PureComponent { render (): React$Node { - const { className, isError, label, style } = this.props; - const _props = {...this.props}; - - delete _props.className; - delete _props.isError; - delete _props.label; - delete _props.onChange; - delete _props.style; - delete _props.transform; + const { className, defaultValue, isDisabled, isError, label, onSearch, options, style, withLabel, value } = this.props; return ( ); diff --git a/packages/ui-app/src/Input.js b/packages/ui-app/src/Input.js index f482d72bc6..d0e7891288 100644 --- a/packages/ui-app/src/Input.js +++ b/packages/ui-app/src/Input.js @@ -25,7 +25,8 @@ type Props = BareProps & { onChange: (value: any) => void, placeholder?: string, type?: Input$Type, - value?: mixed + value?: mixed, + withLabel?: boolean }; type SUIEvent = { @@ -45,7 +46,7 @@ export default class Input extends React.PureComponent { }; render (): React$Node { - const { children, className, defaultValue, isAction = false, isDisabled = false, isError = false, label, max, min, placeholder, style, type = 'text', value } = this.props; + const { children, className, defaultValue, isAction = false, isDisabled = false, isError = false, label, max, min, placeholder, style, type = 'text', value, withLabel } = this.props; const { name } = this.state; return ( @@ -53,6 +54,7 @@ export default class Input extends React.PureComponent { className={className} label={label} style={style} + withLabel={withLabel} > void, type?: KeyringOption$Type, - value?: string | Uint8Array + value?: string | Uint8Array, + withLabel?: boolean }; type State = { @@ -61,7 +62,7 @@ export default class InputAddress extends React.Component { } render (): React$Node { - const { className, hideAddress = false, isError, label, onChange, style, type = 'all' } = this.props; + const { className, hideAddress = false, isError, label, onChange, style, type = 'all', withLabel } = this.props; const { defaultValue, value } = this.state; const options = keyring.getOptions(type); @@ -72,11 +73,12 @@ export default class InputAddress extends React.Component { isError={isError} label={label} onChange={onChange} + onSearch={this.onSearch} options={options} - search={this.onSearch} style={style} transform={transform} value={value} + withLabel={withLabel} /> ); } diff --git a/packages/ui-app/src/InputExtrinsic/SelectMethod.js b/packages/ui-app/src/InputExtrinsic/SelectMethod.js index 0cf509080d..99d53e0181 100644 --- a/packages/ui-app/src/InputExtrinsic/SelectMethod.js +++ b/packages/ui-app/src/InputExtrinsic/SelectMethod.js @@ -19,10 +19,11 @@ type Props = I18nProps & { label?: string, onChange: (value: Extrinsic) => void, type: 'private' | 'public', - value: Extrinsic + value: Extrinsic, + withLabel?: boolean }; -function SelectMethod ({ className, isError, label = '', onChange, style, t, type, value: { name, section } }: Props): React$Node { +function SelectMethod ({ className, isError, label = '', onChange, style, t, type, value: { name, section }, withLabel }: Props): React$Node { // $FlowFixMe string vs ... if (!extrinsics[section]) { return null; @@ -45,6 +46,7 @@ function SelectMethod ({ className, isError, label = '', onChange, style, t, typ style={style} transform={transform} value={name} + withLabel={withLabel} /> ); } diff --git a/packages/ui-app/src/InputExtrinsic/SelectSection.js b/packages/ui-app/src/InputExtrinsic/SelectSection.js index 85d31dc217..98ebae4dea 100644 --- a/packages/ui-app/src/InputExtrinsic/SelectSection.js +++ b/packages/ui-app/src/InputExtrinsic/SelectSection.js @@ -18,10 +18,11 @@ type Props = I18nProps & { label?: string, onChange: (value: ExtrinsicSectionName) => void, type: 'private' | 'public', - value: Extrinsic + value: Extrinsic, + withLabel?: boolean }; -function SelectSection ({ className, defaultValue, isError, label = '', onChange, style, t, type, value: { section } }: Props): React$Node { +function SelectSection ({ className, defaultValue, isError, label = '', onChange, style, t, type, value: { section }, withLabel }: Props): React$Node { const options = createOptions(type); return ( @@ -36,6 +37,7 @@ function SelectSection ({ className, defaultValue, isError, label = '', onChange options={options} style={style} value={section} + withLabel={withLabel} /> ); } diff --git a/packages/ui-app/src/InputExtrinsic/index.js b/packages/ui-app/src/InputExtrinsic/index.js index 2e1e1559ae..02eedcbc1b 100644 --- a/packages/ui-app/src/InputExtrinsic/index.js +++ b/packages/ui-app/src/InputExtrinsic/index.js @@ -24,7 +24,8 @@ type Props = I18nProps & { isPrivate?: boolean, labelMethod?: string, labelSection?: string, - onChange: (value: Extrinsic) => void + onChange: (value: Extrinsic) => void, + withLabel?: boolean }; type State = { @@ -43,7 +44,7 @@ class InputExtrinsic extends React.PureComponent { } render (): React$Node { - const { className, isPrivate = false, labelMethod, labelSection, style } = this.props; + const { className, isPrivate = false, labelMethod, labelSection, style, withLabel } = this.props; const { value } = this.state; const type = isPrivate ? 'private' : 'public'; @@ -58,6 +59,7 @@ class InputExtrinsic extends React.PureComponent { onChange={this.onSectionChange} type={type} value={value} + withLabel={withLabel} /> { onChange={this.onKeyChange} value={value} type={type} + withLabel={withLabel} />
); diff --git a/packages/ui-app/src/InputStorage/SelectKey.js b/packages/ui-app/src/InputStorage/SelectKey.js index cda71c803e..6f5953674f 100644 --- a/packages/ui-app/src/InputStorage/SelectKey.js +++ b/packages/ui-app/src/InputStorage/SelectKey.js @@ -18,10 +18,11 @@ type Props = I18nProps & { isError?: boolean, label?: string, onChange: (value: StorageDef$Key) => void, - value: StorageDef$Key + value: StorageDef$Key, + withLabel?: boolean }; -function SelectKey ({ className, isError, label = '', onChange, style, t, value: { name, section } }: Props): React$Node { +function SelectKey ({ className, isError, label = '', onChange, style, t, value: { name, section }, withLabel }: Props): React$Node { // $FlowFixMe string vs ... if (!map[section]) { return null; @@ -44,6 +45,7 @@ function SelectKey ({ className, isError, label = '', onChange, style, t, value: style={style} transform={transform} value={name} + withLabel={withLabel} /> ); } diff --git a/packages/ui-app/src/InputStorage/SelectSection.js b/packages/ui-app/src/InputStorage/SelectSection.js index b1082ae5ac..b87f4da5ac 100644 --- a/packages/ui-app/src/InputStorage/SelectSection.js +++ b/packages/ui-app/src/InputStorage/SelectSection.js @@ -17,12 +17,13 @@ type Props = I18nProps & { isError?: boolean, label: string, onChange: (value: StateDb$SectionNames) => void, - value: StorageDef$Key + value: StorageDef$Key, + withLabel?: boolean }; const options = createOptions(); -function SelectSection ({ className, defaultValue, isError, label, onChange, style, t, value: { section } }: Props): React$Node { +function SelectSection ({ className, defaultValue, isError, label, onChange, style, t, value: { section }, withLabel }: Props): React$Node { return ( ); } diff --git a/packages/ui-app/src/InputStorage/index.js b/packages/ui-app/src/InputStorage/index.js index f47d96b5d1..fdae65e818 100644 --- a/packages/ui-app/src/InputStorage/index.js +++ b/packages/ui-app/src/InputStorage/index.js @@ -24,6 +24,7 @@ type Props = I18nProps & { labelMethod?: string, labelSection?: string, onChange: (value: StorageDef$Key) => void, + withLabel?: boolean }; type State = { @@ -42,7 +43,7 @@ class InputStorage extends React.PureComponent { } render (): React$Node { - const { className, labelMethod, labelSection, style } = this.props; + const { className, labelMethod, labelSection, style, withLabel } = this.props; const { value } = this.state; return ( @@ -55,12 +56,14 @@ class InputStorage extends React.PureComponent { label={labelSection} onChange={this.onSectionChange} value={value} + withLabel={withLabel} /> ); diff --git a/packages/ui-app/src/Labelled.js b/packages/ui-app/src/Labelled.js index 46e06eb7a0..c84e5f68b9 100644 --- a/packages/ui-app/src/Labelled.js +++ b/packages/ui-app/src/Labelled.js @@ -11,20 +11,25 @@ import Label from 'semantic-ui-react/dist/es/elements/Label'; type Props = BareProps & { // flowlint-next-line unclear-type:off label?: any, - children: React$Node + children: React$Node, + withLabel?: boolean, }; const defaultLabel: React$Node = (
 
); -export default function Labelled ({ className, children, label = defaultLabel, style }: Props): React$Node { +export default function Labelled ({ className, children, label = defaultLabel, style, withLabel = true }: Props): React$Node { return (
- + { + withLabel + ? + : null + } {children}
); diff --git a/packages/ui-app/src/Params/Param/Account.js b/packages/ui-app/src/Params/Param/Account.js index 13e2954c0b..a9b543d326 100644 --- a/packages/ui-app/src/Params/Param/Account.js +++ b/packages/ui-app/src/Params/Param/Account.js @@ -12,7 +12,7 @@ import Bare from './Bare'; export default class Account extends React.PureComponent { render (): React$Node { - const { className, isError, label, style, value: { options: { initValue } = {} } } = this.props; + const { className, isDisabled, isError, label, style, value: { options: { initValue } = {} }, withLabel } = this.props; // flowlint-next-line unclear-type:off const defaultValue = ((initValue: any): Uint8Array); @@ -25,11 +25,13 @@ export default class Account extends React.PureComponent { ); diff --git a/packages/ui-app/src/Params/Param/Amount.js b/packages/ui-app/src/Params/Param/Amount.js index 9a34f3424a..277e7141d4 100644 --- a/packages/ui-app/src/Params/Param/Amount.js +++ b/packages/ui-app/src/Params/Param/Amount.js @@ -14,7 +14,7 @@ import Bare from './Bare'; export default class Amount extends React.PureComponent { render (): React$Node { - const { className, isError, label, style, value: { options: { initValue = 0, maxValue, minValue = 0 } = {} } } = this.props; + const { className, isDisabled, isError, label, style, value: { options: { initValue = 0, maxValue, minValue = 0 } = {} }, withLabel } = this.props; return ( { ); diff --git a/packages/ui-app/src/Params/Param/Base.js b/packages/ui-app/src/Params/Param/Base.js index ff72d58d5c..eb18c08a6b 100644 --- a/packages/ui-app/src/Params/Param/Base.js +++ b/packages/ui-app/src/Params/Param/Base.js @@ -14,10 +14,11 @@ import Bare from './Bare'; type Props = BareProps & { children: React$Node, label?: string, - size?: Size + size?: Size, + withLabel?: boolean }; -export default function Base ({ children, className, label, size = 'medium', style }: Props): React$Node { +export default function Base ({ children, className, label, size = 'medium', style, withLabel }: Props): React$Node { return ( {children}
diff --git a/packages/ui-app/src/Params/Param/Bool.js b/packages/ui-app/src/Params/Param/Bool.js index fe84ed554a..13e31fbc6c 100644 --- a/packages/ui-app/src/Params/Param/Bool.js +++ b/packages/ui-app/src/Params/Param/Bool.js @@ -17,7 +17,7 @@ const options = [ export default class Bool extends React.PureComponent { render (): React$Node { - const { className, isError, label, style, value: { options: { initValue = false } = {} } } = this.props; + const { className, isDisabled, isError, label, style, value: { options: { initValue = false } = {} }, withLabel } = this.props; return ( { > ); diff --git a/packages/ui-app/src/Params/Param/Bytes.js b/packages/ui-app/src/Params/Param/Bytes.js index 21b8b749e8..9761939035 100644 --- a/packages/ui-app/src/Params/Param/Bytes.js +++ b/packages/ui-app/src/Params/Param/Bytes.js @@ -23,7 +23,7 @@ const defaultValidate = (u8a: Uint8Array): boolean => export default class Bytes extends React.PureComponent { render (): React$Node { - const { className, isError, label, size = 'full', style } = this.props; + const { className, isDisabled, isError, label, size = 'full', style, withLabel } = this.props; return ( { > ); diff --git a/packages/ui-app/src/Params/Param/Wasm.js b/packages/ui-app/src/Params/Param/Code.js similarity index 80% rename from packages/ui-app/src/Params/Param/Wasm.js rename to packages/ui-app/src/Params/Param/Code.js index db9e00c402..b96381271e 100644 --- a/packages/ui-app/src/Params/Param/Wasm.js +++ b/packages/ui-app/src/Params/Param/Code.js @@ -12,17 +12,19 @@ import u8aConcat from '@polkadot/util/u8a/concat'; import BytesFile from './File'; -export default class Wasm extends React.PureComponent { +export default class Code extends React.PureComponent { render (): React$Node { - const { className, isError, label, style } = this.props; + const { className, isDisabled, isError, label, style, withLabel } = this.props; return ( ); } diff --git a/packages/ui-app/src/Params/Param/File.js b/packages/ui-app/src/Params/Param/File.js index 1c0206986e..d7d4e38a1e 100644 --- a/packages/ui-app/src/Params/Param/File.js +++ b/packages/ui-app/src/Params/Param/File.js @@ -12,10 +12,12 @@ import translate from '../../translate'; import Base from './Base'; type Props = BareProps & { + isDisabled?: boolean, isError?: boolean, label: string, onChange: (contents: Uint8Array) => void, - t: I18Next$Translate + t: I18Next$Translate, + withLabel?: boolean } type State = { @@ -29,16 +31,18 @@ class BytesFile extends React.PureComponent { state: State = {}; render (): React$Node { - const { className, isError = false, label, t } = this.props; + const { className, isDisabled, isError = false, label, t, withLabel } = this.props; const { file } = this.state; return ( diff --git a/packages/ui-app/src/Params/Param/Hash.js b/packages/ui-app/src/Params/Param/Hash.js index 919e37b337..b621f97e98 100644 --- a/packages/ui-app/src/Params/Param/Hash.js +++ b/packages/ui-app/src/Params/Param/Hash.js @@ -9,16 +9,18 @@ import React from 'react'; import Bytes from './Bytes'; -export default function Hash ({ index, isError, label, onChange, value }: Props): React$Node { +export default function Hash ({ index, isDisabled, isError, label, onChange, value, withLabel }: Props): React$Node { return ( ); } diff --git a/packages/ui-app/src/Params/Param/KeyValue.js b/packages/ui-app/src/Params/Param/KeyValue.js new file mode 100644 index 0000000000..914c6ca399 --- /dev/null +++ b/packages/ui-app/src/Params/Param/KeyValue.js @@ -0,0 +1,115 @@ +// Copyright 2017-2018 Jaco Greeff +// This software may be modified and distributed under the terms +// of the ISC license. See the LICENSE file for details. +// @flow + +import type { Props } from '../types'; + +import React from 'react'; + +import bnToU8a from '@polkadot/util/bn/toU8a'; +import u8aConcat from '@polkadot/util/u8a/concat'; +import hexToU8a from '@polkadot/util/hex/toU8a'; + +import Input from '../../Input'; +import Bare from './Bare'; + +type State$Param = { + isValid: boolean, + u8a: Uint8Array +} + +type State = { + key: State$Param, + value: State$Param +}; + +export default class KeyValue extends React.PureComponent { + state: State = { + key: { + isValid: false, + u8a: new Uint8Array([]) + }, + value: { + isValid: false, + u8a: new Uint8Array([]) + } + }; + + render (): React$Node { + const { className, isDisabled, label, style, withLabel } = this.props; + const { key, value } = this.state; + + return ( + + + + + ); + } + + createParam (hex: string, length: number = -1): State$Param { + let u8a; + + try { + u8a = hexToU8a(hex); + } catch (error) { + u8a = new Uint8Array([]); + } + + const isValidLength = length !== -1 + ? u8a.length === length + : u8a.length !== 0; + + return { + isValid: isValidLength, + u8a + }; + } + + nextState (newState: $Shape): void { + this.setState( + (prevState: State, { index, onChange }: Props) => { + const { key = prevState.key, value = prevState.value } = newState; + + onChange(index, { + isValid: key.isValid && value.isValid, + value: u8aConcat( + u8aConcat(bnToU8a(key.u8a.length, 32, true), key.u8a), + u8aConcat(bnToU8a(value.u8a.length, 32, true), value.u8a) + ) + }); + + return newState; + } + ); + } + + onChangeKey = (key: string): void => { + this.nextState({ key: this.createParam(key) }); + }; + + onChangeValue = (value: string): void => { + this.nextState({ value: this.createParam(value) }); + }; +} diff --git a/packages/ui-app/src/Params/Param/Unknown.js b/packages/ui-app/src/Params/Param/Unknown.js index 57b85d417f..936cf08882 100644 --- a/packages/ui-app/src/Params/Param/Unknown.js +++ b/packages/ui-app/src/Params/Param/Unknown.js @@ -3,7 +3,8 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { Props as BaseProps } from '../types'; +import type { Param$Types } from '@polkadot/params/types'; +import type { Props as BareProps } from '../types'; import React from 'react'; @@ -11,15 +12,20 @@ import translate from '../../translate'; import Base from './Base'; import typeToText from '../typeToText'; -type Props = BaseProps & { - t: I18Next$Translate +type Props = BareProps & { + t: I18Next$Translate, + value: { + type: Param$Types + }, + withLabel?: boolean }; -function Unknown ({ label, t, value: { type } }: Props): React$Node { +function Unknown ({ label, t, value: { type }, withLabel }: Props): React$Node { return (
{t('param.unknown', { diff --git a/packages/ui-app/src/Params/Param/VoteThreshold.js b/packages/ui-app/src/Params/Param/VoteThreshold.js index 0add507f22..e219d45422 100644 --- a/packages/ui-app/src/Params/Param/VoteThreshold.js +++ b/packages/ui-app/src/Params/Param/VoteThreshold.js @@ -19,7 +19,7 @@ const options = [ export default class VoteThreshold extends React.PureComponent { render (): React$Node { - const { className, label, style, value: { options: { initValue = 0 } = {} } } = this.props; + const { className, isDisabled, isError, label, style, value: { options: { initValue = 0 } = {} }, withLabel } = this.props; const defaultValue = initValue || 0; return ( @@ -30,9 +30,12 @@ export default class VoteThreshold extends React.PureComponent { ); diff --git a/packages/ui-app/src/Params/Param/findComponent.js b/packages/ui-app/src/Params/Param/findComponent.js index bc00d7ec72..35eb9a3041 100644 --- a/packages/ui-app/src/Params/Param/findComponent.js +++ b/packages/ui-app/src/Params/Param/findComponent.js @@ -3,17 +3,18 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { Param$Type, Param$TypeArray } from '@polkadot/primitives/param'; +import type { Param$Types } from '@polkadot/params/types'; import type { ComponentMap } from '../types'; import Account from './Account'; import Amount from './Amount'; import Bool from './Bool'; import Bytes from './Bytes'; +import Code from './Code'; import Hash from './Hash'; +import KeyValue from './KeyValue'; import Unknown from './Unknown'; import VoteThreshold from './VoteThreshold'; -import Wasm from './Wasm'; const components: ComponentMap = { 'AccountId': Account, @@ -21,21 +22,32 @@ const components: ComponentMap = { 'BlockNumber': Amount, 'bool': Bool, 'Bytes': Bytes, - 'Digest': Bytes, + 'Code': Code, + 'Call': Unknown, + 'Digest': Unknown, 'Hash': Hash, + 'Index': Amount, + 'KeyValue': KeyValue, + 'MisbehaviorReport': Unknown, + 'PropIndex': Amount, + 'Proposal': Unknown, + 'ReferendumIndex': Amount, + 'SessionKey': Amount, + 'Signature': Hash, 'Timestamp': Amount, 'u32': Amount, 'u64': Amount, - 'VoteThreshold': VoteThreshold, - 'Wasm': Wasm + 'VoteIndex': Amount, + 'VoteThreshold': VoteThreshold }; -export default function findComponent (type: Param$Type | Param$TypeArray, overrides?: ComponentMap = {}): React$ComponentType<*> | Array> { +export default function findComponent (type: Param$Types, overrides?: ComponentMap = {}): React$ComponentType<*> | Array> { if (Array.isArray(type)) { - // $FlowFixMe we are ok here - return type.map((type) => - findComponent(type, overrides) - ); + return type + .map((type) => + // $FlowFixMe running out of options to check the embedded arrays + findComponent(type, overrides) + ); } return overrides[type] || components[type] || Unknown; diff --git a/packages/ui-app/src/Params/Param/index.js b/packages/ui-app/src/Params/Param/index.js index 7ba2144102..3cb66161dc 100644 --- a/packages/ui-app/src/Params/Param/index.js +++ b/packages/ui-app/src/Params/Param/index.js @@ -3,80 +3,133 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { Param, Param$Type } from '@polkadot/primitives/param'; +import type { Param } from '@polkadot/params/types'; import type { I18nProps } from '../../types'; -import type { ComponentMap, RawParam } from '../types'; +import type { BaseProps, ComponentMap, RawParam } from '../types'; import React from 'react'; import translate from '../../translate'; import typeToText from '../typeToText'; import findComponent from './findComponent'; +import Unknown from './Unknown'; type Props = I18nProps & { index: number, overrides?: ComponentMap, - onChange: (value: RawParam) => void, + onChange: (index: number, value: RawParam) => void, value: Param & { name: string }; }; +type ComponentProps = BaseProps & { + index: number +}; + type State = { - Component: React$ComponentType<*> | Array> | null + Components: React$ComponentType<*> | Array> + | null } class ParamComponent extends React.PureComponent { state: State = { - Component: null + Components: [] }; static getDerivedStateFromProps ({ overrides, value: { type } = {} }: Props): State { return { - Component: !type + Components: !type ? null : findComponent(type, overrides) }; } render (): React$Node { - const { Component } = this.state; + const { Components } = this.state; - if (!Component) { + if (Components === null) { return null; } - return Array.isArray(Component) - ? Component.map(this.renderComponent) - : this.renderComponent(Component); + const { value: { type } } = this.props; + + // FIXME We don't handle array or tuple inputs atm + return Array.isArray(type) + ? this.renderUnknown() + : this.renderComponents(); } - renderComponent = (Component: React$ComponentType<*>, sub: number = -1): React$Node => { - const { className, index, onChange, style, value: { name, type, options = {} } = {} } = this.props; - const _type: Param$Type = Array.isArray(type) - ? type[sub] - : type; - const text = typeToText(_type); - const labelExtra = sub === -1 - ? '' - : ` (${index})`; + renderComponents = (_Components: React$ComponentType<*> | Array> | null = this.state.Components, startIndex: string = '0', { name, type, options = {} } = this.props.value) => { + if (!_Components) { + return null; + } + + const { className, index, onChange, style } = this.props; + + if (!Array.isArray(type)) { + // flowlint-next-line unclear-type:off + const Component = ((_Components: any): React$ComponentType<*>); + + return this.renderComponent(Component, startIndex, { + className, + index, + onChange, + style, + value: { + name, + type, + options + } + }); + } + + // flowlint-next-line unclear-type:off + const Components = ((_Components: any): Array>); + + return Components.map((Component, index) => { + return this.renderComponents(Component, `${startIndex}-${index}`, { + name, + type: type[index], + options: {} + }); + }); + } + + renderComponent = (Component: React$ComponentType<*>, sub: string, props: ComponentProps): React$Node => { + const { className, index, onChange, style, value: { name, type, options = {} } } = props; + const text = typeToText(type); return ( ); } + + renderUnknown = (): React$Node => { + const { className, index, onChange, style, value: { name, type } = {} } = this.props; + + return this.renderComponent(Unknown, '0', { + className, + index, + onChange, + style, + value: { + name, + type + } + }); + } } export default translate(ParamComponent); diff --git a/packages/ui-app/src/Params/index.js b/packages/ui-app/src/Params/index.js index 9eef19586e..2ee4e7e20b 100644 --- a/packages/ui-app/src/Params/index.js +++ b/packages/ui-app/src/Params/index.js @@ -3,7 +3,7 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { Section$Item } from '@polkadot/primitives/param'; +import type { Section$Item } from '@polkadot/params/types'; import type { I18nProps } from '../types'; import type { ComponentMap, RawParam, RawParams } from './types'; diff --git a/packages/ui-app/src/Params/initValue.js b/packages/ui-app/src/Params/initValue.js index 178d4b0e62..8aa7983093 100644 --- a/packages/ui-app/src/Params/initValue.js +++ b/packages/ui-app/src/Params/initValue.js @@ -4,34 +4,26 @@ // @flow // flowlint sketchy-null-mixed:off -import type { Param } from '@polkadot/primitives/param'; +import type { Param$Type } from '@polkadot/params/types'; import BN from 'bn.js'; -import isUndefined from '@polkadot/util/is/undefined'; - -export default function getInitValue ({ options: { initValue, minValue } = {}, type }: Param): mixed { - if (Array.isArray(type)) { - return type.map((type, index) => - getInitValue(({ - type, - options: { - initValue: isUndefined(initValue) || !Array.isArray(initValue) - ? initValue - : initValue[index], - minValue: isUndefined(minValue) || !Array.isArray(minValue) - ? minValue - : minValue[index] - } - }: $Shape)) - ); - } +type Options = { + initValue?: mixed, + minValue?: mixed +}; +export default function getInitValue (type: Param$Type, { initValue, minValue }: Options = {}): ?mixed { switch (type) { case 'Balance': case 'BlockNumber': - case 'u32': + case 'Index': + case 'SessionKey': case 'u64': + case 'PropIndex': + case 'ReferendumIndex': + case 'u32': + case 'VoteIndex': return new BN(initValue || minValue || 0); case 'bool': diff --git a/packages/ui-app/src/Params/typeToText.js b/packages/ui-app/src/Params/typeToText.js index b4e03b4383..ba65727a43 100644 --- a/packages/ui-app/src/Params/typeToText.js +++ b/packages/ui-app/src/Params/typeToText.js @@ -3,12 +3,17 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { Param$Type, Param$TypeArray } from '@polkadot/primitives/param'; +import type { Param$Types } from '@polkadot/params/types'; -export default function typeToText (type: Param$Type | Param$TypeArray): string { - if (Array.isArray(type)) { - return `Array<${type.map(typeToText).join(', ')}>`; +export default function typeToText (type: Param$Types): string { + if (!Array.isArray(type)) { + return type; } - return type; + // $FlowFixMe hate doing this, but it _looks_ ok + const text = type.map(typeToText).join(', '); + + return type.length !== 1 + ? `(${text})` + : `Array<${text}>`; } diff --git a/packages/ui-app/src/Params/types.js b/packages/ui-app/src/Params/types.js index 9fbadad1ad..72797cb105 100644 --- a/packages/ui-app/src/Params/types.js +++ b/packages/ui-app/src/Params/types.js @@ -3,7 +3,7 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { Param, Param$Type } from '@polkadot/primitives/param'; +import type { Param$Type, Param$Types } from '@polkadot/params/types'; import type { BareProps } from '../types'; export type RawParam = { @@ -15,17 +15,27 @@ export type RawParams = Array; export type BaseProps = BareProps & { onChange: (index: number, value: RawParam) => void, - value: Param + value: { + name: string, + options?: { + initValue?: mixed, + minValue?: mixed, + maxValue?: mixed + }, + type: Param$Types + } }; export type Props = BaseProps & { + isDisabled?: boolean, isError?: boolean, index: number, - label: string + label: string, + withLabel?: boolean }; export type Size = 'full' | 'large' | 'medium' | 'small'; -export type ComponentMap = $Shape<{ +export type ComponentMap = { [Param$Type]: React$ComponentType<*> -}>; +}; diff --git a/packages/ui-app/src/Params/valueToText.js b/packages/ui-app/src/Params/valueToText.js new file mode 100644 index 0000000000..85904d1a45 --- /dev/null +++ b/packages/ui-app/src/Params/valueToText.js @@ -0,0 +1,54 @@ +// Copyright 2017-2018 Jaco Greeff +// This software may be modified and distributed under the terms +// of the ISC license. See the LICENSE file for details. +// @flow + +import type BN from 'bn.js'; +import type { Param$Types } from '@polkadot/params/types'; + +// import IdentityIcon from '@polkadot/ui-react/IdentityIcon'; +import numberFormat from '@polkadot/ui-react-rx/util/numberFormat'; +import addressEncode from '@polkadot/util-keyring/address/encode'; +import u8aToHexShort from '@polkadot/util/u8a/toHexShort'; +import isBn from '@polkadot/util/is/bn'; +import isU8a from '@polkadot/util/is/u8a'; + +// flowlint-next-line unclear-type:off +export default function valueToText (type: Param$Types, value: any): string { + if (type === 'bool') { + return value ? 'Yes' : 'No'; + } + + if (!value) { + return 'unknown'; + } + + if (Array.isArray(type)) { + if (value.length === 0) { + return 'empty'; + } + + const values = type.map((_type, index) => + // $FlowFixMe hate doing this, but it _looks_ ok + valueToText(_type, value[index]) + ).join(', '); + + return type.length === 1 + ? `(${values})` + : values; + } + + if (type === 'AccountId') { + return addressEncode((value: Uint8Array)); + } + + if (isU8a(value)) { + return u8aToHexShort((value: Uint8Array), 256); + } + + if (isBn(value)) { + return numberFormat((value: BN)); + } + + return value.toString(); +} diff --git a/packages/ui-app/src/Params/values.js b/packages/ui-app/src/Params/values.js index 4d91f51a26..98214c27f6 100644 --- a/packages/ui-app/src/Params/values.js +++ b/packages/ui-app/src/Params/values.js @@ -3,7 +3,7 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { Param, Params } from '@polkadot/primitives/param'; +import type { Param, Params } from '@polkadot/params/types'; import type { RawParam } from './types'; import isUndefined from '@polkadot/util/is/undefined'; @@ -14,8 +14,38 @@ export default function values (params: Params): Array { return Object .values(params) // $FlowFixMe yes, we are sure, the type is correct - .map((param: Param): RawParam => { - const value = getInitValue(param); + .map(({ type, options }: Param): RawParam => { + if (Array.isArray(type)) { + // console.error('Unable to determine default values for array/tuple type', type); + // + // return { + // isValid: false, + // value: void 0 + // }; + + if (type.length !== 1) { + console.error('Unable to determine default values for tuple type', type); + + return { + isValid: false, + value: void 0 + }; + } + + return type.reduce(({ isValid, value }, type) => { + // $FlowFixMe still not sure how to iterate through these + const avalue = getInitValue(type, {}); + + value.push(avalue); + + return { + isValid: isValid && !isUndefined(avalue), + value + }; + }, { isValid: true, value: [] }); + } + + const value = getInitValue(type, options); return { isValid: !isUndefined(value), @@ -23,3 +53,5 @@ export default function values (params: Params): Array { }; }); } + +// 0x050000000600000055555555550ae803000000000000 diff --git a/packages/ui-app/src/Password.js b/packages/ui-app/src/Password.js index 4155f39b5a..5bd996236d 100644 --- a/packages/ui-app/src/Password.js +++ b/packages/ui-app/src/Password.js @@ -18,7 +18,8 @@ type Props = BareProps & { label?: string, name?: string, onChange: (value: string) => void, - value: mixed + value: mixed, + withLabel?: boolean }; type State = { @@ -31,7 +32,7 @@ export default class Password extends React.PureComponent { }; render (): React$Node { - const { children, className, defaultValue, isDisabled, isError, label, name, onChange, style, value } = this.props; + const { children, className, defaultValue, isDisabled, isError, label, name, onChange, style, value, withLabel } = this.props; const { isVisible } = this.state; return ( @@ -51,6 +52,7 @@ export default class Password extends React.PureComponent { : 'password' } value={value} + withLabel={withLabel} >