1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Ensure gas fees update in popover on poll for new values (#11760)

This commit is contained in:
Dan J Miller 2021-08-04 18:27:14 -02:30 committed by Dan Miller
parent 0dcdbdd99e
commit b9d5c431c1

View File

@ -206,41 +206,51 @@ export function useGasFeeInputs(
estimatedGasFeeTimeBounds,
} = useGasFeeEstimates();
const [initialMaxFeePerGas] = useState(
Number(hexWEIToDecGWEI(transaction?.txParams?.maxFeePerGas)),
);
const [initialMaxPriorityFeePerGas] = useState(
Number(hexWEIToDecGWEI(transaction?.txParams?.maxPriorityFeePerGas)),
);
const [initialGasPrice] = useState(
Number(hexWEIToDecGWEI(transaction?.txParams?.gasPrice)),
);
const [initialMatchingEstimateLevel] = useState(
getMatchingEstimateFromGasFees(
gasFeeEstimates,
initialMaxFeePerGas,
initialMaxPriorityFeePerGas,
initialGasPrice,
networkAndAccountSupports1559,
),
);
// This hook keeps track of a few pieces of transitional state. It is
// transitional because it is only used to modify a transaction in the
// metamask (background) state tree.
const [maxFeePerGas, setMaxFeePerGas] = useState(
transaction?.txParams?.maxFeePerGas
? Number(hexWEIToDecGWEI(transaction.txParams.maxFeePerGas))
initialMaxFeePerGas && !initialMatchingEstimateLevel
? initialMaxFeePerGas
: null,
);
const [maxPriorityFeePerGas, setMaxPriorityFeePerGas] = useState(
transaction?.txParams?.maxPriorityFeePerGas
? Number(hexWEIToDecGWEI(transaction.txParams.maxPriorityFeePerGas))
initialMaxPriorityFeePerGas && !initialMatchingEstimateLevel
? initialMaxPriorityFeePerGas
: null,
);
const [gasPriceHasBeenManuallySet, setGasPriceHasBeenManuallySet] = useState(
false,
);
const [gasPrice, setGasPrice] = useState(
transaction?.txParams?.gasPrice
? Number(hexWEIToDecGWEI(transaction.txParams.gasPrice))
: null,
initialGasPrice && !initialMatchingEstimateLevel ? initialGasPrice : null,
);
const [gasLimit, setGasLimit] = useState(
Number(hexToDecimal(transaction?.txParams?.gas ?? minimumGasLimit)),
);
const [estimateToUse, setInternalEstimateToUse] = useState(
transaction
? getMatchingEstimateFromGasFees(
gasFeeEstimates,
maxFeePerGas,
maxPriorityFeePerGas,
gasPrice,
networkAndAccountSupports1559,
)
: defaultEstimateToUse,
transaction ? initialMatchingEstimateLevel : defaultEstimateToUse,
);
// We specify whether to use the estimate value by checking if the state