* ui-react-app -> ui-app
* CopyButton, Input & Password components
* Convert all to use ui-app/{Input, Label}
* Change to PureComponent where we have onChange listeners
* Cleanup layouts
* Swap dropdown components, remove uselexx constructors
* Allow address/account forget
* Bump
* Searching with headers operational
* flex grow/shrink for icon + account add
* Fix balance & transaction display (account/address management)
* Adjust balance layout
* Equalise padding
97 lines
2.3 KiB
JavaScript
97 lines
2.3 KiB
JavaScript
// 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
|
|
|
|
// TODO: We have a lot shared between this and InputStorage
|
|
|
|
import type { Extrinsic, ExtrinsicSectionName } from '@polkadot/extrinsics/types';
|
|
import type { I18nProps } from '../types';
|
|
|
|
import './InputExtrinsic.css';
|
|
|
|
import React from 'react';
|
|
import map from '@polkadot/extrinsics-substrate';
|
|
|
|
import translate from '../translate';
|
|
import SelectMethod from './SelectMethod';
|
|
import SelectSection from './SelectSection';
|
|
import methodOptions from './options/method';
|
|
|
|
type Props = I18nProps & {
|
|
defaultValue: Extrinsic,
|
|
isError?: boolean,
|
|
isPrivate?: boolean,
|
|
labelMethod?: string,
|
|
labelSection?: string,
|
|
onChange: (value: Extrinsic) => void
|
|
};
|
|
|
|
type State = {
|
|
value: Extrinsic
|
|
};
|
|
|
|
class InputExtrinsic extends React.PureComponent<Props, State> {
|
|
state: State;
|
|
|
|
constructor (props: Props) {
|
|
super(props);
|
|
|
|
this.state = {
|
|
value: this.props.defaultValue
|
|
};
|
|
}
|
|
|
|
render (): React$Node {
|
|
const { className, isPrivate = false, labelMethod, labelSection, style } = this.props;
|
|
const { value } = this.state;
|
|
const type = isPrivate ? 'private' : 'public';
|
|
|
|
return (
|
|
<div
|
|
className={['ui--DropdownLinked', 'ui--row', className].join(' ')}
|
|
style={style}
|
|
>
|
|
<SelectSection
|
|
className='small'
|
|
label={labelSection}
|
|
onChange={this.onSectionChange}
|
|
type={type}
|
|
value={value}
|
|
/>
|
|
<SelectMethod
|
|
className='large'
|
|
label={labelMethod}
|
|
onChange={this.onKeyChange}
|
|
value={value}
|
|
type={type}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
onKeyChange = (value: Extrinsic): void => {
|
|
const { onChange } = this.props;
|
|
|
|
this.setState({ value }, () =>
|
|
onChange(value)
|
|
);
|
|
}
|
|
|
|
onSectionChange = (section: ExtrinsicSectionName): void => {
|
|
const { isPrivate = false } = this.props;
|
|
|
|
if (this.state.value.section === section) {
|
|
return;
|
|
}
|
|
|
|
const type = isPrivate ? 'private' : 'public';
|
|
const options = methodOptions(section, type);
|
|
const value = map[section].methods[type][options[0].value];
|
|
|
|
this.onKeyChange(value);
|
|
}
|
|
}
|
|
|
|
export default translate(InputExtrinsic);
|