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
|
|
|
|
2023-02-02 21:15:26 +01:00
|
|
|
import { TextColor } from '../../../helpers/constants/design-system';
|
2021-11-05 18:23:15 +01:00
|
|
|
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
|
2023-04-17 16:34:26 +02:00
|
|
|
import {
|
|
|
|
getPreferences,
|
|
|
|
getUseCurrencyRateCheck,
|
|
|
|
transactionFeeSelector,
|
|
|
|
} from '../../../selectors';
|
|
|
|
import { getCurrentDraftTransaction } from '../../../ducks/send';
|
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';
|
2023-04-17 16:34:26 +02:00
|
|
|
import { hexWEIToDecGWEI } from '../../../../shared/modules/conversion.utils';
|
2023-05-12 20:27:25 +02:00
|
|
|
import { useDraftTransactionWithTxParams } from '../../../hooks/useDraftTransactionWithTxParams';
|
2023-06-08 12:26:18 +02:00
|
|
|
import { PriorityLevels } from '../../../../shared/constants/gas';
|
2021-12-12 00:26:28 +01:00
|
|
|
import GasDetailsItemTitle from './gas-details-item-title';
|
2021-11-05 18:23:15 +01:00
|
|
|
|
2023-06-26 20:43:16 +02:00
|
|
|
const GasDetailsItem = ({
|
|
|
|
'data-testid': dataTestId,
|
|
|
|
userAcknowledgedGasMissing = false,
|
|
|
|
}) => {
|
2022-07-12 15:59:38 +02:00
|
|
|
const t = useI18nContext();
|
2023-04-17 16:34:26 +02:00
|
|
|
const draftTransaction = useSelector(getCurrentDraftTransaction);
|
2023-05-12 20:27:25 +02:00
|
|
|
const transactionData = useDraftTransactionWithTxParams();
|
2023-04-17 16:34:26 +02:00
|
|
|
|
|
|
|
const {
|
|
|
|
hexMinimumTransactionFee: draftHexMinimumTransactionFee,
|
|
|
|
hexMaximumTransactionFee: draftHexMaximumTransactionFee,
|
|
|
|
} = useSelector((state) => transactionFeeSelector(state, transactionData));
|
|
|
|
|
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
|
|
|
|
2023-05-12 17:01:15 +02:00
|
|
|
const maxPriorityFeePerGasToRender = (
|
|
|
|
maxPriorityFeePerGas ??
|
|
|
|
hexWEIToDecGWEI(transactionData.txParams?.maxPriorityFeePerGas ?? '0x0')
|
|
|
|
).toString();
|
|
|
|
|
|
|
|
const maxFeePerGasToRender = (
|
|
|
|
maxFeePerGas ??
|
|
|
|
hexWEIToDecGWEI(transactionData.txParams?.maxFeePerGas ?? '0x0')
|
|
|
|
).toString();
|
|
|
|
|
2021-11-05 18:23:15 +01:00
|
|
|
return (
|
|
|
|
<TransactionDetailItem
|
2023-05-02 05:42:59 +02:00
|
|
|
key="gas-details-item"
|
2023-06-26 20:43:16 +02:00
|
|
|
data-testid={dataTestId}
|
2021-12-12 00:26:28 +01:00
|
|
|
detailTitle={<GasDetailsItemTitle />}
|
2023-02-02 21:15:26 +01:00
|
|
|
detailTitleColor={TextColor.textDefault}
|
2021-11-05 18:23:15 +01:00
|
|
|
detailText={
|
2023-04-17 16:34:26 +02:00
|
|
|
useCurrencyRateCheck &&
|
|
|
|
Object.keys(draftTransaction).length === 0 && (
|
2023-01-17 16:23:04 +01:00
|
|
|
<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}
|
2023-04-17 16:34:26 +02:00
|
|
|
value={hexMinimumTransactionFee || draftHexMinimumTransactionFee}
|
2021-11-05 18:23:15 +01:00
|
|
|
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', {
|
2023-06-08 12:26:18 +02:00
|
|
|
'gas-details-item__gas-fee-warning':
|
|
|
|
estimateUsed === PriorityLevels.high ||
|
|
|
|
estimateUsed === PriorityLevels.dappSuggestedHigh,
|
2021-11-29 18:40:48 +01:00
|
|
|
})}
|
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>
|
2023-06-08 12:26:18 +02:00
|
|
|
{(estimateUsed === PriorityLevels.high ||
|
|
|
|
estimateUsed === PriorityLevels.dappSuggestedHigh) &&
|
|
|
|
'⚠ '}
|
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}
|
2023-04-17 16:34:26 +02:00
|
|
|
value={
|
|
|
|
hexMaximumTransactionFee || draftHexMaximumTransactionFee
|
|
|
|
}
|
2021-11-29 18:40:48 +01:00
|
|
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Box>
|
|
|
|
</>
|
|
|
|
}
|
2021-11-05 18:23:15 +01:00
|
|
|
subTitle={
|
2021-11-18 20:08:29 +01:00
|
|
|
<GasTiming
|
2023-05-12 17:01:15 +02:00
|
|
|
maxPriorityFeePerGas={maxPriorityFeePerGasToRender}
|
|
|
|
maxFeePerGas={maxFeePerGasToRender}
|
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 = {
|
2023-06-26 20:43:16 +02:00
|
|
|
'data-testid': PropTypes.string,
|
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;
|