2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
2021-06-24 01:28:49 +02:00
|
|
|
import { getShouldShowFiat } from '../../../selectors';
|
2021-07-31 03:29:21 +02:00
|
|
|
import { getNativeCurrency } from '../../../ducks/metamask/metamask';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { getHexGasTotal } from '../../../helpers/utils/confirm-tx.util';
|
2021-07-28 19:30:34 +02:00
|
|
|
import { subtractHexes } from '../../../helpers/utils/conversions.util';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { sumHexes } from '../../../helpers/utils/transactions.util';
|
2021-07-31 03:29:21 +02:00
|
|
|
import { isEIP1559Transaction } from '../../../../shared/modules/transaction.utils';
|
2021-02-04 19:15:23 +01:00
|
|
|
import TransactionBreakdown from './transaction-breakdown.component';
|
2018-10-26 10:26:43 +02:00
|
|
|
|
2019-03-06 19:14:53 +01:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2021-03-10 21:16:44 +01:00
|
|
|
const { transaction, isTokenApprove } = ownProps;
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
2021-09-08 20:06:16 +02:00
|
|
|
txParams: { gas, gasPrice, maxFeePerGas, value } = {},
|
2021-07-28 19:30:34 +02:00
|
|
|
txReceipt: { gasUsed, effectiveGasPrice } = {},
|
|
|
|
baseFeePerGas,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = transaction;
|
2019-02-26 19:30:41 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const gasLimit = typeof gasUsed === 'string' ? gasUsed : gas;
|
2019-03-06 19:14:53 +01:00
|
|
|
|
2021-07-28 19:30:34 +02:00
|
|
|
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 =
|
2021-07-28 19:30:34 +02:00
|
|
|
(gasLimit &&
|
|
|
|
usedGasPrice &&
|
|
|
|
getHexGasTotal({ gasLimit, gasPrice: usedGasPrice })) ||
|
|
|
|
'0x0';
|
2021-02-04 19:15:23 +01:00
|
|
|
const totalInHex = sumHexes(hexGasTotal, value);
|
2019-03-06 19:14:53 +01:00
|
|
|
|
2018-10-26 10:26:43 +02:00
|
|
|
return {
|
|
|
|
nativeCurrency: getNativeCurrency(state),
|
2021-06-24 01:28:49 +02:00
|
|
|
showFiat: getShouldShowFiat(state),
|
2019-03-06 19:14:53 +01:00
|
|
|
totalInHex,
|
|
|
|
gas,
|
|
|
|
gasPrice,
|
2021-09-08 20:06:16 +02:00
|
|
|
maxFeePerGas,
|
2019-03-06 19:14:53 +01:00
|
|
|
gasUsed,
|
2020-10-09 22:11:39 +02:00
|
|
|
isTokenApprove,
|
2021-07-28 19:30:34 +02:00
|
|
|
hexGasTotal,
|
|
|
|
priorityFee,
|
|
|
|
baseFee: baseFeePerGas,
|
2021-07-31 03:29:21 +02:00
|
|
|
isEIP1559Transaction: isEIP1559Transaction(transaction),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-10-26 10:26:43 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default connect(mapStateToProps)(TransactionBreakdown);
|