1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +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'
2019-12-03 21:50:55 +01:00
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,
updateState,
2019-11-25 14:32:09 +01:00
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(updateState(selectedKey))
2019-11-25 14:32:09 +01:00
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,
updateState: PropTypes.func.isRequired,
2019-11-25 14:32:09 +01:00
store: PropTypes.object.isRequired,
modifyBackgroundConnection: PropTypes.func.isRequired,
backGroundConnectionModifiers: PropTypes.object.isRequired,
2016-07-01 03:22:48 +02:00
}