aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/transaction-breakdown/transaction-breakdown.container.js
blob: 3e85b9e237f5381076f90656ffbd42f9280b073d (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
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, 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,
  }
}

export default connect(mapStateToProps)(TransactionBreakdown)