2021-04-28 21:53:59 +02:00
|
|
|
import { addHexPrefix } from '../../app/scripts/lib/util';
|
2018-08-16 14:28:27 +02:00
|
|
|
import {
|
|
|
|
conversionUtil,
|
2018-12-10 22:51:00 +01:00
|
|
|
conversionGreaterThan,
|
2021-07-06 19:48:49 +02:00
|
|
|
} from '../../shared/modules/conversion.utils';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { formatCurrency } from '../helpers/utils/confirm-tx.util';
|
|
|
|
import { decEthToConvertedCurrency as ethTotalToConvertedCurrency } from '../helpers/utils/conversions.util';
|
|
|
|
import { formatETHFee } from '../helpers/utils/formatters';
|
|
|
|
import { calcGasTotal } from '../pages/send/send.utils';
|
2018-08-16 14:28:27 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
import { getGasPrice } from '../ducks/send';
|
2021-07-16 18:06:32 +02:00
|
|
|
import {
|
|
|
|
GAS_ESTIMATE_TYPES as GAS_FEE_CONTROLLER_ESTIMATE_TYPES,
|
|
|
|
GAS_LIMITS,
|
|
|
|
} from '../../shared/constants/gas';
|
|
|
|
import {
|
|
|
|
getGasEstimateType,
|
|
|
|
getGasFeeEstimates,
|
|
|
|
isEIP1559Network,
|
|
|
|
} from '../ducks/metamask/metamask';
|
|
|
|
import { GAS_ESTIMATE_TYPES } from '../helpers/constants/common';
|
2021-06-24 01:28:49 +02:00
|
|
|
import { getCurrentCurrency, getIsMainnet, getShouldShowFiat } from '.';
|
Use `AdvancedGasInputs` in `AdvancedTabContent` (#7186)
* Use `AdvancedGasInputs` in `AdvancedTabContent`
The `AdvancedGasInputs` component was originally extracted from the
`AdvancedTabContent` component, duplicating much of the rendering
logic. They have since evolved separately, with bugs being fixed in one
place but not the other.
The inputs and outputs expected weren't exactly the same, as the
`AdvancedGasInputs` component converts the input custom gas price and
limit, and it converts them both in the setter methods as well.
The `GasModalPageContainer` had to be adjusted to avoid converting
these values multiple times.
Both components dealt with input debouncing separately, both in less
than ideal ways. `AdvancedTabContent` didn't debounce either field, but
it did debounce the check for whether the gas limit field was below the
minimum value. So if a less-than-minimum value was set, it would be
propogated upwards and could be saved if the user clicked 'Save'
quickly enough. After a second delay it would snap back to the minimum
value. The `AdvancedGasInputs` component debounced both fields, but
it would replace any gas limit below the minimum with the minimum
value. This led to a problem where a brief pause during typing would
reset the field to 21000.
The `AdvancedGasInputs` approach was chosen, except that it was
updated to no longer change the gas limit if it was below the minimum.
Instead it displays an error. Parent components were checked to ensure
they would detect the error case of the gas limit being set too low,
and prevent the form submission in those cases. Of the three parents,
one had already dealt with it correctly, one needed to convert the
gas limit from hex first, and another needed the gas limit check added.
Closes #6872
* Cleanup send components
Empty README files have been removed, and a mistake in the index file
for the send page has been corrected. The Gas Slider component class
name was updated as well; it looks like it was originally created from
`AdvancedTabContent`, so it still had that class name.
2019-10-23 14:23:15 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const NUMBER_OF_DECIMALS_SM_BTNS = 5;
|
2018-09-13 14:35:17 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getCustomGasLimit(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.gas.customData.limit;
|
2018-08-02 18:02:22 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getCustomGasPrice(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return state.gas.customData.price;
|
2018-08-16 14:28:27 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getBasicGasEstimateLoadingStatus(state) {
|
2021-07-16 18:06:32 +02:00
|
|
|
return getIsGasEstimatesFetched(state) === false;
|
2018-08-16 14:28:27 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getAveragePriceEstimateInHexWEI(state) {
|
2021-07-16 18:06:32 +02:00
|
|
|
const averagePriceEstimate = getAverageEstimate(state);
|
|
|
|
|
2021-04-28 20:02:01 +02:00
|
|
|
return getGasPriceInHexWei(averagePriceEstimate);
|
2018-09-13 10:47:05 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getFastPriceEstimateInHexWEI(state) {
|
2021-03-05 18:32:09 +01:00
|
|
|
const fastPriceEstimate = getFastPriceEstimate(state);
|
2021-02-04 19:15:23 +01:00
|
|
|
return getGasPriceInHexWei(fastPriceEstimate || '0x0');
|
2018-11-13 17:36:52 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getDefaultActiveButtonIndex(
|
|
|
|
gasButtonInfo,
|
|
|
|
customGasPriceInHex,
|
|
|
|
gasPrice,
|
|
|
|
) {
|
2020-10-12 18:51:17 +02:00
|
|
|
return gasButtonInfo
|
|
|
|
.map(({ priceInHexWei }) => priceInHexWei)
|
2021-02-04 19:15:23 +01:00
|
|
|
.lastIndexOf(addHexPrefix(customGasPriceInHex || gasPrice));
|
2018-09-13 10:47:05 +02:00
|
|
|
}
|
2018-08-16 14:28:27 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getSafeLowEstimate(state) {
|
2021-07-16 18:06:32 +02:00
|
|
|
const gasFeeEstimates = getGasFeeEstimates(state);
|
|
|
|
const gasEstimateType = getGasEstimateType(state);
|
|
|
|
|
|
|
|
return gasEstimateType === GAS_FEE_CONTROLLER_ESTIMATE_TYPES.LEGACY
|
|
|
|
? gasFeeEstimates?.low
|
|
|
|
: null;
|
|
|
|
}
|
2018-12-10 22:51:00 +01:00
|
|
|
|
2021-07-16 18:06:32 +02:00
|
|
|
export function getAverageEstimate(state) {
|
|
|
|
const gasFeeEstimates = getGasFeeEstimates(state);
|
|
|
|
const gasEstimateType = getGasEstimateType(state);
|
|
|
|
|
|
|
|
return gasEstimateType === GAS_FEE_CONTROLLER_ESTIMATE_TYPES.LEGACY
|
|
|
|
? gasFeeEstimates?.medium
|
|
|
|
: null;
|
2018-12-10 22:51:00 +01:00
|
|
|
}
|
|
|
|
|
2021-03-05 18:32:09 +01:00
|
|
|
export function getFastPriceEstimate(state) {
|
2021-07-16 18:06:32 +02:00
|
|
|
const gasFeeEstimates = getGasFeeEstimates(state);
|
2021-03-05 18:32:09 +01:00
|
|
|
|
2021-07-16 18:06:32 +02:00
|
|
|
const gasEstimateType = getGasEstimateType(state);
|
|
|
|
|
|
|
|
return gasEstimateType === GAS_FEE_CONTROLLER_ESTIMATE_TYPES.LEGACY
|
|
|
|
? gasFeeEstimates?.high
|
|
|
|
: null;
|
2021-03-05 18:32:09 +01:00
|
|
|
}
|
|
|
|
|
2020-11-04 17:14:08 +01:00
|
|
|
export function isCustomPriceSafe(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const safeLow = getSafeLowEstimate(state);
|
2020-10-17 11:13:51 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const customGasPrice = getCustomGasPrice(state);
|
2018-12-10 22:51:00 +01:00
|
|
|
|
|
|
|
if (!customGasPrice) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return true;
|
2018-12-10 22:51:00 +01:00
|
|
|
}
|
|
|
|
|
2021-03-02 23:19:56 +01:00
|
|
|
if (!safeLow) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return false;
|
2019-06-18 14:17:14 +02:00
|
|
|
}
|
|
|
|
|
2018-12-10 22:51:00 +01:00
|
|
|
const customPriceSafe = conversionGreaterThan(
|
|
|
|
{
|
|
|
|
value: customGasPrice,
|
|
|
|
fromNumericBase: 'hex',
|
|
|
|
fromDenomination: 'WEI',
|
|
|
|
toDenomination: 'GWEI',
|
|
|
|
},
|
2020-11-04 17:14:08 +01:00
|
|
|
{ value: safeLow, fromNumericBase: 'dec' },
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-12-10 22:51:00 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return customPriceSafe;
|
2018-12-10 22:51:00 +01:00
|
|
|
}
|
|
|
|
|
2021-06-24 18:59:47 +02:00
|
|
|
export function isCustomPriceSafeForCustomNetwork(state) {
|
2021-07-16 18:06:32 +02:00
|
|
|
const estimatedPrice = getAverageEstimate(state);
|
2021-06-24 18:59:47 +02:00
|
|
|
|
|
|
|
const customGasPrice = getCustomGasPrice(state);
|
|
|
|
|
|
|
|
if (!customGasPrice) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-30 20:26:34 +02:00
|
|
|
if (!estimatedPrice) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-24 18:59:47 +02:00
|
|
|
const customPriceSafe = conversionGreaterThan(
|
|
|
|
{
|
|
|
|
value: customGasPrice,
|
|
|
|
fromNumericBase: 'hex',
|
|
|
|
fromDenomination: 'WEI',
|
|
|
|
toDenomination: 'GWEI',
|
|
|
|
},
|
|
|
|
{ value: estimatedPrice, fromNumericBase: 'dec' },
|
|
|
|
);
|
|
|
|
|
|
|
|
return customPriceSafe;
|
|
|
|
}
|
|
|
|
|
2021-03-05 18:32:09 +01:00
|
|
|
export function isCustomPriceExcessive(state, checkSend = false) {
|
|
|
|
const customPrice = checkSend ? getGasPrice(state) : getCustomGasPrice(state);
|
|
|
|
const fastPrice = getFastPriceEstimate(state);
|
|
|
|
|
|
|
|
if (!customPrice || !fastPrice) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Custom gas should be considered excessive when it is 1.5 times greater than the fastest estimate.
|
|
|
|
const customPriceExcessive = conversionGreaterThan(
|
|
|
|
{
|
|
|
|
value: customPrice,
|
|
|
|
fromNumericBase: 'hex',
|
|
|
|
fromDenomination: 'WEI',
|
|
|
|
toDenomination: 'GWEI',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fromNumericBase: 'dec',
|
|
|
|
value: Math.floor(fastPrice * 1.5),
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
return customPriceExcessive;
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function basicPriceEstimateToETHTotal(
|
|
|
|
estimate,
|
|
|
|
gasLimit,
|
|
|
|
numberOfDecimals = 9,
|
|
|
|
) {
|
2018-08-16 14:28:27 +02:00
|
|
|
return conversionUtil(calcGasTotal(gasLimit, estimate), {
|
|
|
|
fromNumericBase: 'hex',
|
|
|
|
toNumericBase: 'dec',
|
|
|
|
fromDenomination: 'GWEI',
|
2018-09-13 14:35:17 +02:00
|
|
|
numberOfDecimals,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-08-16 14:28:27 +02:00
|
|
|
}
|
|
|
|
|
2021-03-29 21:30:06 +02:00
|
|
|
export function getRenderableEthFee(
|
|
|
|
estimate,
|
|
|
|
gasLimit,
|
|
|
|
numberOfDecimals = 9,
|
|
|
|
nativeCurrency = 'ETH',
|
|
|
|
) {
|
2020-11-03 00:41:28 +01:00
|
|
|
const value = conversionUtil(estimate, {
|
|
|
|
fromNumericBase: 'dec',
|
|
|
|
toNumericBase: 'hex',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
const fee = basicPriceEstimateToETHTotal(value, gasLimit, numberOfDecimals);
|
2021-03-29 21:30:06 +02:00
|
|
|
return formatETHFee(fee, nativeCurrency);
|
2018-08-16 14:28:27 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getRenderableConvertedCurrencyFee(
|
|
|
|
estimate,
|
|
|
|
gasLimit,
|
|
|
|
convertedCurrency,
|
|
|
|
conversionRate,
|
|
|
|
) {
|
|
|
|
const value = conversionUtil(estimate, {
|
|
|
|
fromNumericBase: 'dec',
|
|
|
|
toNumericBase: 'hex',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
const fee = basicPriceEstimateToETHTotal(value, gasLimit);
|
2020-11-03 00:41:28 +01:00
|
|
|
const feeInCurrency = ethTotalToConvertedCurrency(
|
|
|
|
fee,
|
|
|
|
convertedCurrency,
|
|
|
|
conversionRate,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
return formatCurrency(feeInCurrency, convertedCurrency);
|
2018-08-16 14:28:27 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function priceEstimateToWei(priceEstimate) {
|
2018-08-16 14:28:27 +02:00
|
|
|
return conversionUtil(priceEstimate, {
|
|
|
|
fromNumericBase: 'hex',
|
|
|
|
toNumericBase: 'hex',
|
|
|
|
fromDenomination: 'GWEI',
|
|
|
|
toDenomination: 'WEI',
|
|
|
|
numberOfDecimals: 9,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-08-16 14:28:27 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getGasPriceInHexWei(price) {
|
|
|
|
const value = conversionUtil(price, {
|
|
|
|
fromNumericBase: 'dec',
|
|
|
|
toNumericBase: 'hex',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
return addHexPrefix(priceEstimateToWei(value));
|
2018-08-16 14:28:27 +02:00
|
|
|
}
|
|
|
|
|
2020-11-04 17:14:08 +01:00
|
|
|
export function getRenderableGasButtonData(
|
|
|
|
estimates,
|
2020-11-03 00:41:28 +01:00
|
|
|
gasLimit,
|
2020-11-04 17:14:08 +01:00
|
|
|
showFiat,
|
|
|
|
conversionRate,
|
|
|
|
currentCurrency,
|
2021-03-29 21:30:06 +02:00
|
|
|
nativeCurrency,
|
2020-11-03 00:41:28 +01:00
|
|
|
) {
|
2021-07-16 18:06:32 +02:00
|
|
|
const { low, medium, high } = estimates;
|
2018-08-16 14:28:27 +02:00
|
|
|
|
2020-10-17 11:13:51 +02:00
|
|
|
const slowEstimateData = {
|
2020-10-12 18:51:17 +02:00
|
|
|
gasEstimateType: GAS_ESTIMATE_TYPES.SLOW,
|
2021-07-16 18:06:32 +02:00
|
|
|
feeInPrimaryCurrency: getRenderableEthFee(low, gasLimit, 9, nativeCurrency),
|
2020-10-12 18:51:17 +02:00
|
|
|
feeInSecondaryCurrency: showFiat
|
2020-11-03 00:41:28 +01:00
|
|
|
? getRenderableConvertedCurrencyFee(
|
2021-07-16 18:06:32 +02:00
|
|
|
low,
|
2020-11-03 00:41:28 +01:00
|
|
|
gasLimit,
|
|
|
|
currentCurrency,
|
|
|
|
conversionRate,
|
|
|
|
)
|
2020-10-12 18:51:17 +02:00
|
|
|
: '',
|
2021-07-16 18:06:32 +02:00
|
|
|
priceInHexWei: getGasPriceInHexWei(low),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-12 18:51:17 +02:00
|
|
|
const averageEstimateData = {
|
|
|
|
gasEstimateType: GAS_ESTIMATE_TYPES.AVERAGE,
|
2021-03-29 21:30:06 +02:00
|
|
|
feeInPrimaryCurrency: getRenderableEthFee(
|
2021-07-16 18:06:32 +02:00
|
|
|
medium,
|
2021-03-29 21:30:06 +02:00
|
|
|
gasLimit,
|
|
|
|
9,
|
|
|
|
nativeCurrency,
|
|
|
|
),
|
2020-10-12 18:51:17 +02:00
|
|
|
feeInSecondaryCurrency: showFiat
|
2020-11-03 00:41:28 +01:00
|
|
|
? getRenderableConvertedCurrencyFee(
|
2021-07-16 18:06:32 +02:00
|
|
|
medium,
|
2020-11-03 00:41:28 +01:00
|
|
|
gasLimit,
|
|
|
|
currentCurrency,
|
|
|
|
conversionRate,
|
|
|
|
)
|
2020-10-12 18:51:17 +02:00
|
|
|
: '',
|
2021-07-16 18:06:32 +02:00
|
|
|
priceInHexWei: getGasPriceInHexWei(medium),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-17 11:13:51 +02:00
|
|
|
const fastEstimateData = {
|
2020-10-12 18:51:17 +02:00
|
|
|
gasEstimateType: GAS_ESTIMATE_TYPES.FAST,
|
2021-03-29 21:30:06 +02:00
|
|
|
feeInPrimaryCurrency: getRenderableEthFee(
|
2021-07-16 18:06:32 +02:00
|
|
|
high,
|
2021-03-29 21:30:06 +02:00
|
|
|
gasLimit,
|
|
|
|
9,
|
|
|
|
nativeCurrency,
|
|
|
|
),
|
2020-10-12 18:51:17 +02:00
|
|
|
feeInSecondaryCurrency: showFiat
|
2020-11-03 00:41:28 +01:00
|
|
|
? getRenderableConvertedCurrencyFee(
|
2021-07-16 18:06:32 +02:00
|
|
|
high,
|
2020-11-03 00:41:28 +01:00
|
|
|
gasLimit,
|
|
|
|
currentCurrency,
|
|
|
|
conversionRate,
|
|
|
|
)
|
2020-10-12 18:51:17 +02:00
|
|
|
: '',
|
2021-07-16 18:06:32 +02:00
|
|
|
priceInHexWei: getGasPriceInHexWei(high),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-12 18:51:17 +02:00
|
|
|
|
2020-11-04 17:14:08 +01:00
|
|
|
return {
|
|
|
|
slowEstimateData,
|
|
|
|
averageEstimateData,
|
|
|
|
fastEstimateData,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-11-04 17:14:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getRenderableBasicEstimateData(state, gasLimit) {
|
|
|
|
if (getBasicGasEstimateLoadingStatus(state)) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return [];
|
2020-11-04 17:14:08 +01:00
|
|
|
}
|
|
|
|
|
2021-06-24 01:28:49 +02:00
|
|
|
const showFiat = getShouldShowFiat(state);
|
2021-02-04 19:15:23 +01:00
|
|
|
const { conversionRate } = state.metamask;
|
|
|
|
const currentCurrency = getCurrentCurrency(state);
|
2020-11-04 17:14:08 +01:00
|
|
|
|
|
|
|
const {
|
|
|
|
slowEstimateData,
|
|
|
|
averageEstimateData,
|
|
|
|
fastEstimateData,
|
|
|
|
} = getRenderableGasButtonData(
|
2021-07-16 18:06:32 +02:00
|
|
|
getGasFeeEstimates(state),
|
2020-11-04 17:14:08 +01:00
|
|
|
gasLimit,
|
|
|
|
showFiat,
|
|
|
|
conversionRate,
|
|
|
|
currentCurrency,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-04 17:14:08 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return [slowEstimateData, averageEstimateData, fastEstimateData];
|
2018-08-02 18:02:22 +02:00
|
|
|
}
|
2018-09-13 14:35:17 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getRenderableEstimateDataForSmallButtonsFromGWEI(state) {
|
2021-07-16 18:06:32 +02:00
|
|
|
if (getIsGasEstimatesFetched(state) === false) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return [];
|
2018-09-13 14:35:17 +02:00
|
|
|
}
|
2021-06-24 01:28:49 +02:00
|
|
|
const showFiat = getShouldShowFiat(state);
|
2020-11-03 00:41:28 +01:00
|
|
|
const gasLimit =
|
2021-06-23 23:35:25 +02:00
|
|
|
state.send.gas.gasLimit || getCustomGasLimit(state) || GAS_LIMITS.SIMPLE;
|
2021-02-04 19:15:23 +01:00
|
|
|
const { conversionRate } = state.metamask;
|
|
|
|
const currentCurrency = getCurrentCurrency(state);
|
2021-07-16 18:06:32 +02:00
|
|
|
const gasFeeEstimates = getGasFeeEstimates(state);
|
2018-09-13 14:35:17 +02:00
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
Use `AdvancedGasInputs` in `AdvancedTabContent` (#7186)
* Use `AdvancedGasInputs` in `AdvancedTabContent`
The `AdvancedGasInputs` component was originally extracted from the
`AdvancedTabContent` component, duplicating much of the rendering
logic. They have since evolved separately, with bugs being fixed in one
place but not the other.
The inputs and outputs expected weren't exactly the same, as the
`AdvancedGasInputs` component converts the input custom gas price and
limit, and it converts them both in the setter methods as well.
The `GasModalPageContainer` had to be adjusted to avoid converting
these values multiple times.
Both components dealt with input debouncing separately, both in less
than ideal ways. `AdvancedTabContent` didn't debounce either field, but
it did debounce the check for whether the gas limit field was below the
minimum value. So if a less-than-minimum value was set, it would be
propogated upwards and could be saved if the user clicked 'Save'
quickly enough. After a second delay it would snap back to the minimum
value. The `AdvancedGasInputs` component debounced both fields, but
it would replace any gas limit below the minimum with the minimum
value. This led to a problem where a brief pause during typing would
reset the field to 21000.
The `AdvancedGasInputs` approach was chosen, except that it was
updated to no longer change the gas limit if it was below the minimum.
Instead it displays an error. Parent components were checked to ensure
they would detect the error case of the gas limit being set too low,
and prevent the form submission in those cases. Of the three parents,
one had already dealt with it correctly, one needed to convert the
gas limit from hex first, and another needed the gas limit check added.
Closes #6872
* Cleanup send components
Empty README files have been removed, and a mistake in the index file
for the send page has been corrected. The Gas Slider component class
name was updated as well; it looks like it was originally created from
`AdvancedTabContent`, so it still had that class name.
2019-10-23 14:23:15 +02:00
|
|
|
gasEstimateType: GAS_ESTIMATE_TYPES.SLOW,
|
2019-02-26 19:30:41 +01:00
|
|
|
feeInSecondaryCurrency: showFiat
|
2020-11-03 00:41:28 +01:00
|
|
|
? getRenderableConvertedCurrencyFee(
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates.low,
|
2020-11-03 00:41:28 +01:00
|
|
|
gasLimit,
|
|
|
|
currentCurrency,
|
|
|
|
conversionRate,
|
|
|
|
)
|
2019-02-26 19:30:41 +01:00
|
|
|
: '',
|
2020-11-03 00:41:28 +01:00
|
|
|
feeInPrimaryCurrency: getRenderableEthFee(
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates.low,
|
2020-11-03 00:41:28 +01:00
|
|
|
gasLimit,
|
|
|
|
NUMBER_OF_DECIMALS_SM_BTNS,
|
|
|
|
),
|
2021-07-16 18:06:32 +02:00
|
|
|
priceInHexWei: getGasPriceInHexWei(gasFeeEstimates.low, true),
|
2018-09-13 14:35:17 +02:00
|
|
|
},
|
|
|
|
{
|
Use `AdvancedGasInputs` in `AdvancedTabContent` (#7186)
* Use `AdvancedGasInputs` in `AdvancedTabContent`
The `AdvancedGasInputs` component was originally extracted from the
`AdvancedTabContent` component, duplicating much of the rendering
logic. They have since evolved separately, with bugs being fixed in one
place but not the other.
The inputs and outputs expected weren't exactly the same, as the
`AdvancedGasInputs` component converts the input custom gas price and
limit, and it converts them both in the setter methods as well.
The `GasModalPageContainer` had to be adjusted to avoid converting
these values multiple times.
Both components dealt with input debouncing separately, both in less
than ideal ways. `AdvancedTabContent` didn't debounce either field, but
it did debounce the check for whether the gas limit field was below the
minimum value. So if a less-than-minimum value was set, it would be
propogated upwards and could be saved if the user clicked 'Save'
quickly enough. After a second delay it would snap back to the minimum
value. The `AdvancedGasInputs` component debounced both fields, but
it would replace any gas limit below the minimum with the minimum
value. This led to a problem where a brief pause during typing would
reset the field to 21000.
The `AdvancedGasInputs` approach was chosen, except that it was
updated to no longer change the gas limit if it was below the minimum.
Instead it displays an error. Parent components were checked to ensure
they would detect the error case of the gas limit being set too low,
and prevent the form submission in those cases. Of the three parents,
one had already dealt with it correctly, one needed to convert the
gas limit from hex first, and another needed the gas limit check added.
Closes #6872
* Cleanup send components
Empty README files have been removed, and a mistake in the index file
for the send page has been corrected. The Gas Slider component class
name was updated as well; it looks like it was originally created from
`AdvancedTabContent`, so it still had that class name.
2019-10-23 14:23:15 +02:00
|
|
|
gasEstimateType: GAS_ESTIMATE_TYPES.AVERAGE,
|
2019-02-26 19:30:41 +01:00
|
|
|
feeInSecondaryCurrency: showFiat
|
2020-11-03 00:41:28 +01:00
|
|
|
? getRenderableConvertedCurrencyFee(
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates.medium,
|
2020-11-03 00:41:28 +01:00
|
|
|
gasLimit,
|
|
|
|
currentCurrency,
|
|
|
|
conversionRate,
|
|
|
|
)
|
2019-02-26 19:30:41 +01:00
|
|
|
: '',
|
2020-11-03 00:41:28 +01:00
|
|
|
feeInPrimaryCurrency: getRenderableEthFee(
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates.medium,
|
2020-11-03 00:41:28 +01:00
|
|
|
gasLimit,
|
|
|
|
NUMBER_OF_DECIMALS_SM_BTNS,
|
|
|
|
),
|
2021-07-16 18:06:32 +02:00
|
|
|
priceInHexWei: getGasPriceInHexWei(gasFeeEstimates.medium, true),
|
2018-09-13 14:35:17 +02:00
|
|
|
},
|
|
|
|
{
|
Use `AdvancedGasInputs` in `AdvancedTabContent` (#7186)
* Use `AdvancedGasInputs` in `AdvancedTabContent`
The `AdvancedGasInputs` component was originally extracted from the
`AdvancedTabContent` component, duplicating much of the rendering
logic. They have since evolved separately, with bugs being fixed in one
place but not the other.
The inputs and outputs expected weren't exactly the same, as the
`AdvancedGasInputs` component converts the input custom gas price and
limit, and it converts them both in the setter methods as well.
The `GasModalPageContainer` had to be adjusted to avoid converting
these values multiple times.
Both components dealt with input debouncing separately, both in less
than ideal ways. `AdvancedTabContent` didn't debounce either field, but
it did debounce the check for whether the gas limit field was below the
minimum value. So if a less-than-minimum value was set, it would be
propogated upwards and could be saved if the user clicked 'Save'
quickly enough. After a second delay it would snap back to the minimum
value. The `AdvancedGasInputs` component debounced both fields, but
it would replace any gas limit below the minimum with the minimum
value. This led to a problem where a brief pause during typing would
reset the field to 21000.
The `AdvancedGasInputs` approach was chosen, except that it was
updated to no longer change the gas limit if it was below the minimum.
Instead it displays an error. Parent components were checked to ensure
they would detect the error case of the gas limit being set too low,
and prevent the form submission in those cases. Of the three parents,
one had already dealt with it correctly, one needed to convert the
gas limit from hex first, and another needed the gas limit check added.
Closes #6872
* Cleanup send components
Empty README files have been removed, and a mistake in the index file
for the send page has been corrected. The Gas Slider component class
name was updated as well; it looks like it was originally created from
`AdvancedTabContent`, so it still had that class name.
2019-10-23 14:23:15 +02:00
|
|
|
gasEstimateType: GAS_ESTIMATE_TYPES.FAST,
|
2019-02-26 19:30:41 +01:00
|
|
|
feeInSecondaryCurrency: showFiat
|
2020-11-03 00:41:28 +01:00
|
|
|
? getRenderableConvertedCurrencyFee(
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates.high,
|
2020-11-03 00:41:28 +01:00
|
|
|
gasLimit,
|
|
|
|
currentCurrency,
|
|
|
|
conversionRate,
|
|
|
|
)
|
2019-02-26 19:30:41 +01:00
|
|
|
: '',
|
2020-11-03 00:41:28 +01:00
|
|
|
feeInPrimaryCurrency: getRenderableEthFee(
|
2021-07-16 18:06:32 +02:00
|
|
|
gasFeeEstimates.high,
|
2020-11-03 00:41:28 +01:00
|
|
|
gasLimit,
|
|
|
|
NUMBER_OF_DECIMALS_SM_BTNS,
|
|
|
|
),
|
2021-07-16 18:06:32 +02:00
|
|
|
priceInHexWei: getGasPriceInHexWei(gasFeeEstimates.high, true),
|
2018-09-13 14:35:17 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2018-09-13 14:35:17 +02:00
|
|
|
}
|
2021-04-28 20:02:01 +02:00
|
|
|
|
|
|
|
export function getIsEthGasPriceFetched(state) {
|
2021-07-16 18:06:32 +02:00
|
|
|
const gasEstimateType = getGasEstimateType(state);
|
|
|
|
return (
|
|
|
|
gasEstimateType === GAS_FEE_CONTROLLER_ESTIMATE_TYPES.ETH_GASPRICE &&
|
|
|
|
getIsMainnet(state)
|
2021-04-28 20:02:01 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-06-30 20:26:34 +02:00
|
|
|
export function getIsCustomNetworkGasPriceFetched(state) {
|
2021-07-16 18:06:32 +02:00
|
|
|
const gasEstimateType = getGasEstimateType(state);
|
|
|
|
return (
|
|
|
|
gasEstimateType === GAS_FEE_CONTROLLER_ESTIMATE_TYPES.ETH_GASPRICE &&
|
|
|
|
!getIsMainnet(state)
|
2021-06-30 20:26:34 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-28 20:02:01 +02:00
|
|
|
export function getNoGasPriceFetched(state) {
|
2021-07-16 18:06:32 +02:00
|
|
|
const gasEstimateType = getGasEstimateType(state);
|
|
|
|
return gasEstimateType === GAS_FEE_CONTROLLER_ESTIMATE_TYPES.NONE;
|
2021-05-20 17:32:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getIsGasEstimatesFetched(state) {
|
2021-07-16 18:06:32 +02:00
|
|
|
const gasEstimateType = getGasEstimateType(state);
|
|
|
|
if (isEIP1559Network(state)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return gasEstimateType !== GAS_FEE_CONTROLLER_ESTIMATE_TYPES.NONE;
|
2021-04-28 20:02:01 +02:00
|
|
|
}
|