1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/app/components/app/transaction-breakdown/transaction-breakdown.component.js
Mark Stacey 171704d980
Fix gas price intermittent test failure (#8728)
The "the transaction has the expected gas price" test was assuming the
fifth element with the `transaction-breakdown__value` class was the
element with the gas price. In practice that was sometimes not the
case, because some transaction detail fields would not be present, or
would appear after the first render.

The field is now looked up with a test id, ensuring it always finds the
correct field.
2020-06-03 10:54:55 -03:00

120 lines
3.9 KiB
JavaScript

import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import TransactionBreakdownRow from './transaction-breakdown-row'
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'
export default class TransactionBreakdown extends PureComponent {
static contextTypes = {
t: PropTypes.func,
}
static propTypes = {
className: PropTypes.string,
nativeCurrency: PropTypes.string,
showFiat: PropTypes.bool,
nonce: PropTypes.string,
gas: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
gasPrice: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
gasUsed: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
totalInHex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
}
static defaultProps = {
showFiat: true,
}
render () {
const { t } = this.context
const { gas, gasPrice, value, className, nonce, nativeCurrency, showFiat, totalInHex, gasUsed } = this.props
return (
<div className={classnames('transaction-breakdown', className)}>
<div className="transaction-breakdown__title">
{ t('transaction') }
</div>
<TransactionBreakdownRow title="Nonce">
{typeof nonce !== 'undefined'
? (
<HexToDecimal
className="transaction-breakdown__value"
value={nonce}
/>
) : null
}
</TransactionBreakdownRow>
<TransactionBreakdownRow title={t('amount')}>
<UserPreferencedCurrencyDisplay
className="transaction-breakdown__value"
type={PRIMARY}
value={value}
/>
</TransactionBreakdownRow>
<TransactionBreakdownRow
title={`${t('gasLimit')} (${t('units')})`}
className="transaction-breakdown__row-title"
>
{typeof gas !== 'undefined'
? (
<HexToDecimal
className="transaction-breakdown__value"
value={gas}
/>
)
: '?'
}
</TransactionBreakdownRow>
{
typeof gasUsed === 'string' && (
<TransactionBreakdownRow
title={`${t('gasUsed')} (${t('units')})`}
className="transaction-breakdown__row-title"
>
<HexToDecimal
className="transaction-breakdown__value"
value={gasUsed}
/>
</TransactionBreakdownRow>
)
}
<TransactionBreakdownRow title={t('gasPrice')}>
{typeof gasPrice !== 'undefined'
? (
<CurrencyDisplay
className="transaction-breakdown__value"
data-testid="transaction-breakdown__gas-price"
currency={nativeCurrency}
denomination={GWEI}
value={gasPrice}
hideLabel
/>
)
: '?'
}
</TransactionBreakdownRow>
<TransactionBreakdownRow title={t('total')}>
<div>
<UserPreferencedCurrencyDisplay
className="transaction-breakdown__value transaction-breakdown__value--eth-total"
type={PRIMARY}
value={totalInHex}
/>
{
showFiat && (
<UserPreferencedCurrencyDisplay
className="transaction-breakdown__value"
type={SECONDARY}
value={totalInHex}
/>
)
}
</div>
</TransactionBreakdownRow>
</div>
)
}
}