|
|
|
@ -2,6 +2,18 @@ import React, { useCallback, useContext, useState } from 'react'; |
|
|
|
|
import PropTypes from 'prop-types'; |
|
|
|
|
|
|
|
|
|
import { useDispatch, useSelector } from 'react-redux'; |
|
|
|
|
import { useGasFeeInputs } from '../../../hooks/useGasFeeInputs'; |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
GAS_ESTIMATE_TYPES, |
|
|
|
|
EDIT_GAS_MODES, |
|
|
|
|
} from '../../../../shared/constants/gas'; |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
decGWEIToHexWEI, |
|
|
|
|
decimalToHex, |
|
|
|
|
} from '../../../helpers/utils/conversions.util'; |
|
|
|
|
|
|
|
|
|
import Popover from '../../ui/popover'; |
|
|
|
|
import Button from '../../ui/button'; |
|
|
|
|
import EditGasDisplay from '../edit-gas-display'; |
|
|
|
@ -16,16 +28,11 @@ import { |
|
|
|
|
updateTransaction, |
|
|
|
|
} from '../../../store/actions'; |
|
|
|
|
|
|
|
|
|
export const EDIT_GAS_MODE = { |
|
|
|
|
SPEED_UP: 'speed-up', |
|
|
|
|
CANCEL: 'cancel', |
|
|
|
|
MODIFY_IN_PLACE: 'modify-in-place', |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export default function EditGasPopover({ |
|
|
|
|
popoverTitle, |
|
|
|
|
confirmButtonText, |
|
|
|
|
editGasDisplayProps, |
|
|
|
|
popoverTitle = '', |
|
|
|
|
confirmButtonText = '', |
|
|
|
|
editGasDisplayProps = {}, |
|
|
|
|
defaultEstimateToUse = 'medium', |
|
|
|
|
transaction, |
|
|
|
|
mode, |
|
|
|
|
onClose, |
|
|
|
@ -33,8 +40,42 @@ export default function EditGasPopover({ |
|
|
|
|
const t = useContext(I18nContext); |
|
|
|
|
const dispatch = useDispatch(); |
|
|
|
|
const showSidebar = useSelector((state) => state.appState.sidebar.isOpen); |
|
|
|
|
|
|
|
|
|
const showEducationButton = mode === EDIT_GAS_MODES.MODIFY_IN_PLACE; |
|
|
|
|
const [showEducationContent, setShowEducationContent] = useState(false); |
|
|
|
|
|
|
|
|
|
const [warning] = useState(null); |
|
|
|
|
|
|
|
|
|
const [showAdvancedForm, setShowAdvancedForm] = useState(false); |
|
|
|
|
const [ |
|
|
|
|
dappSuggestedGasFeeAcknowledged, |
|
|
|
|
setDappSuggestedGasFeeAcknowledged, |
|
|
|
|
] = useState(false); |
|
|
|
|
|
|
|
|
|
const { |
|
|
|
|
maxPriorityFeePerGas, |
|
|
|
|
setMaxPriorityFeePerGas, |
|
|
|
|
maxPriorityFeePerGasFiat, |
|
|
|
|
maxFeePerGas, |
|
|
|
|
setMaxFeePerGas, |
|
|
|
|
maxFeePerGasFiat, |
|
|
|
|
estimatedMaximumNative, |
|
|
|
|
isGasEstimatesLoading, |
|
|
|
|
gasFeeEstimates, |
|
|
|
|
gasEstimateType, |
|
|
|
|
gasPrice, |
|
|
|
|
setGasPrice, |
|
|
|
|
gasLimit, |
|
|
|
|
setGasLimit, |
|
|
|
|
estimateToUse, |
|
|
|
|
setEstimateToUse, |
|
|
|
|
estimatedMinimumFiat, |
|
|
|
|
estimatedMaximumFiat, |
|
|
|
|
isMaxFeeError, |
|
|
|
|
isMaxPriorityFeeError, |
|
|
|
|
isGasTooLow, |
|
|
|
|
} = useGasFeeInputs(defaultEstimateToUse); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Temporary placeholder, this should be managed by the parent component but |
|
|
|
|
* we will be extracting this component from the hard to maintain modal/ |
|
|
|
@ -55,26 +96,36 @@ export default function EditGasPopover({ |
|
|
|
|
if (!transaction || !mode) { |
|
|
|
|
closePopover(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const newGasSettings = |
|
|
|
|
gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET |
|
|
|
|
? { |
|
|
|
|
gas: decimalToHex(gasLimit), |
|
|
|
|
gasLimit: decimalToHex(gasLimit), |
|
|
|
|
maxFeePerGas: decGWEIToHexWEI(maxFeePerGas), |
|
|
|
|
maxPriorityFeePerGas: decGWEIToHexWEI(maxPriorityFeePerGas), |
|
|
|
|
} |
|
|
|
|
: { |
|
|
|
|
gas: decimalToHex(gasLimit), |
|
|
|
|
gasLimit: decimalToHex(gasLimit), |
|
|
|
|
gasPrice: decGWEIToHexWEI(gasPrice), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
switch (mode) { |
|
|
|
|
case EDIT_GAS_MODE.CANCEL: |
|
|
|
|
dispatch( |
|
|
|
|
createCancelTransaction(transaction.id, { |
|
|
|
|
/** new gas settings */ |
|
|
|
|
}), |
|
|
|
|
); |
|
|
|
|
case EDIT_GAS_MODES.CANCEL: |
|
|
|
|
dispatch(createCancelTransaction(transaction.id, newGasSettings)); |
|
|
|
|
break; |
|
|
|
|
case EDIT_GAS_MODE.SPEED_UP: |
|
|
|
|
dispatch( |
|
|
|
|
createSpeedUpTransaction(transaction.id, { |
|
|
|
|
/** new gas settings */ |
|
|
|
|
}), |
|
|
|
|
); |
|
|
|
|
case EDIT_GAS_MODES.SPEED_UP: |
|
|
|
|
dispatch(createSpeedUpTransaction(transaction.id, newGasSettings)); |
|
|
|
|
break; |
|
|
|
|
case EDIT_GAS_MODE.MODIFY_IN_PLACE: |
|
|
|
|
case EDIT_GAS_MODES.MODIFY_IN_PLACE: |
|
|
|
|
dispatch( |
|
|
|
|
updateTransaction({ |
|
|
|
|
...transaction, |
|
|
|
|
txParams: { ...transaction.txParams /** ...newGasSettings */ }, |
|
|
|
|
txParams: { |
|
|
|
|
...transaction.txParams, |
|
|
|
|
...newGasSettings, |
|
|
|
|
}, |
|
|
|
|
}), |
|
|
|
|
); |
|
|
|
|
break; |
|
|
|
@ -83,11 +134,29 @@ export default function EditGasPopover({ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
closePopover(); |
|
|
|
|
}, [transaction, mode, dispatch, closePopover]); |
|
|
|
|
}, [ |
|
|
|
|
transaction, |
|
|
|
|
mode, |
|
|
|
|
dispatch, |
|
|
|
|
closePopover, |
|
|
|
|
gasLimit, |
|
|
|
|
gasPrice, |
|
|
|
|
maxFeePerGas, |
|
|
|
|
maxPriorityFeePerGas, |
|
|
|
|
gasEstimateType, |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
let title = t('editGasTitle'); |
|
|
|
|
if (popoverTitle) { |
|
|
|
|
title = popoverTitle; |
|
|
|
|
} else if (showEducationContent) { |
|
|
|
|
title = t('editGasEducationModalTitle'); |
|
|
|
|
} else if (mode === EDIT_GAS_MODES.SPEED_UP) { |
|
|
|
|
title = t('speedUpPopoverTitle'); |
|
|
|
|
} else if (mode === EDIT_GAS_MODES.CANCEL) { |
|
|
|
|
title = t('cancelPopoverTitle'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const title = showEducationContent |
|
|
|
|
? t('editGasEducationModalTitle') |
|
|
|
|
: popoverTitle || t('editGasTitle'); |
|
|
|
|
const footerButtonText = confirmButtonText || t('save'); |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
@ -99,7 +168,11 @@ export default function EditGasPopover({ |
|
|
|
|
} |
|
|
|
|
footer={ |
|
|
|
|
<> |
|
|
|
|
<Button type="primary" onClick={onSubmit}> |
|
|
|
|
<Button |
|
|
|
|
type="primary" |
|
|
|
|
onClick={onSubmit} |
|
|
|
|
disabled={isMaxFeeError || isMaxPriorityFeeError || isGasTooLow} |
|
|
|
|
> |
|
|
|
|
{footerButtonText} |
|
|
|
|
</Button> |
|
|
|
|
</> |
|
|
|
@ -110,8 +183,38 @@ export default function EditGasPopover({ |
|
|
|
|
<EditGasDisplayEducation /> |
|
|
|
|
) : ( |
|
|
|
|
<EditGasDisplay |
|
|
|
|
{...editGasDisplayProps} |
|
|
|
|
showEducationButton={showEducationButton} |
|
|
|
|
warning={warning} |
|
|
|
|
showAdvancedForm={showAdvancedForm} |
|
|
|
|
setShowAdvancedForm={setShowAdvancedForm} |
|
|
|
|
dappSuggestedGasFeeAcknowledged={dappSuggestedGasFeeAcknowledged} |
|
|
|
|
setDappSuggestedGasFeeAcknowledged={ |
|
|
|
|
setDappSuggestedGasFeeAcknowledged |
|
|
|
|
} |
|
|
|
|
maxPriorityFeePerGas={maxPriorityFeePerGas} |
|
|
|
|
setMaxPriorityFeePerGas={setMaxPriorityFeePerGas} |
|
|
|
|
maxPriorityFeePerGasFiat={maxPriorityFeePerGasFiat} |
|
|
|
|
maxFeePerGas={maxFeePerGas} |
|
|
|
|
setMaxFeePerGas={setMaxFeePerGas} |
|
|
|
|
maxFeePerGasFiat={maxFeePerGasFiat} |
|
|
|
|
estimatedMaximumNative={estimatedMaximumNative} |
|
|
|
|
isGasEstimatesLoading={isGasEstimatesLoading} |
|
|
|
|
gasFeeEstimates={gasFeeEstimates} |
|
|
|
|
gasEstimateType={gasEstimateType} |
|
|
|
|
gasPrice={gasPrice} |
|
|
|
|
setGasPrice={setGasPrice} |
|
|
|
|
gasLimit={gasLimit} |
|
|
|
|
setGasLimit={setGasLimit} |
|
|
|
|
estimateToUse={estimateToUse} |
|
|
|
|
setEstimateToUse={setEstimateToUse} |
|
|
|
|
estimatedMinimumFiat={estimatedMinimumFiat} |
|
|
|
|
estimatedMaximumFiat={estimatedMaximumFiat} |
|
|
|
|
isMaxFeeError={isMaxFeeError} |
|
|
|
|
isMaxPriorityFeeError={isMaxPriorityFeeError} |
|
|
|
|
isGasTooLow={isGasTooLow} |
|
|
|
|
onEducationClick={() => setShowEducationContent(true)} |
|
|
|
|
mode={mode} |
|
|
|
|
{...editGasDisplayProps} |
|
|
|
|
/> |
|
|
|
|
)} |
|
|
|
|
</div> |
|
|
|
@ -123,15 +226,8 @@ EditGasPopover.propTypes = { |
|
|
|
|
popoverTitle: PropTypes.string, |
|
|
|
|
editGasDisplayProps: PropTypes.object, |
|
|
|
|
confirmButtonText: PropTypes.string, |
|
|
|
|
showEducationButton: PropTypes.bool, |
|
|
|
|
onClose: PropTypes.func, |
|
|
|
|
transaction: PropTypes.object, |
|
|
|
|
mode: PropTypes.oneOf(Object.values(EDIT_GAS_MODE)), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
EditGasPopover.defaultProps = { |
|
|
|
|
popoverTitle: '', |
|
|
|
|
editGasDisplayProps: {}, |
|
|
|
|
confirmButtonText: '', |
|
|
|
|
showEducationButton: false, |
|
|
|
|
mode: PropTypes.oneOf(Object.values(EDIT_GAS_MODES)), |
|
|
|
|
defaultEstimateToUse: PropTypes.string, |
|
|
|
|
}; |
|
|
|
|