2021-11-05 18:23:15 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-11-12 04:22:54 +01:00
|
|
|
import classNames from 'classnames';
|
2022-01-06 03:47:26 +01:00
|
|
|
import { useSelector } from 'react-redux';
|
2021-11-05 18:23:15 +01:00
|
|
|
|
2021-12-12 00:26:28 +01:00
|
|
|
import { COLORS } from '../../../helpers/constants/design-system';
|
2021-11-05 18:23:15 +01:00
|
|
|
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
|
2023-01-17 16:23:04 +01:00
|
|
|
import { getPreferences, getUseCurrencyRateCheck } from '../../../selectors';
|
2021-11-12 04:22:54 +01:00
|
|
|
import { useGasFeeContext } from '../../../contexts/gasFee';
|
2022-07-12 15:59:38 +02:00
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2022-01-06 03:47:26 +01:00
|
|
|
|
|
|
|
import Box from '../../ui/box';
|
|
|
|
import LoadingHeartBeat from '../../ui/loading-heartbeat';
|
|
|
|
import GasTiming from '../gas-timing/gas-timing.component';
|
|
|
|
import TransactionDetailItem from '../transaction-detail-item/transaction-detail-item.component';
|
|
|
|
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display';
|
2021-12-12 00:26:28 +01:00
|
|
|
import GasDetailsItemTitle from './gas-details-item-title';
|
2021-11-05 18:23:15 +01:00
|
|
|
|
2022-01-06 03:47:26 +01:00
|
|
|
const GasDetailsItem = ({ userAcknowledgedGasMissing = false }) => {
|
2022-07-12 15:59:38 +02:00
|
|
|
const t = useI18nContext();
|
2022-01-06 03:47:26 +01:00
|
|
|
const {
|
|
|
|
estimateUsed,
|
|
|
|
hasSimulationError,
|
|
|
|
maximumCostInHexWei: hexMaximumTransactionFee,
|
|
|
|
minimumCostInHexWei: hexMinimumTransactionFee,
|
2022-03-03 01:22:46 +01:00
|
|
|
maxPriorityFeePerGas,
|
|
|
|
maxFeePerGas,
|
2022-01-06 03:47:26 +01:00
|
|
|
} = useGasFeeContext();
|
|
|
|
|
|
|
|
const { useNativeCurrencyAsPrimaryCurrency } = useSelector(getPreferences);
|
2021-11-24 18:02:53 +01:00
|
|
|
|
2023-01-17 16:23:04 +01:00
|
|
|
const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck);
|
|
|
|
|
2022-01-06 23:56:51 +01:00
|
|
|
if (hasSimulationError && !userAcknowledgedGasMissing) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-11-12 04:22:54 +01:00
|
|
|
|
2021-11-05 18:23:15 +01:00
|
|
|
return (
|
|
|
|
<TransactionDetailItem
|
|
|
|
key="gas-item"
|
2021-12-12 00:26:28 +01:00
|
|
|
detailTitle={<GasDetailsItemTitle />}
|
2022-03-21 14:58:27 +01:00
|
|
|
detailTitleColor={COLORS.TEXT_DEFAULT}
|
2021-11-05 18:23:15 +01:00
|
|
|
detailText={
|
2023-01-17 16:23:04 +01:00
|
|
|
useCurrencyRateCheck && (
|
|
|
|
<div className="gas-details-item__currency-container">
|
|
|
|
<LoadingHeartBeat estimateUsed={estimateUsed} />
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
type={SECONDARY}
|
|
|
|
value={hexMinimumTransactionFee}
|
|
|
|
hideLabel={Boolean(useNativeCurrencyAsPrimaryCurrency)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
2021-11-05 18:23:15 +01:00
|
|
|
}
|
|
|
|
detailTotal={
|
|
|
|
<div className="gas-details-item__currency-container">
|
2022-01-26 19:18:43 +01:00
|
|
|
<LoadingHeartBeat estimateUsed={estimateUsed} />
|
2021-11-05 18:23:15 +01:00
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
type={PRIMARY}
|
|
|
|
value={hexMinimumTransactionFee}
|
|
|
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
}
|
2021-11-29 18:40:48 +01:00
|
|
|
subText={
|
|
|
|
<>
|
|
|
|
<Box
|
|
|
|
key="editGasSubTextFeeLabel"
|
|
|
|
display="inline-flex"
|
|
|
|
className={classNames('gas-details-item__gasfee-label', {
|
|
|
|
'gas-details-item__gas-fee-warning': estimateUsed === 'high',
|
|
|
|
})}
|
2021-11-05 18:23:15 +01:00
|
|
|
>
|
2022-01-26 19:18:43 +01:00
|
|
|
<LoadingHeartBeat estimateUsed={estimateUsed} />
|
2021-11-29 18:40:48 +01:00
|
|
|
<Box marginRight={1}>
|
2021-12-01 01:31:21 +01:00
|
|
|
<strong>
|
2021-11-29 18:40:48 +01:00
|
|
|
{estimateUsed === 'high' && '⚠ '}
|
2022-07-12 15:59:38 +02:00
|
|
|
{t('editGasSubTextFeeLabel')}
|
2021-12-01 01:31:21 +01:00
|
|
|
</strong>
|
2021-11-29 18:40:48 +01:00
|
|
|
</Box>
|
|
|
|
<div
|
|
|
|
key="editGasSubTextFeeValue"
|
|
|
|
className="gas-details-item__currency-container"
|
|
|
|
>
|
2022-01-26 19:18:43 +01:00
|
|
|
<LoadingHeartBeat estimateUsed={estimateUsed} />
|
2021-11-29 18:40:48 +01:00
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
key="editGasSubTextFeeAmount"
|
|
|
|
type={PRIMARY}
|
|
|
|
value={hexMaximumTransactionFee}
|
|
|
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Box>
|
|
|
|
</>
|
|
|
|
}
|
2021-11-05 18:23:15 +01:00
|
|
|
subTitle={
|
2021-11-18 20:08:29 +01:00
|
|
|
<GasTiming
|
2022-06-03 00:54:16 +02:00
|
|
|
maxPriorityFeePerGas={maxPriorityFeePerGas.toString()}
|
|
|
|
maxFeePerGas={maxFeePerGas.toString()}
|
2021-11-18 20:08:29 +01:00
|
|
|
/>
|
2021-11-05 18:23:15 +01:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-11-12 04:22:54 +01:00
|
|
|
GasDetailsItem.propTypes = {
|
2022-01-06 03:47:26 +01:00
|
|
|
userAcknowledgedGasMissing: PropTypes.bool,
|
2021-11-05 18:23:15 +01:00
|
|
|
};
|
|
|
|
|
2021-11-12 04:22:54 +01:00
|
|
|
export default GasDetailsItem;
|