mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix 11705 - Reset gas limit when radio button clicked (#11710)
* Fix 11705 - Reset gas limit when radio button clicked * Trigger manual change when gasLimit is changed * Coordinate gas limit with radio buttons * Revert "Coordinate gas limit with radio buttons" This reverts commit 910327a408e32ae989c5565a107db24ac24f2a98. * Cleanup default gas limit * setEstimateToUse only update gasLimit on error, add default minimum gasLimit * add minimum gasLimit fallback Co-authored-by: Alex <adonesky@gmail.com>
This commit is contained in:
parent
c43f6cab63
commit
d34bf92fd0
@ -75,7 +75,10 @@ export default function AdvancedGasControls({
|
||||
? getGasFormErrorText(gasErrors.gasLimit, t, { minimumGasLimit })
|
||||
: null
|
||||
}
|
||||
onChange={setGasLimit}
|
||||
onChange={(value) => {
|
||||
onManualChange?.();
|
||||
setGasLimit(value);
|
||||
}}
|
||||
tooltipText={t('editGasLimitTooltip')}
|
||||
value={gasLimit}
|
||||
allowDecimals={false}
|
||||
|
@ -167,7 +167,7 @@ function getMatchingEstimateFromGasFees(
|
||||
export function useGasFeeInputs(
|
||||
defaultEstimateToUse = 'medium',
|
||||
transaction,
|
||||
minimumGasLimit,
|
||||
minimumGasLimit = '0x5208',
|
||||
editGasMode,
|
||||
) {
|
||||
const { balance: ethBalance } = useSelector(getSelectedAccount);
|
||||
@ -221,10 +221,9 @@ export function useGasFeeInputs(
|
||||
: null,
|
||||
);
|
||||
const [gasLimit, setGasLimit] = useState(
|
||||
transaction?.txParams?.gas
|
||||
? Number(hexToDecimal(transaction.txParams.gas))
|
||||
: 21000,
|
||||
Number(hexToDecimal(transaction?.txParams?.gas ?? minimumGasLimit)),
|
||||
);
|
||||
|
||||
const [estimateToUse, setInternalEstimateToUse] = useState(
|
||||
transaction
|
||||
? getMatchingEstimateFromGasFees(
|
||||
@ -237,16 +236,6 @@ export function useGasFeeInputs(
|
||||
: defaultEstimateToUse,
|
||||
);
|
||||
|
||||
// When a user selects an estimate level, it will wipe out what they have
|
||||
// previously put in the inputs. This returns the inputs to the estimated
|
||||
// values at the level specified.
|
||||
const setEstimateToUse = useCallback((estimateLevel) => {
|
||||
setInternalEstimateToUse(estimateLevel);
|
||||
setMaxFeePerGas(null);
|
||||
setMaxPriorityFeePerGas(null);
|
||||
setGasPrice(null);
|
||||
}, []);
|
||||
|
||||
// We specify whether to use the estimate value by checking if the state
|
||||
// value has been set. The state value is only set by user input and is wiped
|
||||
// when the user selects an estimate. Default here is '0' to avoid bignumber
|
||||
@ -435,6 +424,28 @@ export function useGasFeeInputs(
|
||||
{ value: ethBalance, fromNumericBase: 'hex' },
|
||||
);
|
||||
|
||||
// When a user selects an estimate level, it will wipe out what they have
|
||||
// previously put in the inputs. This returns the inputs to the estimated
|
||||
// values at the level specified.
|
||||
const setEstimateToUse = useCallback(
|
||||
(estimateLevel) => {
|
||||
setInternalEstimateToUse(estimateLevel);
|
||||
if (gasErrors.gasLimit === GAS_FORM_ERRORS.GAS_LIMIT_OUT_OF_BOUNDS) {
|
||||
const transactionGasLimit = hexToDecimal(transaction?.txParams?.gas);
|
||||
const minimumGasLimitDec = hexToDecimal(minimumGasLimit);
|
||||
setGasLimit(
|
||||
transactionGasLimit > minimumGasLimitDec
|
||||
? transactionGasLimit
|
||||
: minimumGasLimitDec,
|
||||
);
|
||||
}
|
||||
setMaxFeePerGas(null);
|
||||
setMaxPriorityFeePerGas(null);
|
||||
setGasPrice(null);
|
||||
},
|
||||
[minimumGasLimit, gasErrors.gasLimit, transaction],
|
||||
);
|
||||
|
||||
return {
|
||||
maxFeePerGas: maxFeePerGasToUse,
|
||||
maxFeePerGasFiat: showFiat ? maxFeePerGasFiat : '',
|
||||
|
Loading…
x
Reference in New Issue
Block a user