1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
2020-02-15 17:04:21 -03:30

39 lines
1.3 KiB
JavaScript

import { connect } from 'react-redux'
import { showModal } from '../../../../store/actions'
import {
decGWEIToHexWEI,
decimalToHex,
hexWEIToDecGWEI,
} from '../../../../helpers/utils/conversions.util'
import AdvancedGasInputs from './advanced-gas-inputs.component'
function convertGasPriceForInputs (gasPriceInHexWEI) {
return Number(hexWEIToDecGWEI(gasPriceInHexWEI))
}
function convertGasLimitForInputs (gasLimitInHexWEI) {
return parseInt(gasLimitInHexWEI, 16) || 0
}
const mapDispatchToProps = (dispatch) => {
return {
showGasPriceInfoModal: () => dispatch(showModal({ name: 'GAS_PRICE_INFO_MODAL' })),
showGasLimitInfoModal: () => dispatch(showModal({ name: 'GAS_LIMIT_INFO_MODAL' })),
}
}
const mergeProps = (stateProps, dispatchProps, ownProps) => {
const { customGasPrice, customGasLimit, updateCustomGasPrice, updateCustomGasLimit } = ownProps
return {
...ownProps,
...stateProps,
...dispatchProps,
customGasPrice: convertGasPriceForInputs(customGasPrice),
customGasLimit: convertGasLimitForInputs(customGasLimit),
updateCustomGasPrice: (price) => updateCustomGasPrice(decGWEIToHexWEI(price)),
updateCustomGasLimit: (limit) => updateCustomGasLimit(decimalToHex(limit)),
}
}
export default connect(null, mapDispatchToProps, mergeProps)(AdvancedGasInputs)