mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Only show dapp suggested gas fee warning if user has not edited the fee (#11621)
This commit is contained in:
parent
604524f94d
commit
9a81b826c5
@ -14,6 +14,7 @@ import {
|
||||
FONT_WEIGHT,
|
||||
TEXT_ALIGN,
|
||||
} from '../../../helpers/constants/design-system';
|
||||
import { areDappSuggestedAndTxParamGasFeesTheSame } from '../../../helpers/utils/confirm-tx.util';
|
||||
|
||||
import InfoTooltip from '../../ui/info-tooltip';
|
||||
import TransactionTotalBanner from '../transaction-total-banner/transaction-total-banner.component';
|
||||
@ -61,8 +62,14 @@ export default function EditGasDisplay({
|
||||
|
||||
const alwaysShowForm = !estimateToUse || hasGasErrors || false;
|
||||
|
||||
const dappSuggestedAndTxParamGasFeesAreTheSame = areDappSuggestedAndTxParamGasFeesTheSame(
|
||||
transaction,
|
||||
);
|
||||
|
||||
const requireDappAcknowledgement = Boolean(
|
||||
transaction?.dappSuggestedGasFees && !dappSuggestedGasFeeAcknowledged,
|
||||
transaction?.dappSuggestedGasFees &&
|
||||
!dappSuggestedGasFeeAcknowledged &&
|
||||
dappSuggestedAndTxParamGasFeesAreTheSame,
|
||||
);
|
||||
|
||||
return (
|
||||
|
@ -148,3 +148,42 @@ export function roundExponential(decimalString) {
|
||||
? bigNumberValue.toPrecision(PRECISION)
|
||||
: decimalString;
|
||||
}
|
||||
|
||||
export function areDappSuggestedAndTxParamGasFeesTheSame(txData = {}) {
|
||||
const { txParams, dappSuggestedGasFees } = txData;
|
||||
const {
|
||||
gasPrice: txParamsGasPrice,
|
||||
maxFeePerGas: txParamsMaxFeePerGas,
|
||||
maxPriorityFeePerGas: txParamsMaxPriorityFeePerGas,
|
||||
} = txParams || {};
|
||||
const {
|
||||
gasPrice: dappGasPrice,
|
||||
maxFeePerGas: dappMaxFeePerGas,
|
||||
maxPriorityFeePerGas: dappMaxPriorityFeePerGas,
|
||||
} = dappSuggestedGasFees || {};
|
||||
|
||||
const txParamsDoesNotHaveFeeProperties =
|
||||
!txParamsGasPrice && !txParamsMaxFeePerGas && !txParamsMaxPriorityFeePerGas;
|
||||
const dappDidNotSuggestFeeProperties =
|
||||
!dappGasPrice && !dappMaxFeePerGas && !dappMaxPriorityFeePerGas;
|
||||
if (txParamsDoesNotHaveFeeProperties || dappDidNotSuggestFeeProperties) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const txParamsGasPriceMatchesDappSuggestedGasPrice =
|
||||
txParamsGasPrice && txParamsGasPrice === dappGasPrice;
|
||||
const txParamsEIP1559FeesMatchDappSuggestedGasPrice = [
|
||||
txParamsMaxFeePerGas,
|
||||
txParamsMaxPriorityFeePerGas,
|
||||
].every((fee) => fee === dappGasPrice);
|
||||
const txParamsEIP1559FeesMatchDappSuggestedEIP1559Fees =
|
||||
txParamsMaxFeePerGas &&
|
||||
txParamsMaxFeePerGas === dappMaxFeePerGas &&
|
||||
txParamsMaxPriorityFeePerGas === dappMaxPriorityFeePerGas;
|
||||
|
||||
return (
|
||||
txParamsGasPriceMatchesDappSuggestedGasPrice ||
|
||||
txParamsEIP1559FeesMatchDappSuggestedGasPrice ||
|
||||
txParamsEIP1559FeesMatchDappSuggestedEIP1559Fees
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user