mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-05 15:35:46 +01:00
9fa15dda6f
* Support for Layer 2 networks with transaction fees on both layers * Use variable name in transaction-breakdown * Add comment on code source to ui/helpers/utils/optimism/fetchEstimatedL1Fee.js * Fix unit tests * Ensure values passed to are defined * Fix activity log
69 lines
2.3 KiB
JavaScript
69 lines
2.3 KiB
JavaScript
import { connect } from 'react-redux';
|
|
import {
|
|
getShouldShowFiat,
|
|
getIsMultiLayerFeeNetwork,
|
|
} from '../../../selectors';
|
|
import { getNativeCurrency } from '../../../ducks/metamask/metamask';
|
|
import { getHexGasTotal } from '../../../helpers/utils/confirm-tx.util';
|
|
import { subtractHexes } from '../../../helpers/utils/conversions.util';
|
|
import { sumHexes } from '../../../helpers/utils/transactions.util';
|
|
import { isEIP1559Transaction } from '../../../../shared/modules/transaction.utils';
|
|
|
|
import TransactionBreakdown from './transaction-breakdown.component';
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
const { transaction, isTokenApprove } = ownProps;
|
|
const {
|
|
txParams: { gas, gasPrice, maxFeePerGas, value } = {},
|
|
txReceipt: { gasUsed, effectiveGasPrice, l1Fee: l1HexGasTotal } = {},
|
|
baseFeePerGas,
|
|
} = transaction;
|
|
|
|
const gasLimit = typeof gasUsed === 'string' ? gasUsed : gas;
|
|
|
|
const priorityFee =
|
|
effectiveGasPrice &&
|
|
baseFeePerGas &&
|
|
subtractHexes(effectiveGasPrice, baseFeePerGas);
|
|
|
|
// To calculate the total cost of the transaction, we use gasPrice if it is in the txParam,
|
|
// which will only be the case on non-EIP1559 networks. If it is not in the params, we can
|
|
// use the effectiveGasPrice from the receipt, which will ultimately represent to true cost
|
|
// of the transaction. Either of these are used the same way with gasLimit to calculate total
|
|
// cost. effectiveGasPrice will be available on the txReciept for all EIP1559 networks
|
|
const usedGasPrice = gasPrice || effectiveGasPrice;
|
|
const hexGasTotal =
|
|
(gasLimit &&
|
|
usedGasPrice &&
|
|
getHexGasTotal({ gasLimit, gasPrice: usedGasPrice })) ||
|
|
'0x0';
|
|
|
|
let totalInHex = sumHexes(hexGasTotal, value);
|
|
|
|
const isMultiLayerFeeNetwork =
|
|
getIsMultiLayerFeeNetwork(state) && l1HexGasTotal !== undefined;
|
|
|
|
if (isMultiLayerFeeNetwork) {
|
|
totalInHex = sumHexes(totalInHex, l1HexGasTotal);
|
|
}
|
|
|
|
return {
|
|
nativeCurrency: getNativeCurrency(state),
|
|
showFiat: getShouldShowFiat(state),
|
|
totalInHex,
|
|
gas,
|
|
gasPrice,
|
|
maxFeePerGas,
|
|
gasUsed,
|
|
isTokenApprove,
|
|
hexGasTotal,
|
|
priorityFee,
|
|
baseFee: baseFeePerGas,
|
|
isEIP1559Transaction: isEIP1559Transaction(transaction),
|
|
isMultiLayerFeeNetwork,
|
|
l1HexGasTotal,
|
|
};
|
|
};
|
|
|
|
export default connect(mapStateToProps)(TransactionBreakdown);
|