mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Ensure that gas price in popover updates when api provided estimate updates (#11727)
This commit is contained in:
parent
ce61eaacdf
commit
ac32efd814
@ -1,8 +1,7 @@
|
|||||||
import { addHexPrefix } from 'ethereumjs-util';
|
import { addHexPrefix } from 'ethereumjs-util';
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import { findKey } from 'lodash';
|
import { findKey, isEqual } from 'lodash';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
GAS_ESTIMATE_TYPES,
|
GAS_ESTIMATE_TYPES,
|
||||||
EDIT_GAS_MODES,
|
EDIT_GAS_MODES,
|
||||||
@ -220,6 +219,9 @@ export function useGasFeeInputs(
|
|||||||
? Number(hexWEIToDecGWEI(transaction.txParams.maxPriorityFeePerGas))
|
? Number(hexWEIToDecGWEI(transaction.txParams.maxPriorityFeePerGas))
|
||||||
: null,
|
: null,
|
||||||
);
|
);
|
||||||
|
const [gasPriceHasBeenManuallySet, setGasPriceHasBeenManuallySet] = useState(
|
||||||
|
false,
|
||||||
|
);
|
||||||
const [gasPrice, setGasPrice] = useState(
|
const [gasPrice, setGasPrice] = useState(
|
||||||
transaction?.txParams?.gasPrice
|
transaction?.txParams?.gasPrice
|
||||||
? Number(hexWEIToDecGWEI(transaction.txParams.gasPrice))
|
? Number(hexWEIToDecGWEI(transaction.txParams.gasPrice))
|
||||||
@ -263,9 +265,20 @@ export function useGasFeeInputs(
|
|||||||
estimateToUse,
|
estimateToUse,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [initialGasPriceEstimates] = useState(gasFeeEstimates);
|
||||||
|
const gasPriceEstimatesHaveNotChanged = isEqual(
|
||||||
|
initialGasPriceEstimates,
|
||||||
|
gasFeeEstimates,
|
||||||
|
);
|
||||||
const gasPriceToUse =
|
const gasPriceToUse =
|
||||||
gasPrice ??
|
gasPrice !== null &&
|
||||||
getGasPriceEstimate(gasFeeEstimates, gasEstimateType, estimateToUse);
|
(gasPriceHasBeenManuallySet || gasPriceEstimatesHaveNotChanged)
|
||||||
|
? gasPrice
|
||||||
|
: getGasPriceEstimate(
|
||||||
|
gasFeeEstimates,
|
||||||
|
gasEstimateType,
|
||||||
|
estimateToUse || defaultEstimateToUse,
|
||||||
|
);
|
||||||
|
|
||||||
// We have two helper methods that take an object that can have either
|
// We have two helper methods that take an object that can have either
|
||||||
// gasPrice OR the EIP-1559 fields on it, plus gasLimit. This object is
|
// gasPrice OR the EIP-1559 fields on it, plus gasLimit. This object is
|
||||||
@ -456,6 +469,7 @@ export function useGasFeeInputs(
|
|||||||
setMaxFeePerGas(null);
|
setMaxFeePerGas(null);
|
||||||
setMaxPriorityFeePerGas(null);
|
setMaxPriorityFeePerGas(null);
|
||||||
setGasPrice(null);
|
setGasPrice(null);
|
||||||
|
setGasPriceHasBeenManuallySet(false);
|
||||||
},
|
},
|
||||||
[minimumGasLimit, gasErrors.gasLimit, transaction],
|
[minimumGasLimit, gasErrors.gasLimit, transaction],
|
||||||
);
|
);
|
||||||
@ -489,6 +503,7 @@ export function useGasFeeInputs(
|
|||||||
setGasLimit(gasLimit);
|
setGasLimit(gasLimit);
|
||||||
setMaxFeePerGas(maxFeePerGasToUse);
|
setMaxFeePerGas(maxFeePerGasToUse);
|
||||||
setMaxPriorityFeePerGas(maxPriorityFeePerGasToUse);
|
setMaxPriorityFeePerGas(maxPriorityFeePerGasToUse);
|
||||||
|
setGasPriceHasBeenManuallySet(true);
|
||||||
},
|
},
|
||||||
balanceError,
|
balanceError,
|
||||||
estimatesUnavailableWarning,
|
estimatesUnavailableWarning,
|
||||||
|
Loading…
Reference in New Issue
Block a user