|
|
|
@ -1,21 +1,25 @@ |
|
|
|
|
import React, { useState, useContext } from 'react'; |
|
|
|
|
import PropTypes from 'prop-types'; |
|
|
|
|
|
|
|
|
|
import { GAS_RECOMMENDATIONS } from '../../../../shared/constants/gas'; |
|
|
|
|
|
|
|
|
|
import Button from '../../ui/button'; |
|
|
|
|
import Typography from '../../ui/typography/typography'; |
|
|
|
|
import { |
|
|
|
|
COLORS, |
|
|
|
|
TYPOGRAPHY, |
|
|
|
|
FONT_WEIGHT, |
|
|
|
|
TEXT_ALIGN, |
|
|
|
|
} from '../../../helpers/constants/design-system'; |
|
|
|
|
|
|
|
|
|
import InfoTooltip from '../../ui/info-tooltip'; |
|
|
|
|
import TransactionTotalBanner from '../transaction-total-banner/transaction-total-banner.component'; |
|
|
|
|
import RadioGroup from '../../ui/radio-group/radio-group.component'; |
|
|
|
|
import AdvancedGasControls from '../advanced-gas-controls/advanced-gas-controls.component'; |
|
|
|
|
import ActionableMessage from '../../ui/actionable-message/actionable-message'; |
|
|
|
|
|
|
|
|
|
import { I18nContext } from '../../../contexts/i18n'; |
|
|
|
|
import ActionableMessage from '../../ui/actionable-message/actionable-message'; |
|
|
|
|
import { useGasFeeInputs } from '../../../hooks/useGasFeeInputs'; |
|
|
|
|
|
|
|
|
|
export default function EditGasDisplay({ |
|
|
|
|
alwaysShowForm, |
|
|
|
@ -24,18 +28,45 @@ export default function EditGasDisplay({ |
|
|
|
|
onEducationClick, |
|
|
|
|
dappSuggestedGasFee, |
|
|
|
|
dappOrigin, |
|
|
|
|
defaultEstimateToUse = 'medium', |
|
|
|
|
}) { |
|
|
|
|
const t = useContext(I18nContext); |
|
|
|
|
|
|
|
|
|
const [warning] = useState(null); |
|
|
|
|
|
|
|
|
|
const [showAdvancedForm, setShowAdvancedForm] = useState(false); |
|
|
|
|
const [ |
|
|
|
|
dappSuggestedGasFeeAcknowledged, |
|
|
|
|
setDappSuggestedGasFeeAcknowledged, |
|
|
|
|
] = useState(false); |
|
|
|
|
|
|
|
|
|
const requireDappAcknowledgement = |
|
|
|
|
dappSuggestedGasFee && !dappSuggestedGasFeeAcknowledged; |
|
|
|
|
const requireDappAcknowledgement = Boolean( |
|
|
|
|
dappSuggestedGasFee && !dappSuggestedGasFeeAcknowledged, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const { |
|
|
|
|
maxPriorityFeePerGas, |
|
|
|
|
setMaxPriorityFeePerGas, |
|
|
|
|
maxPriorityFeePerGasFiat, |
|
|
|
|
maxFeePerGas, |
|
|
|
|
setMaxFeePerGas, |
|
|
|
|
maxFeePerGasFiat, |
|
|
|
|
estimatedMaximumNative, |
|
|
|
|
isGasEstimatesLoading, |
|
|
|
|
gasFeeEstimates, |
|
|
|
|
gasEstimateType, |
|
|
|
|
gasPrice, |
|
|
|
|
setGasPrice, |
|
|
|
|
gasLimit, |
|
|
|
|
setGasLimit, |
|
|
|
|
estimateToUse, |
|
|
|
|
setEstimateToUse, |
|
|
|
|
estimatedMinimumFiat, |
|
|
|
|
estimatedMaximumFiat, |
|
|
|
|
isMaxFeeError, |
|
|
|
|
isMaxPriorityFeeError, |
|
|
|
|
isGasTooLow, |
|
|
|
|
} = useGasFeeInputs(defaultEstimateToUse); |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<div className="edit-gas-display"> |
|
|
|
@ -44,7 +75,7 @@ export default function EditGasDisplay({ |
|
|
|
|
<div className="edit-gas-display__warning"> |
|
|
|
|
<ActionableMessage |
|
|
|
|
className="actionable-message--warning" |
|
|
|
|
message="Swaps are time sensitive. “Medium” is not reccomended." |
|
|
|
|
message={warning} |
|
|
|
|
/> |
|
|
|
|
</div> |
|
|
|
|
)} |
|
|
|
@ -72,9 +103,25 @@ export default function EditGasDisplay({ |
|
|
|
|
</Typography> |
|
|
|
|
</div> |
|
|
|
|
)} |
|
|
|
|
|
|
|
|
|
<TransactionTotalBanner total="" detail="" timing="" /> |
|
|
|
|
|
|
|
|
|
<TransactionTotalBanner |
|
|
|
|
total={estimatedMinimumFiat} |
|
|
|
|
detail={ |
|
|
|
|
process.env.SHOW_EIP_1559_UI && |
|
|
|
|
t('editGasTotalBannerSubtitle', [ |
|
|
|
|
<Typography |
|
|
|
|
fontWeight={FONT_WEIGHT.BOLD} |
|
|
|
|
tag="span" |
|
|
|
|
key="secondary" |
|
|
|
|
> |
|
|
|
|
{estimatedMaximumFiat} |
|
|
|
|
</Typography>, |
|
|
|
|
<Typography tag="span" key="primary"> |
|
|
|
|
{estimatedMaximumNative} |
|
|
|
|
</Typography>, |
|
|
|
|
]) |
|
|
|
|
} |
|
|
|
|
timing="" |
|
|
|
|
/> |
|
|
|
|
{requireDappAcknowledgement && ( |
|
|
|
|
<Button |
|
|
|
|
className="edit-gas-display__dapp-acknowledgement-button" |
|
|
|
@ -83,23 +130,43 @@ export default function EditGasDisplay({ |
|
|
|
|
{t('gasDisplayAcknowledgeDappButtonText')} |
|
|
|
|
</Button> |
|
|
|
|
)} |
|
|
|
|
|
|
|
|
|
{isGasTooLow && ( |
|
|
|
|
<div className="edit-gas-display__error"> |
|
|
|
|
<Typography |
|
|
|
|
color={COLORS.ERROR1} |
|
|
|
|
variant={TYPOGRAPHY.H7} |
|
|
|
|
align={TEXT_ALIGN.CENTER} |
|
|
|
|
> |
|
|
|
|
{t('editGasTooLow')} |
|
|
|
|
</Typography> |
|
|
|
|
</div> |
|
|
|
|
)} |
|
|
|
|
{!requireDappAcknowledgement && ( |
|
|
|
|
<RadioGroup |
|
|
|
|
name="gas-recommendation" |
|
|
|
|
options={[ |
|
|
|
|
{ value: 'low', label: t('editGasLow'), recommended: false }, |
|
|
|
|
{ |
|
|
|
|
value: 'medium', |
|
|
|
|
value: GAS_RECOMMENDATIONS.LOW, |
|
|
|
|
label: t('editGasLow'), |
|
|
|
|
recommended: defaultEstimateToUse === GAS_RECOMMENDATIONS.LOW, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
value: GAS_RECOMMENDATIONS.MEDIUM, |
|
|
|
|
label: t('editGasMedium'), |
|
|
|
|
recommended: false, |
|
|
|
|
recommended: |
|
|
|
|
defaultEstimateToUse === GAS_RECOMMENDATIONS.MEDIUM, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
value: GAS_RECOMMENDATIONS.HIGH, |
|
|
|
|
label: t('editGasHigh'), |
|
|
|
|
recommended: defaultEstimateToUse === GAS_RECOMMENDATIONS.HIGH, |
|
|
|
|
}, |
|
|
|
|
{ value: 'high', label: t('editGasHigh'), recommended: true }, |
|
|
|
|
]} |
|
|
|
|
selectedValue="high" |
|
|
|
|
selectedValue={estimateToUse} |
|
|
|
|
onChange={setEstimateToUse} |
|
|
|
|
/> |
|
|
|
|
)} |
|
|
|
|
{!requireDappAcknowledgement && !alwaysShowForm && ( |
|
|
|
|
{!alwaysShowForm && ( |
|
|
|
|
<button |
|
|
|
|
className="edit-gas-display__advanced-button" |
|
|
|
|
onClick={() => setShowAdvancedForm(!showAdvancedForm)} |
|
|
|
@ -112,8 +179,29 @@ export default function EditGasDisplay({ |
|
|
|
|
)} |
|
|
|
|
</button> |
|
|
|
|
)} |
|
|
|
|
{((!requireDappAcknowledgement && alwaysShowForm) || |
|
|
|
|
showAdvancedForm) && <AdvancedGasControls />} |
|
|
|
|
{!requireDappAcknowledgement && |
|
|
|
|
(alwaysShowForm || showAdvancedForm) && ( |
|
|
|
|
<AdvancedGasControls |
|
|
|
|
gasFeeEstimates={gasFeeEstimates} |
|
|
|
|
gasEstimateType={gasEstimateType} |
|
|
|
|
estimateToUse={estimateToUse} |
|
|
|
|
isGasEstimatesLoading={isGasEstimatesLoading} |
|
|
|
|
gasLimit={gasLimit} |
|
|
|
|
setGasLimit={setGasLimit} |
|
|
|
|
maxPriorityFee={maxPriorityFeePerGas} |
|
|
|
|
setMaxPriorityFee={setMaxPriorityFeePerGas} |
|
|
|
|
maxFee={maxFeePerGas} |
|
|
|
|
setMaxFee={setMaxFeePerGas} |
|
|
|
|
gasPrice={gasPrice} |
|
|
|
|
setGasPrice={setGasPrice} |
|
|
|
|
maxPriorityFeeFiat={maxPriorityFeePerGasFiat} |
|
|
|
|
maxFeeFiat={maxFeePerGasFiat} |
|
|
|
|
maxPriorityFeeError={ |
|
|
|
|
isMaxPriorityFeeError ? t('editGasMaxPriorityFeeLow') : null |
|
|
|
|
} |
|
|
|
|
maxFeeError={isMaxFeeError ? t('editGasMaxFeeLow') : null} |
|
|
|
|
/> |
|
|
|
|
)} |
|
|
|
|
</div> |
|
|
|
|
{!requireDappAcknowledgement && showEducationButton && ( |
|
|
|
|
<div className="edit-gas-display__education"> |
|
|
|
@ -133,6 +221,7 @@ EditGasDisplay.propTypes = { |
|
|
|
|
onEducationClick: PropTypes.func, |
|
|
|
|
dappSuggestedGasFee: PropTypes.number, |
|
|
|
|
dappOrigin: PropTypes.string, |
|
|
|
|
defaultEstimateToUse: PropTypes.oneOf(Object.values(GAS_RECOMMENDATIONS)), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
EditGasDisplay.defaultProps = { |
|
|
|
|