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,
|
2018-11-20 01:06:34 +01:00
|
|
|
displayValue: propsDisplayValue,
|
|
|
|
suffix: propsSuffix,
|
2018-10-17 01:03:29 +02:00
|
|
|
...restOwnProps
|
|
|
|
} = ownProps
|
|
|
|
|
2018-08-24 01:44:38 +02:00
|
|
|
const toCurrency = currency || currentCurrency
|
2018-11-20 01:06:34 +01:00
|
|
|
|
|
|
|
const displayValue = propsDisplayValue || formatCurrency(
|
|
|
|
getValueFromWeiHex({
|
|
|
|
value,
|
|
|
|
fromCurrency: nativeCurrency,
|
|
|
|
toCurrency, conversionRate,
|
|
|
|
numberOfDecimals,
|
|
|
|
toDenomination: denomination,
|
|
|
|
}),
|
|
|
|
toCurrency
|
|
|
|
)
|
|
|
|
const suffix = propsSuffix || (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)
|