You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.8 KiB
122 lines
3.8 KiB
4 years ago
|
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';
|
||
|
import { GWEI, PRIMARY, SECONDARY } from '../../../helpers/constants/common';
|
||
|
import TransactionBreakdownRow from './transaction-breakdown-row';
|
||
6 years ago
|
|
||
|
export default class TransactionBreakdown extends PureComponent {
|
||
|
static contextTypes = {
|
||
|
t: PropTypes.func,
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
|
static propTypes = {
|
||
|
className: PropTypes.string,
|
||
5 years ago
|
nativeCurrency: PropTypes.string,
|
||
6 years ago
|
showFiat: PropTypes.bool,
|
||
5 years ago
|
nonce: PropTypes.string,
|
||
4 years ago
|
primaryCurrency: PropTypes.string,
|
||
|
isTokenApprove: PropTypes.bool,
|
||
6 years ago
|
gas: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||
|
gasPrice: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||
|
gasUsed: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||
|
totalInHex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
|
static defaultProps = {
|
||
6 years ago
|
showFiat: true,
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
4 years ago
|
render() {
|
||
4 years ago
|
const { t } = this.context;
|
||
4 years ago
|
const {
|
||
|
gas,
|
||
|
gasPrice,
|
||
|
primaryCurrency,
|
||
|
className,
|
||
|
nonce,
|
||
|
nativeCurrency,
|
||
|
showFiat,
|
||
|
totalInHex,
|
||
|
gasUsed,
|
||
|
isTokenApprove,
|
||
4 years ago
|
} = this.props;
|
||
6 years ago
|
return (
|
||
|
<div className={classnames('transaction-breakdown', className)}>
|
||
4 years ago
|
<div className="transaction-breakdown__title">{t('transaction')}</div>
|
||
5 years ago
|
<TransactionBreakdownRow title="Nonce">
|
||
4 years ago
|
{typeof nonce === 'undefined' ? null : (
|
||
|
<HexToDecimal
|
||
|
className="transaction-breakdown__value"
|
||
|
value={nonce}
|
||
|
/>
|
||
|
)}
|
||
5 years ago
|
</TransactionBreakdownRow>
|
||
4 years ago
|
<TransactionBreakdownRow
|
||
4 years ago
|
title={isTokenApprove ? t('spendLimitAmount') : t('amount')}
|
||
4 years ago
|
>
|
||
4 years ago
|
<span className="transaction-breakdown__value">
|
||
|
{primaryCurrency}
|
||
|
</span>
|
||
6 years ago
|
</TransactionBreakdownRow>
|
||
|
<TransactionBreakdownRow
|
||
|
title={`${t('gasLimit')} (${t('units')})`}
|
||
|
className="transaction-breakdown__row-title"
|
||
6 years ago
|
>
|
||
4 years ago
|
{typeof gas === 'undefined' ? (
|
||
|
'?'
|
||
|
) : (
|
||
|
<HexToDecimal
|
||
|
className="transaction-breakdown__value"
|
||
|
value={gas}
|
||
|
/>
|
||
|
)}
|
||
6 years ago
|
</TransactionBreakdownRow>
|
||
4 years ago
|
{typeof gasUsed === 'string' && (
|
||
|
<TransactionBreakdownRow
|
||
|
title={`${t('gasUsed')} (${t('units')})`}
|
||
|
className="transaction-breakdown__row-title"
|
||
|
>
|
||
|
<HexToDecimal
|
||
|
className="transaction-breakdown__value"
|
||
|
value={gasUsed}
|
||
|
/>
|
||
|
</TransactionBreakdownRow>
|
||
|
)}
|
||
6 years ago
|
<TransactionBreakdownRow title={t('gasPrice')}>
|
||
4 years ago
|
{typeof gasPrice === 'undefined' ? (
|
||
|
'?'
|
||
|
) : (
|
||
|
<CurrencyDisplay
|
||
|
className="transaction-breakdown__value"
|
||
|
data-testid="transaction-breakdown__gas-price"
|
||
|
currency={nativeCurrency}
|
||
|
denomination={GWEI}
|
||
|
value={gasPrice}
|
||
|
hideLabel
|
||
|
/>
|
||
|
)}
|
||
6 years ago
|
</TransactionBreakdownRow>
|
||
|
<TransactionBreakdownRow title={t('total')}>
|
||
|
<div>
|
||
6 years ago
|
<UserPreferencedCurrencyDisplay
|
||
6 years ago
|
className="transaction-breakdown__value transaction-breakdown__value--eth-total"
|
||
6 years ago
|
type={PRIMARY}
|
||
6 years ago
|
value={totalInHex}
|
||
6 years ago
|
/>
|
||
4 years ago
|
{showFiat && (
|
||
|
<UserPreferencedCurrencyDisplay
|
||
|
className="transaction-breakdown__value"
|
||
|
type={SECONDARY}
|
||
|
value={totalInHex}
|
||
|
/>
|
||
|
)}
|
||
6 years ago
|
</div>
|
||
|
</TransactionBreakdownRow>
|
||
6 years ago
|
</div>
|
||
4 years ago
|
);
|
||
6 years ago
|
}
|
||
|
}
|