aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/app/gas-customization/advanced-gas-inputs/advanced-gas-inputs.container.js
blob: 90fef1a1b898aa612f497c78ad894c7c65896c41 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)
}

const mapDispatchToProps = dispatch => {
  return {
    showGasPriceInfoModal: modalName => dispatch(showModal({ name: 'GAS_PRICE_INFO_MODAL' })),
    showGasLimitInfoModal: modalName => dispatch(showModal({ name: 'GAS_LIMIT_INFO_MODAL' })),
  }
}

const mergeProps = (stateProps, dispatchProps, ownProps) => {
  const {customGasPrice, customGasLimit, updateCustomGasPrice, updateCustomGasLimit} = ownProps
  return {
    ...stateProps,
    ...dispatchProps,
    ...ownProps,
    customGasPrice: convertGasPriceForInputs(customGasPrice),
    customGasLimit: convertGasLimitForInputs(customGasLimit),
    updateCustomGasPrice: (price) => updateCustomGasPrice(decGWEIToHexWEI(price)),
    updateCustomGasLimit: (limit) => updateCustomGasLimit(decimalToHex(limit)),
  }
}

export default connect(null, mapDispatchToProps, mergeProps)(AdvancedGasInputs)