mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Use eth_gasPrice result for setting too low warning on custom networks (#11370)
* Use eth_gasPrice result for setting too low warning on custom networks * Assume CustomPriceSafeForCustomNetwork when there is no custom price set (it will default to recommended)
This commit is contained in:
parent
73200a7876
commit
b7b30d0796
@ -28,6 +28,7 @@ import {
|
|||||||
getIsMainnet,
|
getIsMainnet,
|
||||||
getSendToken,
|
getSendToken,
|
||||||
getPreferences,
|
getPreferences,
|
||||||
|
getIsTestnet,
|
||||||
getBasicGasEstimateLoadingStatus,
|
getBasicGasEstimateLoadingStatus,
|
||||||
getCustomGasLimit,
|
getCustomGasLimit,
|
||||||
getCustomGasPrice,
|
getCustomGasPrice,
|
||||||
@ -36,6 +37,7 @@ import {
|
|||||||
isCustomPriceSafe,
|
isCustomPriceSafe,
|
||||||
getTokenBalance,
|
getTokenBalance,
|
||||||
getSendMaxModeState,
|
getSendMaxModeState,
|
||||||
|
isCustomPriceSafeForCustomNetwork,
|
||||||
getAveragePriceEstimateInHexWEI,
|
getAveragePriceEstimateInHexWEI,
|
||||||
isCustomPriceExcessive,
|
isCustomPriceExcessive,
|
||||||
getIsGasEstimatesFetched,
|
getIsGasEstimatesFetched,
|
||||||
@ -118,6 +120,7 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
const showFiat = Boolean(isMainnet || showFiatInTestnets);
|
const showFiat = Boolean(isMainnet || showFiatInTestnets);
|
||||||
|
|
||||||
const isSendTokenSet = Boolean(sendToken);
|
const isSendTokenSet = Boolean(sendToken);
|
||||||
|
const isTestnet = getIsTestnet(state);
|
||||||
|
|
||||||
const newTotalEth =
|
const newTotalEth =
|
||||||
maxModeOn && !isSendTokenSet
|
maxModeOn && !isSendTokenSet
|
||||||
@ -138,6 +141,16 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
conversionRate,
|
conversionRate,
|
||||||
});
|
});
|
||||||
const isGasEstimate = getIsGasEstimatesFetched(state);
|
const isGasEstimate = getIsGasEstimatesFetched(state);
|
||||||
|
|
||||||
|
let customPriceIsSafe;
|
||||||
|
if ((isMainnet || process.env.IN_TEST) && isGasEstimate) {
|
||||||
|
customPriceIsSafe = isCustomPriceSafe(state);
|
||||||
|
} else if (isTestnet) {
|
||||||
|
customPriceIsSafe = true;
|
||||||
|
} else {
|
||||||
|
customPriceIsSafe = isCustomPriceSafeForCustomNetwork(state);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hideBasic,
|
hideBasic,
|
||||||
isConfirm: isConfirm(state),
|
isConfirm: isConfirm(state),
|
||||||
@ -147,10 +160,7 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
customGasLimit: calcCustomGasLimit(customModalGasLimitInHex),
|
customGasLimit: calcCustomGasLimit(customModalGasLimitInHex),
|
||||||
customGasTotal,
|
customGasTotal,
|
||||||
newTotalFiat,
|
newTotalFiat,
|
||||||
customPriceIsSafe:
|
customPriceIsSafe,
|
||||||
(isMainnet || process.env.IN_TEST) && isGasEstimate
|
|
||||||
? isCustomPriceSafe(state)
|
|
||||||
: true,
|
|
||||||
customPriceIsExcessive: isCustomPriceExcessive(state),
|
customPriceIsExcessive: isCustomPriceExcessive(state),
|
||||||
maxModeOn,
|
maxModeOn,
|
||||||
gasPriceButtonGroupProps: {
|
gasPriceButtonGroupProps: {
|
||||||
|
@ -100,6 +100,28 @@ export function isCustomPriceSafe(state) {
|
|||||||
return customPriceSafe;
|
return customPriceSafe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isCustomPriceSafeForCustomNetwork(state) {
|
||||||
|
const estimatedPrice = state.gas.basicEstimates.average;
|
||||||
|
|
||||||
|
const customGasPrice = getCustomGasPrice(state);
|
||||||
|
|
||||||
|
if (!customGasPrice) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const customPriceSafe = conversionGreaterThan(
|
||||||
|
{
|
||||||
|
value: customGasPrice,
|
||||||
|
fromNumericBase: 'hex',
|
||||||
|
fromDenomination: 'WEI',
|
||||||
|
toDenomination: 'GWEI',
|
||||||
|
},
|
||||||
|
{ value: estimatedPrice, fromNumericBase: 'dec' },
|
||||||
|
);
|
||||||
|
|
||||||
|
return customPriceSafe;
|
||||||
|
}
|
||||||
|
|
||||||
export function isCustomPriceExcessive(state, checkSend = false) {
|
export function isCustomPriceExcessive(state, checkSend = false) {
|
||||||
const customPrice = checkSend ? getGasPrice(state) : getCustomGasPrice(state);
|
const customPrice = checkSend ? getGasPrice(state) : getCustomGasPrice(state);
|
||||||
const fastPrice = getFastPriceEstimate(state);
|
const fastPrice = getFastPriceEstimate(state);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user