Only show dapp suggested gas fee warning if user has not edited the fee (#11621)

feature/default_network_editable
Dan J Miller 3 years ago committed by GitHub
parent 604524f94d
commit 9a81b826c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      ui/components/app/edit-gas-display/edit-gas-display.component.js
  2. 39
      ui/helpers/utils/confirm-tx.util.js

@ -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…
Cancel
Save