1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 11:01:41 +01:00
metamask-extension/ui/app/components/send/gas-tooltip.js

101 lines
2.6 KiB
JavaScript
Raw Normal View History

const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const InputNumber = require('../input-number.js')
module.exports = GasTooltip
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)
}
GasTooltip.prototype.componentWillMount = function () {
const { gasPrice = 0, gasLimit = 0} = this.props
2017-08-29 16:50:48 +02:00
this.setState({
gasPrice: parseInt(gasPrice, 16) / 1000000000,
gasLimit: parseInt(gasLimit, 16),
})
}
GasTooltip.prototype.updateGasPrice = function (newPrice) {
const { onFeeChange } = this.props
const { gasLimit } = this.state
this.setState({ gasPrice: newPrice })
onFeeChange({
gasLimit: gasLimit.toString(16),
2017-08-29 16:50:48 +02:00
gasPrice: (newPrice * 1000000000).toString(16),
})
}
GasTooltip.prototype.updateGasLimit = function (newLimit) {
const { onFeeChange } = this.props
const { gasPrice } = this.state
this.setState({ gasLimit: newLimit })
onFeeChange({
gasLimit: newLimit.toString(16),
2017-08-29 16:50:48 +02:00
gasPrice: (gasPrice * 1000000000).toString(16),
})
}
GasTooltip.prototype.onClose = function (e) {
2017-08-29 16:50:48 +02:00
e.stopPropagation()
this.props.onClose()
}
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', {}, [
h('div.gas-tooltip-close-area', {
2017-08-29 16:50:48 +02:00
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']),
2017-08-29 16:50:48 +02:00
h('i.fa.fa-info-circle'),
]),
h(InputNumber, {
unitLabel: 'GWEI',
step: 1,
min: 0,
placeholder: '0',
initValue: gasPrice,
2017-08-29 16:50:48 +02:00
onChange: (newPrice) => this.updateGasPrice(newPrice),
}),
h('div.gas-tooltip-input-label', {
style: {
'marginTop': '81px',
},
}, [
h('span.gas-tooltip-label', {}, ['Gas Limit']),
2017-08-29 16:50:48 +02:00
h('i.fa.fa-info-circle'),
]),
h(InputNumber, {
unitLabel: 'UNITS',
step: 1,
min: 0,
placeholder: '0',
initValue: gasLimit,
2017-08-29 16:50:48 +02:00
onChange: (newLimit) => this.updateGasLimit(newLimit),
}),
]),
h('div.gas-tooltip-arrow', {}),
2017-08-29 16:50:48 +02:00
]),
])
2017-08-25 21:20:23 +02:00
}