1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00
metamask-extension/ui/components/app/advanced-gas-inputs/advanced-gas-inputs.container.js
2023-04-26 05:43:38 +05:30

44 lines
1.3 KiB
JavaScript

import { connect } from 'react-redux';
import { MIN_GAS_LIMIT_DEC } from '../../../pages/send/send.constants';
import {
decGWEIToHexWEI,
decimalToHex,
hexWEIToDecGWEI,
} from '../../../../shared/modules/conversion.utils';
import AdvancedGasInputs from './advanced-gas-inputs.component';
function convertGasPriceForInputs(gasPriceInHexWEI) {
return Number(hexWEIToDecGWEI(gasPriceInHexWEI));
}
function convertGasLimitForInputs(gasLimitInHexWEI) {
return parseInt(gasLimitInHexWEI, 16) || 0;
}
function convertMinimumGasLimitForInputs(minimumGasLimit = MIN_GAS_LIMIT_DEC) {
return parseInt(minimumGasLimit, 10);
}
function mergeProps(stateProps, dispatchProps, ownProps) {
const {
customGasPrice,
customGasLimit,
updateCustomGasPrice,
updateCustomGasLimit,
minimumGasLimit,
} = ownProps;
return {
...ownProps,
...stateProps,
...dispatchProps,
customGasPrice: convertGasPriceForInputs(customGasPrice),
customGasLimit: convertGasLimitForInputs(customGasLimit),
minimumGasLimit: convertMinimumGasLimitForInputs(minimumGasLimit),
updateCustomGasPrice: (price) =>
updateCustomGasPrice(decGWEIToHexWEI(price)),
updateCustomGasLimit: (limit) => updateCustomGasLimit(decimalToHex(limit)),
};
}
export default connect(undefined, null, mergeProps)(AdvancedGasInputs);