aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send/gas-tooltip.js
blob: 62cdc1cad54aa4f409e5a2a184dbd3bcf38841e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const Component = require('react').Component
const PropTypes = require('prop-types')
const h = require('react-hyperscript')
const inherits = require('util').inherits
const InputNumber = require('../input-number.js')
const connect = require('react-redux').connect

GasTooltip.contextTypes = {
  t: PropTypes.func,
}

module.exports = connect()(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)
  this.onClose = this.onClose.bind(this)
}

GasTooltip.prototype.componentWillMount = function () {
  const { gasPrice = 0, gasLimit = 0} = this.props

  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),
    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),
    gasPrice: (gasPrice * 1000000000).toString(16),
  })
}

GasTooltip.prototype.onClose = function (e) {
  e.stopPropagation()
  this.props.onClose()
}

GasTooltip.prototype.render = function () {
  const { gasPrice, gasLimit } = this.state

  return h('div.gas-tooltip', {}, [
    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'),
        ]),
        h(InputNumber, {
          unitLabel: 'GWEI',
          step: 1,
          min: 0,
          placeholder: '0',
          value: gasPrice,
          onChange: (newPrice) => this.updateGasPrice(newPrice),
        }),
        h('div.gas-tooltip-input-label', {
          style: {
            'marginTop': '81px',
          },
        }, [
          h('span.gas-tooltip-label', {}, [this.context.t('gasLimit')]),
          h('i.fa.fa-info-circle'),
        ]),
        h(InputNumber, {
          unitLabel: 'UNITS',
          step: 1,
          min: 0,
          placeholder: '0',
          value: gasLimit,
          onChange: (newLimit) => this.updateGasLimit(newLimit),
        }),
      ]),
      h('div.gas-tooltip-arrow', {}),
    ]),
  ])
}