2017-08-29 16:09:07 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2017-08-30 20:37:46 +02:00
|
|
|
const USDFeeDisplay = require('./usd-fee-display')
|
|
|
|
const EthFeeDisplay = require('./eth-fee-display')
|
2017-09-13 10:25:39 +02:00
|
|
|
const { getTxFeeBn, formatBalance, shortenBalance } = require('../../util')
|
2017-08-29 16:09:07 +02:00
|
|
|
|
|
|
|
module.exports = GasFeeDisplay
|
|
|
|
|
|
|
|
inherits(GasFeeDisplay, Component)
|
|
|
|
function GasFeeDisplay () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
2017-09-13 10:25:39 +02:00
|
|
|
GasFeeDisplay.prototype.getTokenValue = function () {
|
|
|
|
const {
|
|
|
|
tokenExchangeRate,
|
|
|
|
gas,
|
|
|
|
gasPrice,
|
|
|
|
blockGasLimit,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
const value = formatBalance(getTxFeeBn(gas, gasPrice, blockGasLimit), 6, true)
|
|
|
|
const [ethNumber] = value.split(' ')
|
|
|
|
|
|
|
|
return shortenBalance(Number(ethNumber) / tokenExchangeRate, 6)
|
|
|
|
}
|
|
|
|
|
2017-08-29 16:09:07 +02:00
|
|
|
GasFeeDisplay.prototype.render = function () {
|
|
|
|
const {
|
2017-09-13 19:57:15 +02:00
|
|
|
activeCurrency,
|
2017-08-29 16:09:07 +02:00
|
|
|
conversionRate,
|
|
|
|
gas,
|
|
|
|
gasPrice,
|
|
|
|
blockGasLimit,
|
|
|
|
} = this.props
|
|
|
|
|
2017-09-13 19:57:15 +02:00
|
|
|
switch (activeCurrency) {
|
2017-08-30 20:37:46 +02:00
|
|
|
case 'USD':
|
|
|
|
return h(USDFeeDisplay, {
|
2017-09-13 19:57:15 +02:00
|
|
|
activeCurrency,
|
2017-08-30 20:37:46 +02:00
|
|
|
conversionRate,
|
|
|
|
gas,
|
|
|
|
gasPrice,
|
|
|
|
blockGasLimit,
|
|
|
|
})
|
|
|
|
case 'ETH':
|
|
|
|
return h(EthFeeDisplay, {
|
2017-09-13 19:57:15 +02:00
|
|
|
activeCurrency,
|
2017-08-30 20:37:46 +02:00
|
|
|
conversionRate,
|
|
|
|
gas,
|
|
|
|
gasPrice,
|
|
|
|
blockGasLimit,
|
|
|
|
})
|
|
|
|
default:
|
2017-09-13 10:25:39 +02:00
|
|
|
return h('div.token-gas', [
|
|
|
|
h('div.token-gas__amount', this.getTokenValue()),
|
2017-09-13 19:57:15 +02:00
|
|
|
h('div.token-gas__symbol', activeCurrency),
|
2017-09-13 10:25:39 +02:00
|
|
|
])
|
2017-08-29 16:09:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|