1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00
metamask-extension/ui/components/app/advanced-gas-inputs/advanced-gas-inputs.container.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

import { connect } from 'react-redux';
import { getNetworkSupportsSettingGasFees } from '../../../selectors/selectors';
import { MIN_GAS_LIMIT_DEC } from '../../../pages/send/send.constants';
2019-02-08 14:50:25 +01:00
import {
decGWEIToHexWEI,
2019-02-08 14:50:25 +01:00
decimalToHex,
hexWEIToDecGWEI,
} from '../../../../shared/modules/conversion.utils';
import AdvancedGasInputs from './advanced-gas-inputs.component';
2020-11-03 00:41:28 +01:00
function convertGasPriceForInputs(gasPriceInHexWEI) {
return Number(hexWEIToDecGWEI(gasPriceInHexWEI));
2019-02-08 14:50:25 +01:00
}
2020-11-03 00:41:28 +01:00
function convertGasLimitForInputs(gasLimitInHexWEI) {
return parseInt(gasLimitInHexWEI, 16) || 0;
2019-02-08 14:50:25 +01:00
}
function convertMinimumGasLimitForInputs(minimumGasLimit = MIN_GAS_LIMIT_DEC) {
return parseInt(minimumGasLimit, 10);
}
function mapStateToProps(state) {
return {
networkSupportsSettingGasFees: getNetworkSupportsSettingGasFees(state),
};
}
function mergeProps(stateProps, dispatchProps, ownProps) {
2020-11-03 00:41:28 +01:00
const {
customGasPrice,
customGasLimit,
updateCustomGasPrice,
updateCustomGasLimit,
minimumGasLimit,
} = ownProps;
2019-02-08 14:50:25 +01:00
return {
Use `AdvancedGasInputs` in `AdvancedTabContent` (#7186) * Use `AdvancedGasInputs` in `AdvancedTabContent` The `AdvancedGasInputs` component was originally extracted from the `AdvancedTabContent` component, duplicating much of the rendering logic. They have since evolved separately, with bugs being fixed in one place but not the other. The inputs and outputs expected weren't exactly the same, as the `AdvancedGasInputs` component converts the input custom gas price and limit, and it converts them both in the setter methods as well. The `GasModalPageContainer` had to be adjusted to avoid converting these values multiple times. Both components dealt with input debouncing separately, both in less than ideal ways. `AdvancedTabContent` didn't debounce either field, but it did debounce the check for whether the gas limit field was below the minimum value. So if a less-than-minimum value was set, it would be propogated upwards and could be saved if the user clicked 'Save' quickly enough. After a second delay it would snap back to the minimum value. The `AdvancedGasInputs` component debounced both fields, but it would replace any gas limit below the minimum with the minimum value. This led to a problem where a brief pause during typing would reset the field to 21000. The `AdvancedGasInputs` approach was chosen, except that it was updated to no longer change the gas limit if it was below the minimum. Instead it displays an error. Parent components were checked to ensure they would detect the error case of the gas limit being set too low, and prevent the form submission in those cases. Of the three parents, one had already dealt with it correctly, one needed to convert the gas limit from hex first, and another needed the gas limit check added. Closes #6872 * Cleanup send components Empty README files have been removed, and a mistake in the index file for the send page has been corrected. The Gas Slider component class name was updated as well; it looks like it was originally created from `AdvancedTabContent`, so it still had that class name.
2019-10-23 14:23:15 +02:00
...ownProps,
2019-02-08 14:50:25 +01:00
...stateProps,
...dispatchProps,
customGasPrice: convertGasPriceForInputs(customGasPrice),
customGasLimit: convertGasLimitForInputs(customGasLimit),
minimumGasLimit: convertMinimumGasLimitForInputs(minimumGasLimit),
2020-11-03 00:41:28 +01:00
updateCustomGasPrice: (price) =>
updateCustomGasPrice(decGWEIToHexWEI(price)),
2019-02-08 14:50:25 +01:00
updateCustomGasLimit: (limit) => updateCustomGasLimit(decimalToHex(limit)),
};
}
2019-02-08 14:50:25 +01:00
export default connect(mapStateToProps, null, mergeProps)(AdvancedGasInputs);