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

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

  const toCurrency = currency || 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)