1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 11:46:13 +02:00
metamask-extension/ui/components/app/transaction-breakdown/transaction-breakdown.container.js

59 lines
2.0 KiB
JavaScript
Raw Normal View History

import { connect } from 'react-redux';
import { getShouldShowFiat } from '../../../selectors';
import {
getNativeCurrency,
isEIP1559Network,
} 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 TransactionBreakdown from './transaction-breakdown.component';
const mapStateToProps = (state, ownProps) => {
const { transaction, isTokenApprove } = ownProps;
2020-11-03 00:41:28 +01:00
const {
txParams: { gas, gasPrice, value } = {},
txReceipt: { gasUsed, effectiveGasPrice } = {},
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;
2020-11-03 00:41:28 +01:00
const hexGasTotal =
(gasLimit &&
usedGasPrice &&
getHexGasTotal({ gasLimit, gasPrice: usedGasPrice })) ||
'0x0';
const totalInHex = sumHexes(hexGasTotal, value);
const supportsEIP1559 = isEIP1559Network(state);
return {
nativeCurrency: getNativeCurrency(state),
showFiat: getShouldShowFiat(state),
totalInHex,
gas,
gasPrice,
gasUsed,
isTokenApprove,
effectiveGasPrice,
hexGasTotal,
priorityFee,
baseFee: baseFeePerGas,
supportsEIP1559,
};
};
export default connect(mapStateToProps)(TransactionBreakdown);