2021-02-04 19:15:23 +01:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import CurrencyDisplay from '../../ui/currency-display';
|
|
|
|
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display';
|
|
|
|
import HexToDecimal from '../../ui/hex-to-decimal';
|
2023-01-25 16:47:02 +01:00
|
|
|
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
|
|
|
|
import { EtherDenomination } from '../../../../shared/constants/common';
|
2021-02-04 19:15:23 +01:00
|
|
|
import TransactionBreakdownRow from './transaction-breakdown-row';
|
2018-08-31 21:36:07 +02:00
|
|
|
|
|
|
|
export default class TransactionBreakdown extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-31 21:36:07 +02:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
className: PropTypes.string,
|
2020-01-16 22:49:38 +01:00
|
|
|
nativeCurrency: PropTypes.string,
|
2019-02-26 19:30:41 +01:00
|
|
|
showFiat: PropTypes.bool,
|
2020-06-02 00:19:49 +02:00
|
|
|
nonce: PropTypes.string,
|
2020-10-09 22:11:39 +02:00
|
|
|
primaryCurrency: PropTypes.string,
|
|
|
|
isTokenApprove: PropTypes.bool,
|
2019-03-06 19:14:53 +01:00
|
|
|
gas: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
|
|
gasPrice: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
2021-09-08 20:06:16 +02:00
|
|
|
maxFeePerGas: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
2019-03-06 19:14:53 +01:00
|
|
|
gasUsed: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
|
|
totalInHex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
2021-07-13 15:42:36 +02:00
|
|
|
baseFee: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
|
|
priorityFee: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
2021-07-28 19:30:34 +02:00
|
|
|
hexGasTotal: PropTypes.string,
|
2021-07-31 03:29:21 +02:00
|
|
|
isEIP1559Transaction: PropTypes.bool,
|
2021-11-11 17:46:45 +01:00
|
|
|
isMultiLayerFeeNetwork: PropTypes.bool,
|
|
|
|
l1HexGasTotal: PropTypes.string,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-31 21:36:07 +02:00
|
|
|
|
|
|
|
static defaultProps = {
|
2019-02-26 19:30:41 +01:00
|
|
|
showFiat: true,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-31 21:36:07 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
gas,
|
|
|
|
gasPrice,
|
2021-09-08 20:06:16 +02:00
|
|
|
maxFeePerGas,
|
2020-11-03 00:41:28 +01:00
|
|
|
primaryCurrency,
|
|
|
|
className,
|
|
|
|
nonce,
|
|
|
|
nativeCurrency,
|
|
|
|
showFiat,
|
|
|
|
totalInHex,
|
|
|
|
gasUsed,
|
|
|
|
isTokenApprove,
|
2021-07-13 15:42:36 +02:00
|
|
|
baseFee,
|
|
|
|
priorityFee,
|
2021-07-28 19:30:34 +02:00
|
|
|
hexGasTotal,
|
2021-07-31 03:29:21 +02:00
|
|
|
isEIP1559Transaction,
|
2021-11-11 17:46:45 +01:00
|
|
|
isMultiLayerFeeNetwork,
|
|
|
|
l1HexGasTotal,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2018-08-31 21:36:07 +02:00
|
|
|
return (
|
|
|
|
<div className={classnames('transaction-breakdown', className)}>
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="transaction-breakdown__title">{t('transaction')}</div>
|
2021-12-01 18:22:08 +01:00
|
|
|
<TransactionBreakdownRow divider title={t('nonce')}>
|
2020-11-03 00:41:28 +01:00
|
|
|
{typeof nonce === 'undefined' ? null : (
|
|
|
|
<HexToDecimal
|
|
|
|
className="transaction-breakdown__value"
|
|
|
|
value={nonce}
|
|
|
|
/>
|
|
|
|
)}
|
2020-06-02 00:19:49 +02:00
|
|
|
</TransactionBreakdownRow>
|
2020-10-09 22:11:39 +02:00
|
|
|
<TransactionBreakdownRow
|
2023-01-25 16:15:58 +01:00
|
|
|
title={isTokenApprove ? t('spendingCap') : t('amount')}
|
2020-10-09 22:11:39 +02:00
|
|
|
>
|
2023-06-15 20:17:21 +02:00
|
|
|
<span
|
|
|
|
className="transaction-breakdown__value transaction-breakdown__value--amount"
|
|
|
|
data-testid="transaction-breakdown-value-amount"
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{primaryCurrency}
|
|
|
|
</span>
|
2018-12-09 21:48:06 +01:00
|
|
|
</TransactionBreakdownRow>
|
|
|
|
<TransactionBreakdownRow
|
2021-11-11 17:46:45 +01:00
|
|
|
title={
|
|
|
|
isMultiLayerFeeNetwork
|
|
|
|
? t('transactionHistoryL2GasLimitLabel')
|
|
|
|
: `${t('gasLimit')} (${t('units')})`
|
|
|
|
}
|
2018-12-09 21:48:06 +01:00
|
|
|
className="transaction-breakdown__row-title"
|
2018-08-31 21:36:07 +02:00
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{typeof gas === 'undefined' ? (
|
|
|
|
'?'
|
|
|
|
) : (
|
|
|
|
<HexToDecimal
|
|
|
|
className="transaction-breakdown__value"
|
|
|
|
value={gas}
|
|
|
|
/>
|
|
|
|
)}
|
2018-12-09 21:48:06 +01:00
|
|
|
</TransactionBreakdownRow>
|
2020-11-03 00:41:28 +01:00
|
|
|
{typeof gasUsed === 'string' && (
|
|
|
|
<TransactionBreakdownRow
|
|
|
|
title={`${t('gasUsed')} (${t('units')})`}
|
|
|
|
className="transaction-breakdown__row-title"
|
|
|
|
>
|
|
|
|
<HexToDecimal
|
|
|
|
className="transaction-breakdown__value"
|
|
|
|
value={gasUsed}
|
|
|
|
/>
|
|
|
|
</TransactionBreakdownRow>
|
|
|
|
)}
|
2021-09-15 23:42:06 +02:00
|
|
|
{isEIP1559Transaction && typeof baseFee !== 'undefined' ? (
|
2021-07-13 15:42:36 +02:00
|
|
|
<TransactionBreakdownRow title={t('transactionHistoryBaseFee')}>
|
2021-09-15 23:42:06 +02:00
|
|
|
<CurrencyDisplay
|
|
|
|
className="transaction-breakdown__value"
|
|
|
|
data-testid="transaction-breakdown__base-fee"
|
|
|
|
currency={nativeCurrency}
|
2023-01-25 16:47:02 +01:00
|
|
|
denomination={EtherDenomination.GWEI}
|
2021-09-15 23:42:06 +02:00
|
|
|
value={baseFee}
|
|
|
|
numberOfDecimals={10}
|
|
|
|
hideLabel
|
|
|
|
/>
|
2021-07-13 15:42:36 +02:00
|
|
|
</TransactionBreakdownRow>
|
2021-09-15 23:42:06 +02:00
|
|
|
) : null}
|
|
|
|
{isEIP1559Transaction && typeof priorityFee !== 'undefined' ? (
|
2021-07-13 15:42:36 +02:00
|
|
|
<TransactionBreakdownRow title={t('transactionHistoryPriorityFee')}>
|
2021-09-15 23:42:06 +02:00
|
|
|
<CurrencyDisplay
|
|
|
|
className="transaction-breakdown__value"
|
|
|
|
data-testid="transaction-breakdown__priority-fee"
|
|
|
|
currency={nativeCurrency}
|
2023-01-25 16:47:02 +01:00
|
|
|
denomination={EtherDenomination.GWEI}
|
2021-09-15 23:42:06 +02:00
|
|
|
value={priorityFee}
|
|
|
|
numberOfDecimals={10}
|
|
|
|
hideLabel
|
|
|
|
/>
|
2021-07-13 15:42:36 +02:00
|
|
|
</TransactionBreakdownRow>
|
2021-09-15 23:42:06 +02:00
|
|
|
) : null}
|
2021-07-31 03:29:21 +02:00
|
|
|
{!isEIP1559Transaction && (
|
2021-11-11 17:46:45 +01:00
|
|
|
<TransactionBreakdownRow
|
|
|
|
title={
|
|
|
|
isMultiLayerFeeNetwork
|
|
|
|
? t('transactionHistoryL2GasPriceLabel')
|
|
|
|
: t('advancedGasPriceTitle')
|
|
|
|
}
|
|
|
|
>
|
2021-07-13 15:42:36 +02:00
|
|
|
{typeof gasPrice === 'undefined' ? (
|
|
|
|
'?'
|
|
|
|
) : (
|
|
|
|
<CurrencyDisplay
|
|
|
|
className="transaction-breakdown__value"
|
|
|
|
data-testid="transaction-breakdown__gas-price"
|
|
|
|
currency={nativeCurrency}
|
2023-01-25 16:47:02 +01:00
|
|
|
denomination={EtherDenomination.GWEI}
|
2021-07-13 15:42:36 +02:00
|
|
|
value={gasPrice}
|
2021-08-05 00:10:29 +02:00
|
|
|
numberOfDecimals={9}
|
2021-07-13 15:42:36 +02:00
|
|
|
hideLabel
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</TransactionBreakdownRow>
|
|
|
|
)}
|
2021-07-31 03:29:21 +02:00
|
|
|
{isEIP1559Transaction && (
|
2021-08-04 15:22:54 +02:00
|
|
|
<TransactionBreakdownRow title={t('transactionHistoryTotalGasFee')}>
|
2021-07-13 15:42:36 +02:00
|
|
|
<UserPreferencedCurrencyDisplay
|
2020-11-03 00:41:28 +01:00
|
|
|
className="transaction-breakdown__value"
|
2021-07-28 19:30:34 +02:00
|
|
|
data-testid="transaction-breakdown__effective-gas-price"
|
|
|
|
currency={nativeCurrency}
|
2023-01-25 16:47:02 +01:00
|
|
|
denomination={EtherDenomination.ETH}
|
2021-07-28 19:30:34 +02:00
|
|
|
numberOfDecimals={6}
|
|
|
|
value={hexGasTotal}
|
|
|
|
type={PRIMARY}
|
2020-11-03 00:41:28 +01:00
|
|
|
/>
|
2021-07-28 19:30:34 +02:00
|
|
|
{showFiat && (
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
className="transaction-breakdown__value"
|
|
|
|
type={SECONDARY}
|
|
|
|
value={hexGasTotal}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</TransactionBreakdownRow>
|
|
|
|
)}
|
2021-09-08 20:06:16 +02:00
|
|
|
{isEIP1559Transaction && (
|
2021-12-01 18:22:08 +01:00
|
|
|
<TransactionBreakdownRow
|
|
|
|
divider
|
|
|
|
title={t('transactionHistoryMaxFeePerGas')}
|
|
|
|
>
|
2021-09-08 20:06:16 +02:00
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
className="transaction-breakdown__value"
|
|
|
|
currency={nativeCurrency}
|
2023-01-25 16:47:02 +01:00
|
|
|
denomination={EtherDenomination.ETH}
|
2021-09-08 20:06:16 +02:00
|
|
|
numberOfDecimals={9}
|
|
|
|
value={maxFeePerGas}
|
|
|
|
type={PRIMARY}
|
|
|
|
/>
|
|
|
|
{showFiat && (
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
className="transaction-breakdown__value"
|
|
|
|
type={SECONDARY}
|
|
|
|
value={maxFeePerGas}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</TransactionBreakdownRow>
|
|
|
|
)}
|
2021-11-11 17:46:45 +01:00
|
|
|
{isMultiLayerFeeNetwork && (
|
|
|
|
<TransactionBreakdownRow title={t('transactionHistoryL1GasLabel')}>
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
className="transaction-breakdown__value"
|
|
|
|
data-testid="transaction-breakdown__l1-gas-total"
|
|
|
|
numberOfDecimals={18}
|
|
|
|
value={l1HexGasTotal}
|
|
|
|
type={PRIMARY}
|
|
|
|
/>
|
|
|
|
{showFiat && (
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
className="transaction-breakdown__value"
|
|
|
|
type={SECONDARY}
|
|
|
|
value={l1HexGasTotal}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</TransactionBreakdownRow>
|
|
|
|
)}
|
2018-12-09 21:48:06 +01:00
|
|
|
<TransactionBreakdownRow title={t('total')}>
|
2021-07-13 15:42:36 +02:00
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
className="transaction-breakdown__value transaction-breakdown__value--eth-total"
|
|
|
|
type={PRIMARY}
|
|
|
|
value={totalInHex}
|
2021-11-11 17:46:45 +01:00
|
|
|
numberOfDecimals={isMultiLayerFeeNetwork ? 18 : null}
|
2021-07-13 15:42:36 +02:00
|
|
|
/>
|
|
|
|
{showFiat && (
|
2018-10-17 01:03:29 +02:00
|
|
|
<UserPreferencedCurrencyDisplay
|
2021-07-13 15:42:36 +02:00
|
|
|
className="transaction-breakdown__value"
|
|
|
|
type={SECONDARY}
|
2018-12-09 21:48:06 +01:00
|
|
|
value={totalInHex}
|
2018-08-31 21:36:07 +02:00
|
|
|
/>
|
2021-07-13 15:42:36 +02:00
|
|
|
)}
|
2018-12-09 21:48:06 +01:00
|
|
|
</TransactionBreakdownRow>
|
2018-08-31 21:36:07 +02:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-08-31 21:36:07 +02:00
|
|
|
}
|
|
|
|
}
|