2018-10-17 01:03:29 +02:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import UserPreferencedCurrencyDisplay from './user-preferenced-currency-display.component'
|
|
|
|
import { preferencesSelector } from '../../selectors'
|
|
|
|
import { ETH, PRIMARY, SECONDARY } from '../../constants/common'
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2018-10-26 10:26:43 +02:00
|
|
|
const { useNativeCurrencyAsPrimaryCurrency } = preferencesSelector(state)
|
2018-10-17 01:03:29 +02:00
|
|
|
|
|
|
|
return {
|
2018-10-26 10:26:43 +02:00
|
|
|
useNativeCurrencyAsPrimaryCurrency,
|
|
|
|
nativeCurrency: state.metamask.nativeCurrency,
|
2018-10-17 01:03:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
2018-10-26 10:26:43 +02:00
|
|
|
const { useNativeCurrencyAsPrimaryCurrency, nativeCurrency, ...restStateProps } = stateProps
|
2018-10-17 01:03:29 +02:00
|
|
|
const {
|
|
|
|
type,
|
|
|
|
numberOfDecimals: propsNumberOfDecimals,
|
|
|
|
ethNumberOfDecimals,
|
|
|
|
fiatNumberOfDecimals,
|
|
|
|
ethPrefix,
|
|
|
|
fiatPrefix,
|
|
|
|
prefix: propsPrefix,
|
|
|
|
...restOwnProps
|
|
|
|
} = ownProps
|
|
|
|
|
|
|
|
let currency, numberOfDecimals, prefix
|
|
|
|
|
2018-10-26 10:26:43 +02:00
|
|
|
if (type === PRIMARY && useNativeCurrencyAsPrimaryCurrency ||
|
|
|
|
type === SECONDARY && !useNativeCurrencyAsPrimaryCurrency) {
|
2018-10-17 01:03:29 +02:00
|
|
|
// Display ETH
|
2018-10-26 10:26:43 +02:00
|
|
|
currency = nativeCurrency || ETH
|
2018-10-17 01:03:29 +02:00
|
|
|
numberOfDecimals = propsNumberOfDecimals || ethNumberOfDecimals || 6
|
|
|
|
prefix = propsPrefix || ethPrefix
|
2018-10-26 10:26:43 +02:00
|
|
|
} else if (type === SECONDARY && useNativeCurrencyAsPrimaryCurrency ||
|
|
|
|
type === PRIMARY && !useNativeCurrencyAsPrimaryCurrency) {
|
2018-10-17 01:03:29 +02:00
|
|
|
// Display Fiat
|
|
|
|
numberOfDecimals = propsNumberOfDecimals || fiatNumberOfDecimals || 2
|
|
|
|
prefix = propsPrefix || fiatPrefix
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...restStateProps,
|
|
|
|
...dispatchProps,
|
|
|
|
...restOwnProps,
|
2018-10-26 10:26:43 +02:00
|
|
|
nativeCurrency,
|
2018-10-17 01:03:29 +02:00
|
|
|
currency,
|
|
|
|
numberOfDecimals,
|
|
|
|
prefix,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, null, mergeProps)(UserPreferencedCurrencyDisplay)
|