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-fee-display.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-08-29 16:09:07 +02:00
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
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 {
activeCurrency,
2017-08-29 16:09:07 +02:00
conversionRate,
gas,
gasPrice,
blockGasLimit,
} = this.props
switch (activeCurrency) {
case 'USD':
return h(USDFeeDisplay, {
activeCurrency,
conversionRate,
gas,
gasPrice,
blockGasLimit,
})
case 'ETH':
return h(EthFeeDisplay, {
activeCurrency,
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()),
h('div.token-gas__symbol', activeCurrency),
2017-09-13 10:25:39 +02:00
])
2017-08-29 16:09:07 +02:00
}
}