1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 19:10:22 +01:00
metamask-extension/ui/app/components/transaction-breakdown/transaction-breakdown.component.js

101 lines
3.3 KiB
JavaScript
Raw Normal View History

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'
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display'
2018-08-31 21:36:07 +02:00
import HexToDecimal from '../hex-to-decimal'
import { GWEI, PRIMARY, SECONDARY } from '../../constants/common'
2018-08-31 21:36:07 +02:00
import { getHexGasTotal } from '../../helpers/confirm-transaction/util'
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,
nativeCurrency: PropTypes.string.isRequired,
2018-08-31 21:36:07 +02:00
}
static defaultProps = {
transaction: {},
}
render () {
const { t } = this.context
const { transaction, className, nativeCurrency } = 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)
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')}>
<UserPreferencedCurrencyDisplay
2018-08-31 21:36:07 +02:00
className="transaction-breakdown__value"
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>
{
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"
currency={nativeCurrency}
2018-08-31 21:36:07 +02:00
denomination={GWEI}
value={gasPrice}
hideLabel
/>
</TransactionBreakdownRow>
<TransactionBreakdownRow title={t('total')}>
<div>
<UserPreferencedCurrencyDisplay
2018-08-31 21:36:07 +02:00
className="transaction-breakdown__value transaction-breakdown__value--eth-total"
type={PRIMARY}
2018-08-31 21:36:07 +02:00
value={totalInHex}
/>
<UserPreferencedCurrencyDisplay
2018-08-31 21:36:07 +02:00
className="transaction-breakdown__value"
type={SECONDARY}
2018-08-31 21:36:07 +02:00
value={totalInHex}
/>
</div>
</TransactionBreakdownRow>
</Card>
</div>
)
}
}