1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-11 20:27:12 +01:00
metamask-extension/ui/components/app/transaction-breakdown/transaction-breakdown.component.js

122 lines
3.8 KiB
JavaScript
Raw Normal View History

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';
2018-08-31 21:36:07 +02:00
export default class TransactionBreakdown extends PureComponent {
static contextTypes = {
t: PropTypes.func,
};
2018-08-31 21:36:07 +02:00
static propTypes = {
className: PropTypes.string,
nativeCurrency: PropTypes.string,
showFiat: PropTypes.bool,
nonce: PropTypes.string,
primaryCurrency: PropTypes.string,
isTokenApprove: PropTypes.bool,
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]),
};
2018-08-31 21:36:07 +02:00
static defaultProps = {
showFiat: true,
};
2018-08-31 21:36:07 +02:00
2020-11-03 00:41:28 +01:00
render() {
const { t } = this.context;
2020-11-03 00:41:28 +01:00
const {
gas,
gasPrice,
primaryCurrency,
className,
nonce,
nativeCurrency,
showFiat,
totalInHex,
gasUsed,
isTokenApprove,
} = 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>
<TransactionBreakdownRow title="Nonce">
2020-11-03 00:41:28 +01:00
{typeof nonce === 'undefined' ? null : (
<HexToDecimal
className="transaction-breakdown__value"
value={nonce}
/>
)}
</TransactionBreakdownRow>
<TransactionBreakdownRow
2020-11-03 00:41:28 +01:00
title={isTokenApprove ? t('spendLimitAmount') : t('amount')}
>
2020-11-03 00:41:28 +01:00
<span className="transaction-breakdown__value">
{primaryCurrency}
</span>
2018-12-09 21:48:06 +01:00
</TransactionBreakdownRow>
<TransactionBreakdownRow
title={`${t('gasLimit')} (${t('units')})`}
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>
)}
2018-12-09 21:48:06 +01:00
<TransactionBreakdownRow title={t('gasPrice')}>
2020-11-03 00:41:28 +01:00
{typeof gasPrice === 'undefined' ? (
'?'
) : (
<CurrencyDisplay
className="transaction-breakdown__value"
data-testid="transaction-breakdown__gas-price"
currency={nativeCurrency}
denomination={GWEI}
value={gasPrice}
hideLabel
/>
)}
2018-12-09 21:48:06 +01:00
</TransactionBreakdownRow>
<TransactionBreakdownRow title={t('total')}>
<div>
<UserPreferencedCurrencyDisplay
2018-12-09 21:48:06 +01:00
className="transaction-breakdown__value transaction-breakdown__value--eth-total"
type={PRIMARY}
2018-12-09 21:48:06 +01:00
value={totalInHex}
2018-08-31 21:36:07 +02:00
/>
2020-11-03 00:41:28 +01:00
{showFiat && (
<UserPreferencedCurrencyDisplay
className="transaction-breakdown__value"
type={SECONDARY}
value={totalInHex}
/>
)}
2018-12-09 21:48:06 +01:00
</div>
</TransactionBreakdownRow>
2018-08-31 21:36:07 +02:00
</div>
);
2018-08-31 21:36:07 +02:00
}
}