2018-08-16 04:18:01 +02:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import CurrencyDisplay from './currency-display.component'
|
|
|
|
import { getValueFromWeiHex, formatCurrency } from '../../helpers/confirm-transaction/util'
|
|
|
|
|
2018-10-17 01:03:29 +02:00
|
|
|
const mapStateToProps = state => {
|
2018-10-30 12:15:38 +01:00
|
|
|
const { metamask: { nativeCurrency, currentCurrency, conversionRate } } = state
|
2018-08-16 04:18:01 +02:00
|
|
|
|
2018-10-17 01:03:29 +02:00
|
|
|
return {
|
|
|
|
currentCurrency,
|
|
|
|
conversionRate,
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency,
|
2018-10-17 01:03:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
2018-10-30 12:15:38 +01:00
|
|
|
const { nativeCurrency, currentCurrency, conversionRate, ...restStateProps } = stateProps
|
2018-10-17 01:03:29 +02:00
|
|
|
const {
|
|
|
|
value,
|
|
|
|
numberOfDecimals = 2,
|
|
|
|
currency,
|
|
|
|
denomination,
|
|
|
|
hideLabel,
|
|
|
|
...restOwnProps
|
|
|
|
} = ownProps
|
|
|
|
|
2018-08-24 01:44:38 +02:00
|
|
|
const toCurrency = currency || currentCurrency
|
2018-08-31 21:14:06 +02:00
|
|
|
const convertedValue = getValueFromWeiHex({
|
2018-10-30 12:15:38 +01:00
|
|
|
value, fromCurrency: nativeCurrency, toCurrency, conversionRate, numberOfDecimals, toDenomination: denomination,
|
2018-08-31 21:14:06 +02:00
|
|
|
})
|
2018-10-21 13:12:40 +02:00
|
|
|
const displayValue = formatCurrency(convertedValue, toCurrency)
|
|
|
|
const suffix = hideLabel ? undefined : toCurrency.toUpperCase()
|
2018-08-16 04:18:01 +02:00
|
|
|
|
|
|
|
return {
|
2018-10-17 01:03:29 +02:00
|
|
|
...restStateProps,
|
|
|
|
...dispatchProps,
|
|
|
|
...restOwnProps,
|
2018-08-16 04:18:01 +02:00
|
|
|
displayValue,
|
2018-10-21 13:12:40 +02:00
|
|
|
suffix,
|
2018-08-16 04:18:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-17 01:03:29 +02:00
|
|
|
export default connect(mapStateToProps, null, mergeProps)(CurrencyDisplay)
|