Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import CurrencyDisplay from '../currency-display'
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display'
import HexToDecimal from '../hex-to-decimal'
import { GWEI, PRIMARY, SECONDARY } from '../../constants/common'
import { getHexGasTotal } from '../../helpers/confirm-transaction/util'
import { sumHexes } from '../../helpers/transactions.util'

export default class TransactionBreakdown extends PureComponent {
static contextTypes = {
Expand All @@ -19,6 +17,11 @@ export default class TransactionBreakdown extends PureComponent {
className: PropTypes.string,
nativeCurrency: PropTypes.string.isRequired,
showFiat: PropTypes.bool,
gas: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
gasPrice: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
gasUsed: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
totalInHex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
}

static defaultProps = {
Expand All @@ -28,13 +31,7 @@ export default class TransactionBreakdown extends PureComponent {

render () {
const { t } = this.context
const { transaction, className, nativeCurrency, showFiat } = this.props
const { txParams: { gas, gasPrice, value } = {}, txReceipt: { gasUsed } = {} } = transaction

const gasLimit = typeof gasUsed === 'string' ? gasUsed : gas

const hexGasTotal = getHexGasTotal({ gasLimit, gasPrice })
const totalInHex = sumHexes(hexGasTotal, value)
const { gas, gasPrice, value, className, nativeCurrency, showFiat, totalInHex, gasUsed } = this.props

return (
<div className={classnames('transaction-breakdown', className)}>
Expand All @@ -52,10 +49,13 @@ export default class TransactionBreakdown extends PureComponent {
title={`${t('gasLimit')} (${t('units')})`}
className="transaction-breakdown__row-title"
>
<HexToDecimal
className="transaction-breakdown__value"
value={gas}
/>
{typeof gas !== 'undefined'
? <HexToDecimal
className="transaction-breakdown__value"
value={gas}
/>
: '?'
}
</TransactionBreakdownRow>
{
typeof gasUsed === 'string' && (
Expand All @@ -71,13 +71,16 @@ export default class TransactionBreakdown extends PureComponent {
)
}
<TransactionBreakdownRow title={t('gasPrice')}>
<CurrencyDisplay
className="transaction-breakdown__value"
currency={nativeCurrency}
denomination={GWEI}
value={gasPrice}
hideLabel
/>
{typeof gasPrice !== 'undefined'
? <CurrencyDisplay
className="transaction-breakdown__value"
currency={nativeCurrency}
denomination={GWEI}
value={gasPrice}
hideLabel
/>
: '?'
}
</TransactionBreakdownRow>
<TransactionBreakdownRow title={t('total')}>
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import { connect } from 'react-redux'
import TransactionBreakdown from './transaction-breakdown.component'
import {getIsMainnet, getNativeCurrency, preferencesSelector} from '../../selectors'
import { getHexGasTotal } from '../../helpers/confirm-transaction/util'
import { sumHexes } from '../../helpers/transactions.util'

const mapStateToProps = (state) => {
const mapStateToProps = (state, ownProps) => {
const { transaction } = ownProps
const { txParams: { gas, gasPrice, value } = {}, txReceipt: { gasUsed } = {} } = transaction
const { showFiatInTestnets } = preferencesSelector(state)
const isMainnet = getIsMainnet(state)

const gasLimit = typeof gasUsed === 'string' ? gasUsed : gas

const hexGasTotal = gasLimit && gasPrice && getHexGasTotal({ gasLimit, gasPrice }) || '0x0'
const totalInHex = sumHexes(hexGasTotal, value)

return {
nativeCurrency: getNativeCurrency(state),
showFiat: (isMainnet || !!showFiatInTestnets),
totalInHex,
gas,
gasPrice,
value,
gasUsed,
}
}

Expand Down