2018-08-31 21:36:07 +02:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import classnames from 'classnames'
|
|
|
|
import TransactionBreakdownRow from './transaction-breakdown-row'
|
|
|
|
import Card from '../card'
|
|
|
|
import CurrencyDisplay from '../currency-display'
|
2018-10-17 01:03:29 +02:00
|
|
|
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display'
|
2018-08-31 21:36:07 +02:00
|
|
|
import HexToDecimal from '../hex-to-decimal'
|
2018-10-26 10:26:43 +02:00
|
|
|
import { GWEI, PRIMARY, SECONDARY } from '../../constants/common'
|
2018-08-31 21:36:07 +02:00
|
|
|
import { getHexGasTotal } from '../../helpers/confirm-transaction/util'
|
2018-09-07 22:59:05 +02:00
|
|
|
import { sumHexes } from '../../helpers/transactions.util'
|
2018-08-31 21:36:07 +02:00
|
|
|
|
|
|
|
export default class TransactionBreakdown extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
transaction: PropTypes.object,
|
|
|
|
className: PropTypes.string,
|
2018-10-26 10:26:43 +02:00
|
|
|
nativeCurrency: PropTypes.string.isRequired,
|
2018-08-31 21:36:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
transaction: {},
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { t } = this.context
|
2018-10-26 10:26:43 +02:00
|
|
|
const { transaction, className, nativeCurrency } = this.props
|
2018-10-16 00:00:47 +02:00
|
|
|
const { txParams: { gas, gasPrice, value } = {}, txReceipt: { gasUsed } = {} } = transaction
|
|
|
|
|
|
|
|
const gasLimit = typeof gasUsed === 'string' ? gasUsed : gas
|
|
|
|
|
|
|
|
const hexGasTotal = getHexGasTotal({ gasLimit, gasPrice })
|
2018-09-07 22:59:05 +02:00
|
|
|
const totalInHex = sumHexes(hexGasTotal, value)
|
2018-08-31 21:36:07 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classnames('transaction-breakdown', className)}>
|
|
|
|
<Card
|
|
|
|
title={t('transaction')}
|
|
|
|
className="transaction-breakdown__card"
|
|
|
|
>
|
|
|
|
<TransactionBreakdownRow title={t('amount')}>
|
2018-10-17 01:03:29 +02:00
|
|
|
<UserPreferencedCurrencyDisplay
|
2018-08-31 21:36:07 +02:00
|
|
|
className="transaction-breakdown__value"
|
2018-10-17 01:03:29 +02:00
|
|
|
type={PRIMARY}
|
2018-08-31 21:36:07 +02:00
|
|
|
value={value}
|
|
|
|
/>
|
|
|
|
</TransactionBreakdownRow>
|
|
|
|
<TransactionBreakdownRow
|
|
|
|
title={`${t('gasLimit')} (${t('units')})`}
|
|
|
|
className="transaction-breakdown__row-title"
|
|
|
|
>
|
|
|
|
<HexToDecimal
|
|
|
|
className="transaction-breakdown__value"
|
|
|
|
value={gas}
|
|
|
|
/>
|
|
|
|
</TransactionBreakdownRow>
|
2018-10-16 00:00:47 +02:00
|
|
|
{
|
|
|
|
typeof gasUsed === 'string' && (
|
|
|
|
<TransactionBreakdownRow
|
|
|
|
title={`${t('gasUsed')} (${t('units')})`}
|
|
|
|
className="transaction-breakdown__row-title"
|
|
|
|
>
|
|
|
|
<HexToDecimal
|
|
|
|
className="transaction-breakdown__value"
|
|
|
|
value={gasUsed}
|
|
|
|
/>
|
|
|
|
</TransactionBreakdownRow>
|
|
|
|
)
|
|
|
|
}
|
2018-08-31 21:36:07 +02:00
|
|
|
<TransactionBreakdownRow title={t('gasPrice')}>
|
|
|
|
<CurrencyDisplay
|
|
|
|
className="transaction-breakdown__value"
|
2018-10-26 10:26:43 +02:00
|
|
|
currency={nativeCurrency}
|
2018-08-31 21:36:07 +02:00
|
|
|
denomination={GWEI}
|
|
|
|
value={gasPrice}
|
|
|
|
hideLabel
|
|
|
|
/>
|
|
|
|
</TransactionBreakdownRow>
|
|
|
|
<TransactionBreakdownRow title={t('total')}>
|
|
|
|
<div>
|
2018-10-17 01:03:29 +02:00
|
|
|
<UserPreferencedCurrencyDisplay
|
2018-08-31 21:36:07 +02:00
|
|
|
className="transaction-breakdown__value transaction-breakdown__value--eth-total"
|
2018-10-17 01:03:29 +02:00
|
|
|
type={PRIMARY}
|
2018-08-31 21:36:07 +02:00
|
|
|
value={totalInHex}
|
|
|
|
/>
|
2018-10-17 01:03:29 +02:00
|
|
|
<UserPreferencedCurrencyDisplay
|
2018-08-31 21:36:07 +02:00
|
|
|
className="transaction-breakdown__value"
|
2018-10-17 01:03:29 +02:00
|
|
|
type={SECONDARY}
|
2018-08-31 21:36:07 +02:00
|
|
|
value={totalInHex}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</TransactionBreakdownRow>
|
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|