2017-08-25 18:18:52 +02:00
|
|
|
const Component = require('react').Component
|
2018-03-29 17:00:44 +02:00
|
|
|
const PropTypes = require('prop-types')
|
2017-08-25 18:18:52 +02:00
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2017-08-29 15:55:11 +02:00
|
|
|
const InputNumber = require('../input-number.js')
|
2018-03-29 17:00:44 +02:00
|
|
|
const connect = require('react-redux').connect
|
|
|
|
|
|
|
|
GasTooltip.contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
}
|
2017-08-25 18:18:52 +02:00
|
|
|
|
2018-03-22 01:41:47 +01:00
|
|
|
module.exports = connect()(GasTooltip)
|
2017-08-25 18:18:52 +02:00
|
|
|
|
2018-03-29 17:00:44 +02:00
|
|
|
|
2017-08-25 18:18:52 +02:00
|
|
|
inherits(GasTooltip, Component)
|
|
|
|
function GasTooltip () {
|
|
|
|
Component.call(this)
|
|
|
|
this.state = {
|
|
|
|
gasLimit: 0,
|
|
|
|
gasPrice: 0,
|
|
|
|
}
|
|
|
|
|
2017-08-29 16:50:48 +02:00
|
|
|
this.updateGasPrice = this.updateGasPrice.bind(this)
|
|
|
|
this.updateGasLimit = this.updateGasLimit.bind(this)
|
|
|
|
this.onClose = this.onClose.bind(this)
|
2017-08-25 18:18:52 +02:00
|
|
|
}
|
|
|
|
|
2017-08-26 01:23:30 +02:00
|
|
|
GasTooltip.prototype.componentWillMount = function () {
|
|
|
|
const { gasPrice = 0, gasLimit = 0} = this.props
|
2017-08-29 16:50:48 +02:00
|
|
|
|
2017-08-29 14:51:31 +02:00
|
|
|
this.setState({
|
|
|
|
gasPrice: parseInt(gasPrice, 16) / 1000000000,
|
|
|
|
gasLimit: parseInt(gasLimit, 16),
|
|
|
|
})
|
2017-08-26 01:23:30 +02:00
|
|
|
}
|
|
|
|
|
2017-08-25 18:18:52 +02:00
|
|
|
GasTooltip.prototype.updateGasPrice = function (newPrice) {
|
|
|
|
const { onFeeChange } = this.props
|
|
|
|
const { gasLimit } = this.state
|
|
|
|
|
|
|
|
this.setState({ gasPrice: newPrice })
|
2017-08-29 14:51:31 +02:00
|
|
|
onFeeChange({
|
|
|
|
gasLimit: gasLimit.toString(16),
|
2017-08-29 16:50:48 +02:00
|
|
|
gasPrice: (newPrice * 1000000000).toString(16),
|
2017-08-29 14:51:31 +02:00
|
|
|
})
|
2017-08-25 18:18:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GasTooltip.prototype.updateGasLimit = function (newLimit) {
|
|
|
|
const { onFeeChange } = this.props
|
|
|
|
const { gasPrice } = this.state
|
|
|
|
|
|
|
|
this.setState({ gasLimit: newLimit })
|
2017-08-29 14:51:31 +02:00
|
|
|
onFeeChange({
|
|
|
|
gasLimit: newLimit.toString(16),
|
2017-08-29 16:50:48 +02:00
|
|
|
gasPrice: (gasPrice * 1000000000).toString(16),
|
2017-08-29 14:51:31 +02:00
|
|
|
})
|
2017-08-25 18:18:52 +02:00
|
|
|
}
|
|
|
|
|
2017-08-28 19:39:05 +02:00
|
|
|
GasTooltip.prototype.onClose = function (e) {
|
2017-08-29 16:50:48 +02:00
|
|
|
e.stopPropagation()
|
|
|
|
this.props.onClose()
|
2017-08-28 19:39:05 +02:00
|
|
|
}
|
|
|
|
|
2017-08-25 18:18:52 +02:00
|
|
|
GasTooltip.prototype.render = function () {
|
|
|
|
const { gasPrice, gasLimit } = this.state
|
2017-08-25 21:20:23 +02:00
|
|
|
|
2017-08-29 20:39:56 +02:00
|
|
|
return h('div.gas-tooltip', {}, [
|
2017-08-28 19:39:05 +02:00
|
|
|
h('div.gas-tooltip-close-area', {
|
2017-08-29 16:50:48 +02:00
|
|
|
onClick: this.onClose,
|
2017-08-28 19:39:05 +02:00
|
|
|
}),
|
|
|
|
h('div.customize-gas-tooltip-container', {}, [
|
|
|
|
h('div.customize-gas-tooltip', {}, [
|
|
|
|
h('div.gas-tooltip-header.gas-tooltip-label', {}, ['Customize Gas']),
|
|
|
|
h('div.gas-tooltip-input-label', {}, [
|
|
|
|
h('span.gas-tooltip-label', {}, ['Gas Price']),
|
2017-08-29 16:50:48 +02:00
|
|
|
h('i.fa.fa-info-circle'),
|
2017-08-25 18:18:52 +02:00
|
|
|
]),
|
2017-08-28 19:39:05 +02:00
|
|
|
h(InputNumber, {
|
|
|
|
unitLabel: 'GWEI',
|
2017-08-29 14:51:31 +02:00
|
|
|
step: 1,
|
|
|
|
min: 0,
|
|
|
|
placeholder: '0',
|
2017-10-13 22:19:22 +02:00
|
|
|
value: gasPrice,
|
2017-08-29 16:50:48 +02:00
|
|
|
onChange: (newPrice) => this.updateGasPrice(newPrice),
|
2017-08-28 19:39:05 +02:00
|
|
|
}),
|
|
|
|
h('div.gas-tooltip-input-label', {
|
|
|
|
style: {
|
|
|
|
'marginTop': '81px',
|
|
|
|
},
|
|
|
|
}, [
|
2018-03-29 17:00:44 +02:00
|
|
|
h('span.gas-tooltip-label', {}, [this.context.t('gasLimit')]),
|
2017-08-29 16:50:48 +02:00
|
|
|
h('i.fa.fa-info-circle'),
|
2017-08-28 19:39:05 +02:00
|
|
|
]),
|
|
|
|
h(InputNumber, {
|
|
|
|
unitLabel: 'UNITS',
|
|
|
|
step: 1,
|
|
|
|
min: 0,
|
|
|
|
placeholder: '0',
|
2017-10-13 22:19:22 +02:00
|
|
|
value: gasLimit,
|
2017-08-29 16:50:48 +02:00
|
|
|
onChange: (newLimit) => this.updateGasLimit(newLimit),
|
2017-08-28 19:39:05 +02:00
|
|
|
}),
|
|
|
|
]),
|
|
|
|
h('div.gas-tooltip-arrow', {}),
|
2017-08-29 16:50:48 +02:00
|
|
|
]),
|
2017-08-28 19:39:05 +02:00
|
|
|
])
|
2017-08-25 21:20:23 +02:00
|
|
|
}
|