1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 21:57:06 +01:00
metamask-extension/ui/components/app/transaction-detail-item/transaction-detail-item.component.js
Mark Stacey ec7e7fdf6d
Fix fallback gas estimation (#19746)
* Fix fallback gas estimation

Our fallback gas estimation was failing due to a bug in the
`@metamask/controller-utils` package. This was causing gas estimation
to fail completely on certain networks (those not supported by our gas
estimation APIs and non EIP-1559 compatibile), and it was causing the
fallback gas estimation operation (in case our API was down) to fail
across all networks.

Fixes https://github.com/MetaMask/metamask-extension/issues/19735

* Add e2e tests

E2E tests have been added to capture gas estimation. Cases are added
for our API, for the fallback estimate, and for non-EIP-1559 estimates.

As part of this work, the legacy gas API had to be disabled. This was
being used in e2e tests but was dead code in production. It needed to
be disabled to ensure the code under test was reachable.

* Fix gas API referenced in e2e test

* Update unit test snapshots
2023-06-26 16:13:16 -02:30

132 lines
3.7 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import Typography from '../../ui/typography/typography';
import {
Color,
FontWeight,
TypographyVariant,
DISPLAY,
FLEX_WRAP,
AlignItems,
TextAlign,
} from '../../../helpers/constants/design-system';
export default function TransactionDetailItem({
'data-testid': dataTestId,
detailTitle = '',
detailText,
detailTitleColor = Color.textDefault,
detailTotal = '',
subTitle = '',
subText = '',
boldHeadings = true,
flexWidthValues = false,
}) {
return (
<div className="transaction-detail-item" data-testid={dataTestId}>
<div className="transaction-detail-item__row">
<Typography
color={detailTitleColor}
fontWeight={boldHeadings ? FontWeight.Bold : FontWeight.Normal}
variant={TypographyVariant.H6}
boxProps={{
display: DISPLAY.FLEX,
flexWrap: FLEX_WRAP.NO_WRAP,
alignItems: AlignItems.center,
}}
>
{detailTitle}
</Typography>
<div
className={classnames('transaction-detail-item__detail-values', {
'transaction-detail-item__detail-values--flex-width':
flexWidthValues,
})}
>
{detailText && (
<Typography
variant={TypographyVariant.H6}
color={Color.textAlternative}
>
{detailText}
</Typography>
)}
<Typography
color={Color.textDefault}
fontWeight={boldHeadings ? FontWeight.Bold : FontWeight.Normal}
variant={TypographyVariant.H6}
marginTop={1}
marginBottom={1}
marginLeft={1}
boxProps={{ textAlign: TextAlign.Right }}
>
{detailTotal}
</Typography>
</div>
</div>
<div className="transaction-detail-item__row">
{React.isValidElement(subTitle) ? (
<div>{subTitle}</div>
) : (
<Typography
variant={TypographyVariant.H7}
color={Color.textAlternative}
>
{subTitle}
</Typography>
)}
<Typography
variant={TypographyVariant.H7}
color={Color.textAlternative}
align="end"
className="transaction-detail-item__row-subText"
>
{subText}
</Typography>
</div>
</div>
);
}
TransactionDetailItem.propTypes = {
/**
* An identifier for use in end-to-end tests.
*/
'data-testid': PropTypes.string,
/**
* Detail title text wrapped in Typography component.
*/
detailTitle: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
/**
* The color of the detailTitle text accepts all Typography color props
*/
detailTitleColor: PropTypes.string,
/**
* Text to show on the left of the detailTotal. Wrapped in Typography component.
*/
detailText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
/**
* Total amount to show. Wrapped in Typography component. Will be bold if boldHeadings is true
*/
detailTotal: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
/**
* Subtitle text. Checks if React.isValidElement before displaying. Displays under detailTitle
*/
subTitle: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
/**
* Text to show under detailTotal. Wrapped in Typography component.
*/
subText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
/**
* Whether detailTotal is bold or not. Defaults to true
*/
boldHeadings: PropTypes.bool,
/**
* Changes width to auto for transaction-detail-item__detail-values
*/
flexWidthValues: PropTypes.bool,
};