mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-24 11:01:41 +01:00
badebe017f
* Add UnitInput component * Add CurrencyInput component * Add UserPreferencedCurrencyInput component * Add UserPreferencedCurrencyDisplay component * Add updatePreferences action * Add styles for CurrencyInput, CurrencyDisplay, and UnitInput * Update SettingsTab page with Primary Currency toggle * Refactor currency displays and inputs to use UserPreferenced displays and inputs * Add TokenInput component * Add UserPreferencedTokenInput component * Use TokenInput in the send screen * Fix unit tests * Fix e2e and integration tests * Remove send/CurrencyDisplay component * Replace diamond unicode character with Eth logo. Fix typos
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
import { connect } from 'react-redux'
|
|
import CurrencyDisplay from './currency-display.component'
|
|
import { getValueFromWeiHex, formatCurrency } from '../../helpers/confirm-transaction/util'
|
|
|
|
const mapStateToProps = state => {
|
|
const { metamask: { currentCurrency, conversionRate } } = state
|
|
|
|
return {
|
|
currentCurrency,
|
|
conversionRate,
|
|
}
|
|
}
|
|
|
|
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
|
const { currentCurrency, conversionRate, ...restStateProps } = stateProps
|
|
const {
|
|
value,
|
|
numberOfDecimals = 2,
|
|
currency,
|
|
denomination,
|
|
hideLabel,
|
|
...restOwnProps
|
|
} = ownProps
|
|
|
|
const toCurrency = currency || currentCurrency
|
|
const convertedValue = getValueFromWeiHex({
|
|
value, toCurrency, conversionRate, numberOfDecimals, toDenomination: denomination,
|
|
})
|
|
const formattedValue = formatCurrency(convertedValue, toCurrency)
|
|
const displayValue = hideLabel ? formattedValue : `${formattedValue} ${toCurrency.toUpperCase()}`
|
|
|
|
return {
|
|
...restStateProps,
|
|
...dispatchProps,
|
|
...restOwnProps,
|
|
displayValue,
|
|
}
|
|
}
|
|
|
|
export default connect(mapStateToProps, null, mergeProps)(CurrencyDisplay)
|