aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/transaction-breakdown/transaction-breakdown.component.js
blob: 26dc4c15394b4ad2f1c9968f0a378f3941f5ac8f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import TransactionBreakdownRow from './transaction-breakdown-row'
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'

export default class TransactionBreakdown extends PureComponent {
  static contextTypes = {
    t: PropTypes.func,
  }

  static propTypes = {
    transaction: PropTypes.object,
    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 = {
    transaction: {},
    showFiat: true,
  }

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

    return (
      <div className={classnames('transaction-breakdown', className)}>
        <div className="transaction-breakdown__title">
          { t('transaction') }
        </div>
        <TransactionBreakdownRow title={t('amount')}>
          <UserPreferencedCurrencyDisplay
            className="transaction-breakdown__value"
            type={PRIMARY}
            value={value}
          />
        </TransactionBreakdownRow>
        <TransactionBreakdownRow
          title={`${t('gasLimit')} (${t('units')})`}
          className="transaction-breakdown__row-title"
        >
          {typeof gas !== 'undefined'
            ? <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>
          )
        }
        <TransactionBreakdownRow title={t('gasPrice')}>
          {typeof gasPrice !== 'undefined'
            ? <CurrencyDisplay
              className="transaction-breakdown__value"
              currency={nativeCurrency}
              denomination={GWEI}
              value={gasPrice}
              hideLabel
            />
            : '?'
          }
        </TransactionBreakdownRow>
        <TransactionBreakdownRow title={t('total')}>
          <div>
            <UserPreferencedCurrencyDisplay
              className="transaction-breakdown__value transaction-breakdown__value--eth-total"
              type={PRIMARY}
              value={totalInHex}
            />
            {
              showFiat && (
                <UserPreferencedCurrencyDisplay
                  className="transaction-breakdown__value"
                  type={SECONDARY}
                  value={totalInHex}
                />
              )
            }
          </div>
        </TransactionBreakdownRow>
      </div>
    )
  }
}