You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.7 KiB
103 lines
2.7 KiB
7 years ago
|
const Component = require('react').Component
|
||
|
const h = require('react-hyperscript')
|
||
|
const inherits = require('util').inherits
|
||
7 years ago
|
const InputNumber = require('../input-number.js')
|
||
7 years ago
|
const findDOMNode = require('react-dom').findDOMNode
|
||
7 years ago
|
|
||
|
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);
|
||
7 years ago
|
this.onClose = this.onClose.bind(this);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
GasTooltip.prototype.componentWillMount = function () {
|
||
|
const { gasPrice = 0, gasLimit = 0} = this.props
|
||
|
|
||
7 years ago
|
this.setState({
|
||
|
gasPrice: parseInt(gasPrice, 16) / 1000000000,
|
||
|
gasLimit: parseInt(gasLimit, 16),
|
||
|
})
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
GasTooltip.prototype.updateGasPrice = function (newPrice) {
|
||
|
const { onFeeChange } = this.props
|
||
|
const { gasLimit } = this.state
|
||
|
|
||
|
this.setState({ gasPrice: newPrice })
|
||
7 years ago
|
onFeeChange({
|
||
|
gasLimit: gasLimit.toString(16),
|
||
|
gasPrice: (newPrice * 1000000000).toString(16)
|
||
|
})
|
||
7 years ago
|
}
|
||
|
|
||
|
GasTooltip.prototype.updateGasLimit = function (newLimit) {
|
||
|
const { onFeeChange } = this.props
|
||
|
const { gasPrice } = this.state
|
||
|
|
||
|
this.setState({ gasLimit: newLimit })
|
||
7 years ago
|
onFeeChange({
|
||
|
gasLimit: newLimit.toString(16),
|
||
|
gasPrice: (gasPrice * 1000000000).toString(16)
|
||
|
})
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
GasTooltip.prototype.onClose = function (e) {
|
||
|
e.stopPropagation();
|
||
|
this.props.onClose();
|
||
|
}
|
||
|
|
||
7 years ago
|
GasTooltip.prototype.render = function () {
|
||
7 years ago
|
const { position, title, children, className } = this.props
|
||
7 years ago
|
const { gasPrice, gasLimit } = this.state
|
||
7 years ago
|
|
||
7 years ago
|
return h('div.gas-tooltip', {}, [
|
||
7 years ago
|
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')
|
||
7 years ago
|
]),
|
||
7 years ago
|
h(InputNumber, {
|
||
|
unitLabel: 'GWEI',
|
||
7 years ago
|
step: 1,
|
||
|
min: 0,
|
||
|
placeholder: '0',
|
||
7 years ago
|
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', {}),
|
||
|
])
|
||
|
])
|
||
7 years ago
|
}
|
||
|
|