2021-07-12 18:16:03 +02:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-07-31 03:29:21 +02:00
|
|
|
import { useSelector } from 'react-redux';
|
2021-06-28 16:45:08 +02:00
|
|
|
|
2021-06-24 01:39:44 +02:00
|
|
|
import { I18nContext } from '../../../contexts/i18n';
|
2021-07-07 00:19:11 +02:00
|
|
|
import FormField from '../../ui/form-field';
|
2021-08-04 23:00:46 +02:00
|
|
|
import { GAS_ESTIMATE_TYPES } from '../../../../shared/constants/gas';
|
2021-07-20 21:34:32 +02:00
|
|
|
import { getGasFormErrorText } from '../../../helpers/constants/gas';
|
2021-08-06 01:59:58 +02:00
|
|
|
import { getIsGasEstimatesLoading } from '../../../ducks/metamask/metamask';
|
2022-03-29 21:21:45 +02:00
|
|
|
import { getNetworkSupportsSettingGasFees } from '../../../selectors';
|
2021-07-12 18:16:03 +02:00
|
|
|
|
|
|
|
export default function AdvancedGasControls({
|
|
|
|
gasEstimateType,
|
|
|
|
maxPriorityFee,
|
|
|
|
maxFee,
|
|
|
|
setMaxPriorityFee,
|
|
|
|
setMaxFee,
|
|
|
|
onManualChange,
|
|
|
|
gasLimit,
|
|
|
|
setGasLimit,
|
|
|
|
gasPrice,
|
|
|
|
setGasPrice,
|
|
|
|
maxPriorityFeeFiat,
|
|
|
|
maxFeeFiat,
|
2021-07-20 21:34:32 +02:00
|
|
|
gasErrors,
|
2021-07-31 15:02:14 +02:00
|
|
|
minimumGasLimit,
|
2021-10-06 20:29:57 +02:00
|
|
|
supportsEIP1559,
|
2021-07-12 18:16:03 +02:00
|
|
|
}) {
|
2021-06-24 01:39:44 +02:00
|
|
|
const t = useContext(I18nContext);
|
2021-08-06 01:59:58 +02:00
|
|
|
const isGasEstimatesLoading = useSelector(getIsGasEstimatesLoading);
|
2021-06-24 01:39:44 +02:00
|
|
|
|
2021-07-31 03:29:21 +02:00
|
|
|
const showFeeMarketFields =
|
2021-10-06 20:29:57 +02:00
|
|
|
supportsEIP1559 &&
|
2021-07-31 03:29:21 +02:00
|
|
|
(gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET ||
|
2021-08-06 21:31:30 +02:00
|
|
|
gasEstimateType === GAS_ESTIMATE_TYPES.ETH_GASPRICE ||
|
|
|
|
isGasEstimatesLoading);
|
2021-06-28 16:45:08 +02:00
|
|
|
|
2022-03-29 21:21:45 +02:00
|
|
|
const networkSupportsSettingGasFees = useSelector(
|
|
|
|
getNetworkSupportsSettingGasFees,
|
2021-11-11 17:46:45 +01:00
|
|
|
);
|
|
|
|
|
2021-06-24 01:39:44 +02:00
|
|
|
return (
|
|
|
|
<div className="advanced-gas-controls">
|
2021-07-07 00:19:11 +02:00
|
|
|
<FormField
|
2021-06-24 01:39:44 +02:00
|
|
|
titleText={t('gasLimit')}
|
2021-07-20 21:34:32 +02:00
|
|
|
error={
|
|
|
|
gasErrors?.gasLimit
|
2021-07-30 13:35:30 +02:00
|
|
|
? getGasFormErrorText(gasErrors.gasLimit, t, { minimumGasLimit })
|
2021-07-20 21:34:32 +02:00
|
|
|
: null
|
|
|
|
}
|
2021-08-02 22:28:30 +02:00
|
|
|
onChange={(value) => {
|
|
|
|
onManualChange?.();
|
|
|
|
setGasLimit(value);
|
|
|
|
}}
|
2021-07-15 19:23:37 +02:00
|
|
|
tooltipText={t('editGasLimitTooltip')}
|
2021-06-24 01:39:44 +02:00
|
|
|
value={gasLimit}
|
2021-07-29 17:59:14 +02:00
|
|
|
allowDecimals={false}
|
2022-03-29 21:21:45 +02:00
|
|
|
disabled={!networkSupportsSettingGasFees}
|
2021-07-07 00:19:11 +02:00
|
|
|
numeric
|
2021-06-24 01:39:44 +02:00
|
|
|
/>
|
2021-07-12 18:16:03 +02:00
|
|
|
{showFeeMarketFields ? (
|
2021-06-28 16:45:08 +02:00
|
|
|
<>
|
2021-07-07 00:19:11 +02:00
|
|
|
<FormField
|
2021-06-28 16:45:08 +02:00
|
|
|
titleText={t('maxPriorityFee')}
|
2021-07-01 16:37:00 +02:00
|
|
|
titleUnit="(GWEI)"
|
2021-07-15 19:23:37 +02:00
|
|
|
tooltipText={t('editGasMaxPriorityFeeTooltip')}
|
2021-07-12 18:16:03 +02:00
|
|
|
onChange={(value) => {
|
|
|
|
onManualChange?.();
|
2021-07-22 18:32:59 +02:00
|
|
|
setMaxPriorityFee(value);
|
2021-07-12 18:16:03 +02:00
|
|
|
}}
|
2021-06-28 16:45:08 +02:00
|
|
|
value={maxPriorityFee}
|
2021-07-12 18:16:03 +02:00
|
|
|
detailText={maxPriorityFeeFiat}
|
2021-07-07 00:19:11 +02:00
|
|
|
numeric
|
2022-10-25 04:55:31 +02:00
|
|
|
allowDecimals
|
2021-07-20 21:34:32 +02:00
|
|
|
error={
|
|
|
|
gasErrors?.maxPriorityFee
|
|
|
|
? getGasFormErrorText(gasErrors.maxPriorityFee, t)
|
|
|
|
: null
|
|
|
|
}
|
2021-06-28 16:45:08 +02:00
|
|
|
/>
|
2021-07-07 00:19:11 +02:00
|
|
|
<FormField
|
2021-06-28 16:45:08 +02:00
|
|
|
titleText={t('maxFee')}
|
2021-07-01 16:37:00 +02:00
|
|
|
titleUnit="(GWEI)"
|
2021-07-15 19:23:37 +02:00
|
|
|
tooltipText={t('editGasMaxFeeTooltip')}
|
2021-07-12 18:16:03 +02:00
|
|
|
onChange={(value) => {
|
|
|
|
onManualChange?.();
|
2021-07-22 18:32:59 +02:00
|
|
|
setMaxFee(value);
|
2021-07-12 18:16:03 +02:00
|
|
|
}}
|
2021-06-28 16:45:08 +02:00
|
|
|
value={maxFee}
|
2021-07-07 00:19:11 +02:00
|
|
|
numeric
|
2022-10-25 04:55:31 +02:00
|
|
|
allowDecimals
|
2021-07-12 18:16:03 +02:00
|
|
|
detailText={maxFeeFiat}
|
2021-07-20 21:34:32 +02:00
|
|
|
error={
|
|
|
|
gasErrors?.maxFee
|
|
|
|
? getGasFormErrorText(gasErrors.maxFee, t)
|
|
|
|
: null
|
|
|
|
}
|
2021-06-28 16:45:08 +02:00
|
|
|
/>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
2021-07-07 00:19:11 +02:00
|
|
|
<FormField
|
2021-07-15 19:23:54 +02:00
|
|
|
titleText={t('advancedGasPriceTitle')}
|
2021-07-01 16:37:00 +02:00
|
|
|
titleUnit="(GWEI)"
|
2021-07-12 18:16:03 +02:00
|
|
|
onChange={(value) => {
|
|
|
|
onManualChange?.();
|
2021-07-22 18:32:59 +02:00
|
|
|
setGasPrice(value);
|
2021-07-12 18:16:03 +02:00
|
|
|
}}
|
2021-07-02 21:07:34 +02:00
|
|
|
tooltipText={t('editGasPriceTooltip')}
|
2021-06-28 16:45:08 +02:00
|
|
|
value={gasPrice}
|
2021-07-07 00:19:11 +02:00
|
|
|
numeric
|
2022-10-25 04:55:31 +02:00
|
|
|
allowDecimals
|
2021-08-03 17:54:49 +02:00
|
|
|
error={
|
|
|
|
gasErrors?.gasPrice
|
|
|
|
? getGasFormErrorText(gasErrors.gasPrice, t)
|
|
|
|
: null
|
|
|
|
}
|
2022-03-29 21:21:45 +02:00
|
|
|
disabled={!networkSupportsSettingGasFees}
|
2021-06-28 16:45:08 +02:00
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
2021-06-24 01:39:44 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2021-07-12 18:16:03 +02:00
|
|
|
|
|
|
|
AdvancedGasControls.propTypes = {
|
|
|
|
gasEstimateType: PropTypes.oneOf(Object.values(GAS_ESTIMATE_TYPES)),
|
|
|
|
setMaxPriorityFee: PropTypes.func,
|
|
|
|
setMaxFee: PropTypes.func,
|
2022-06-02 20:05:41 +02:00
|
|
|
maxPriorityFee: PropTypes.string,
|
|
|
|
maxFee: PropTypes.string,
|
2021-07-12 18:16:03 +02:00
|
|
|
onManualChange: PropTypes.func,
|
|
|
|
gasLimit: PropTypes.number,
|
|
|
|
setGasLimit: PropTypes.func,
|
2022-06-02 20:05:41 +02:00
|
|
|
gasPrice: PropTypes.string,
|
2021-07-12 18:16:03 +02:00
|
|
|
setGasPrice: PropTypes.func,
|
|
|
|
maxPriorityFeeFiat: PropTypes.string,
|
|
|
|
maxFeeFiat: PropTypes.string,
|
2021-07-20 21:34:32 +02:00
|
|
|
gasErrors: PropTypes.object,
|
2021-08-10 22:45:09 +02:00
|
|
|
minimumGasLimit: PropTypes.string,
|
2021-10-06 20:29:57 +02:00
|
|
|
supportsEIP1559: PropTypes.bool,
|
2021-07-12 18:16:03 +02:00
|
|
|
};
|