2017-08-25 18:18:52 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2017-08-29 15:55:11 +02:00
|
|
|
const InputNumber = require('../input-number.js')
|
2017-08-25 21:20:23 +02:00
|
|
|
const findDOMNode = require('react-dom').findDOMNode
|
2017-08-25 18:18:52 +02:00
|
|
|
|
|
|
|
module.exports = GasTooltip
|
|
|
|
|
|
|
|
inherits(GasTooltip, Component)
|
|
|
|
function GasTooltip () {
|
|
|
|
Component.call(this)
|
|
|
|
this.state = {
|
|
|
|
gasLimit: 0,
|
|
|
|
gasPrice: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateGasPrice = this.updateGasPrice.bind(this);
|
|
|
|
this.updateGasLimit = this.updateGasLimit.bind(this);
|
2017-08-28 19:39:05 +02:00
|
|
|
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 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),
|
|
|
|
gasPrice: (newPrice * 1000000000).toString(16)
|
|
|
|
})
|
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),
|
|
|
|
gasPrice: (gasPrice * 1000000000).toString(16)
|
|
|
|
})
|
2017-08-25 18:18:52 +02:00
|
|
|
}
|
|
|
|
|
2017-08-28 19:39:05 +02:00
|
|
|
GasTooltip.prototype.onClose = function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
|
|
|
|
2017-08-25 18:18:52 +02:00
|
|
|
GasTooltip.prototype.render = function () {
|
2017-08-28 19:39:05 +02:00
|
|
|
const { position, title, children, className } = this.props
|
2017-08-25 18:18:52 +02:00
|
|
|
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', {
|
|
|
|
onClick: this.onClose
|
|
|
|
}),
|
|
|
|
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']),
|
|
|
|
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-08-28 19:39:05 +02:00
|
|
|
initValue: gasPrice,
|
|
|
|
onChange: (newPrice) => this.updateGasPrice(newPrice),
|
|
|
|
}),
|
|
|
|
h('div.gas-tooltip-input-label', {
|
|
|
|
style: {
|
|
|
|
'marginTop': '81px',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h('span.gas-tooltip-label', {}, ['Gas Limit']),
|
|
|
|
h('i.fa.fa-info-circle')
|
|
|
|
]),
|
|
|
|
h(InputNumber, {
|
|
|
|
unitLabel: 'UNITS',
|
|
|
|
step: 1,
|
|
|
|
min: 0,
|
|
|
|
placeholder: '0',
|
|
|
|
initValue: gasLimit,
|
|
|
|
onChange: (newLimit) => this.updateGasLimit(newLimit),
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
h('div.gas-tooltip-arrow', {}),
|
|
|
|
])
|
|
|
|
])
|
2017-08-25 21:20:23 +02:00
|
|
|
}
|
|
|
|
|