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';
|
|
|
|
import { hexWEIToDecGWEI } from '../../../helpers/utils/conversions.util';
|
2022-01-06 03:47:26 +01:00
|
|
|
import { getPreferences } from '../../../selectors';
|
2021-11-12 04:22:54 +01:00
|
|
|
import { useGasFeeContext } from '../../../contexts/gasFee';
|
2022-01-06 03:47:26 +01:00
|
|
|
|
|
|
|
import Box from '../../ui/box';
|
|
|
|
import I18nValue from '../../ui/i18n-value';
|
|
|
|
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 }) => {
|
|
|
|
const {
|
|
|
|
estimateUsed,
|
|
|
|
hasSimulationError,
|
|
|
|
maximumCostInHexWei: hexMaximumTransactionFee,
|
|
|
|
minimumCostInHexWei: hexMinimumTransactionFee,
|
|
|
|
transaction,
|
|
|
|
} = useGasFeeContext();
|
|
|
|
|
|
|
|
const { useNativeCurrencyAsPrimaryCurrency } = useSelector(getPreferences);
|
2021-11-24 18:02:53 +01:00
|
|
|
|
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 />}
|
2021-11-05 18:23:15 +01:00
|
|
|
detailTitleColor={COLORS.BLACK}
|
|
|
|
detailText={
|
|
|
|
<div className="gas-details-item__currency-container">
|
2021-12-10 01:50:38 +01:00
|
|
|
<LoadingHeartBeat />
|
2021-11-05 18:23:15 +01:00
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
type={SECONDARY}
|
|
|
|
value={hexMinimumTransactionFee}
|
|
|
|
hideLabel={Boolean(useNativeCurrencyAsPrimaryCurrency)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
detailTotal={
|
|
|
|
<div className="gas-details-item__currency-container">
|
2021-12-10 01:50:38 +01:00
|
|
|
<LoadingHeartBeat />
|
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
|
|
|
>
|
2021-12-10 01:50:38 +01:00
|
|
|
<LoadingHeartBeat />
|
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' && '⚠ '}
|
|
|
|
<I18nValue messageKey="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"
|
|
|
|
>
|
2021-12-10 01:50:38 +01:00
|
|
|
<LoadingHeartBeat />
|
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
|
|
|
|
maxPriorityFeePerGas={hexWEIToDecGWEI(
|
2022-01-06 03:47:26 +01:00
|
|
|
transaction.txParams.maxPriorityFeePerGas,
|
2021-11-18 20:08:29 +01:00
|
|
|
)}
|
2022-01-06 03:47:26 +01:00
|
|
|
maxFeePerGas={hexWEIToDecGWEI(transaction.txParams.maxFeePerGas)}
|
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;
|