aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/currency-display/currency-display.container.js
blob: b36bba52ad70d07f1e69291bdc0465999886edda (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { connect } from 'react-redux'
import CurrencyDisplay from './currency-display.component'
import { getValueFromWeiHex, formatCurrency } from '../../helpers/confirm-transaction/util'
import { ETH } from '../../constants/common'

const mapStateToProps = (state, ownProps) => {
  const { value, numberOfDecimals = 2, currency } = ownProps
  const { metamask: { currentCurrency, conversionRate } } = state

  const toCurrency = currency === ETH ? ETH : currentCurrency
  const convertedValue = getValueFromWeiHex({ value, toCurrency, conversionRate, numberOfDecimals })
  const formattedValue = formatCurrency(convertedValue, toCurrency)
  const displayValue = `${formattedValue} ${toCurrency.toUpperCase()}`

  return {
    displayValue,
  }
}

export default connect(mapStateToProps)(CurrencyDisplay)