You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.4 KiB
106 lines
3.4 KiB
3 years ago
|
import React from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
3 years ago
|
import classNames from 'classnames';
|
||
3 years ago
|
import { useSelector } from 'react-redux';
|
||
3 years ago
|
|
||
3 years ago
|
import { COLORS } from '../../../helpers/constants/design-system';
|
||
3 years ago
|
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
|
||
|
import { hexWEIToDecGWEI } from '../../../helpers/utils/conversions.util';
|
||
3 years ago
|
import { getPreferences } from '../../../selectors';
|
||
3 years ago
|
import { useGasFeeContext } from '../../../contexts/gasFee';
|
||
3 years ago
|
|
||
|
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';
|
||
3 years ago
|
import GasDetailsItemTitle from './gas-details-item-title';
|
||
3 years ago
|
|
||
3 years ago
|
const GasDetailsItem = ({ userAcknowledgedGasMissing = false }) => {
|
||
|
const {
|
||
|
estimateUsed,
|
||
|
hasSimulationError,
|
||
|
maximumCostInHexWei: hexMaximumTransactionFee,
|
||
|
minimumCostInHexWei: hexMinimumTransactionFee,
|
||
|
transaction,
|
||
|
} = useGasFeeContext();
|
||
|
|
||
|
const { useNativeCurrencyAsPrimaryCurrency } = useSelector(getPreferences);
|
||
3 years ago
|
|
||
|
if (hasSimulationError && !userAcknowledgedGasMissing) return null;
|
||
3 years ago
|
|
||
3 years ago
|
return (
|
||
|
<TransactionDetailItem
|
||
|
key="gas-item"
|
||
3 years ago
|
detailTitle={<GasDetailsItemTitle />}
|
||
3 years ago
|
detailTitleColor={COLORS.BLACK}
|
||
|
detailText={
|
||
|
<div className="gas-details-item__currency-container">
|
||
3 years ago
|
<LoadingHeartBeat />
|
||
3 years ago
|
<UserPreferencedCurrencyDisplay
|
||
|
type={SECONDARY}
|
||
|
value={hexMinimumTransactionFee}
|
||
|
hideLabel={Boolean(useNativeCurrencyAsPrimaryCurrency)}
|
||
|
/>
|
||
|
</div>
|
||
|
}
|
||
|
detailTotal={
|
||
|
<div className="gas-details-item__currency-container">
|
||
3 years ago
|
<LoadingHeartBeat />
|
||
3 years ago
|
<UserPreferencedCurrencyDisplay
|
||
|
type={PRIMARY}
|
||
|
value={hexMinimumTransactionFee}
|
||
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
|
||
|
/>
|
||
|
</div>
|
||
|
}
|
||
3 years ago
|
subText={
|
||
|
<>
|
||
|
<Box
|
||
|
key="editGasSubTextFeeLabel"
|
||
|
display="inline-flex"
|
||
|
className={classNames('gas-details-item__gasfee-label', {
|
||
|
'gas-details-item__gas-fee-warning': estimateUsed === 'high',
|
||
|
})}
|
||
3 years ago
|
>
|
||
3 years ago
|
<LoadingHeartBeat />
|
||
3 years ago
|
<Box marginRight={1}>
|
||
3 years ago
|
<strong>
|
||
3 years ago
|
{estimateUsed === 'high' && '⚠ '}
|
||
|
<I18nValue messageKey="editGasSubTextFeeLabel" />
|
||
3 years ago
|
</strong>
|
||
3 years ago
|
</Box>
|
||
|
<div
|
||
|
key="editGasSubTextFeeValue"
|
||
|
className="gas-details-item__currency-container"
|
||
|
>
|
||
3 years ago
|
<LoadingHeartBeat />
|
||
3 years ago
|
<UserPreferencedCurrencyDisplay
|
||
|
key="editGasSubTextFeeAmount"
|
||
|
type={PRIMARY}
|
||
|
value={hexMaximumTransactionFee}
|
||
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
|
||
|
/>
|
||
|
</div>
|
||
|
</Box>
|
||
|
</>
|
||
|
}
|
||
3 years ago
|
subTitle={
|
||
3 years ago
|
<GasTiming
|
||
|
maxPriorityFeePerGas={hexWEIToDecGWEI(
|
||
3 years ago
|
transaction.txParams.maxPriorityFeePerGas,
|
||
3 years ago
|
)}
|
||
3 years ago
|
maxFeePerGas={hexWEIToDecGWEI(transaction.txParams.maxFeePerGas)}
|
||
3 years ago
|
/>
|
||
3 years ago
|
}
|
||
|
/>
|
||
|
);
|
||
|
};
|
||
|
|
||
3 years ago
|
GasDetailsItem.propTypes = {
|
||
3 years ago
|
userAcknowledgedGasMissing: PropTypes.bool,
|
||
3 years ago
|
};
|
||
|
|
||
3 years ago
|
export default GasDetailsItem;
|