Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Feature) Select input for Boolean type for contract type acc #229

Merged
merged 13 commits into from
Dec 26, 2018
77 changes: 64 additions & 13 deletions old-ui/app/components/send/send-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class SendTransactionField extends Component {
this.state = {
val: props.defaultValue,
}
this.timerID = null
}

static propTypes = {
Expand All @@ -40,18 +39,57 @@ class SendTransactionField extends Component {
placeholder={this.props.placeholder}
value={this.state.val}
disabled={this.props.disabled}
onChange={e => {
onChange={(e) => {
this.setState({
val: e.target.value,
})
this.props.onChange(e)
this.props.onChange(e.target.value)
}}
style={{ marginTop: '5px' }}
/>
)
}
}

class SendTransactionInputSelect extends Component {
constructor (props) {
super(props)
this.state = {
val: props.defaultValue,
}
}

static propTypes = {
defaultValue: PropTypes.string,
value: PropTypes.string,
onChange: PropTypes.func,
}

render () {
return (
<Select
clearable={false}
value={this.state.val}
options={[{
label: 'false',
value: 'false',
}, {
label: 'true',
value: 'true',
}]}
onChange={(opt) => {
this.setState({
val: opt.value,
})
this.props.onChange(opt.value)
}
}
style={{ marginTop: '5px' }}
/>
)
}
}

class SendTransactionScreen extends PersistentForm {
constructor (props) {
super(props)
Expand All @@ -71,6 +109,7 @@ class SendTransactionScreen extends PersistentForm {
copyDisabled: true,
}

this.timerID = null
PersistentForm.call(this)
}

Expand Down Expand Up @@ -174,16 +213,28 @@ class SendTransactionScreen extends PersistentForm {
/> : null}
</h3>
)
const field = (
<SendTransactionField
key={Math.random()}
ind={ind}
disabled={!isInput}
placeholder={params.type}
defaultValue={defaultValue}
onChange={e => isInput ? this.handleInputChange(e.target.value, params.type, ind) : null}
/>
)
let field
if (params.type === 'bool' && isInput) {
field = (
<SendTransactionInputSelect
key={Math.random()}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necesssary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, key prop is not necessary for inputs. Removed, thanks @fvictorio

ind={ind}
defaultValue={defaultValue}
onChange={val => this.handleInputChange(val, params.type, ind)}
/>
)
} else {
field = (
<SendTransactionField
key={Math.random()}
ind={ind}
disabled={!isInput}
placeholder={params.type}
defaultValue={defaultValue}
onChange={val => isInput ? this.handleInputChange(val, params.type, ind) : null}
/>
)
}
const fieldObj = (
<div key={`method_label_container_${ind}`}>
{label}
Expand Down