1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00
metamask-extension/development/selector.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-11-25 14:32:09 +01:00
import PropTypes from 'prop-types'
import React, {Component} from 'react'
2016-07-01 03:22:48 +02:00
2019-11-25 14:32:09 +01:00
export default class Selector extends Component {
state = {}
2016-07-01 03:22:48 +02:00
2019-11-25 14:32:09 +01:00
render () {
const {
states,
selectedKey,
actions,
store,
modifyBackgroundConnection,
backGroundConnectionModifiers,
} = this.props
const selected = this.state.selected || selectedKey
2016-07-01 03:22:48 +02:00
2019-11-25 14:32:09 +01:00
return (
<select
style={{ margin: '20px 20px 0px' }}
value={selected}
onChange={(event) => {
const selectedKey = event.target.value
const backgroundConnectionModifier = backGroundConnectionModifiers[selectedKey]
modifyBackgroundConnection(backgroundConnectionModifier || {})
store.dispatch(actions.update(selectedKey))
this.setState({ selected: selectedKey })
}}
>
{Object.keys(states).map((stateName, index) => {
return (
<option key={index} value={stateName}>
{stateName}
</option>
)
})}
</select>
)
}
}
2016-07-01 03:22:48 +02:00
2019-11-25 14:32:09 +01:00
Selector.propTypes = {
states: PropTypes.object.isRequired,
selectedKey: PropTypes.string.isRequired,
actions: PropTypes.object.isRequired,
store: PropTypes.object.isRequired,
modifyBackgroundConnection: PropTypes.func.isRequired,
backGroundConnectionModifiers: PropTypes.object.isRequired,
2016-07-01 03:22:48 +02:00
}