import React, { useEffect, useState } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { useTransactionEventFragment } from '../../../../hooks/useTransactionEventFragment'; import { EditGasModes } from '../../../../../shared/constants/gas'; import Box from '../../../ui/box'; import Typography from '../../../ui/typography'; import CheckBox from '../../../ui/check-box'; import { DISPLAY, FLEX_DIRECTION, TextColor, TypographyVariant, } from '../../../../helpers/constants/design-system'; import { getAdvancedGasFeeValues } from '../../../../selectors'; import { setAdvancedGasFee } from '../../../../store/actions'; import { useGasFeeContext } from '../../../../contexts/gasFee'; import { useAdvancedGasFeePopoverContext } from '../context'; import { useI18nContext } from '../../../../hooks/useI18nContext'; const AdvancedGasFeeDefaults = () => { const t = useI18nContext(); const dispatch = useDispatch(); const { gasErrors, maxBaseFee, maxPriorityFeePerGas } = useAdvancedGasFeePopoverContext(); const advancedGasFeeValues = useSelector(getAdvancedGasFeeValues); const { updateTransactionEventFragment } = useTransactionEventFragment(); const { editGasMode } = useGasFeeContext(); const [isDefaultSettingsSelected, setDefaultSettingsSelected] = useState( Boolean(advancedGasFeeValues) && advancedGasFeeValues.maxBaseFee === maxBaseFee && advancedGasFeeValues.priorityFee === maxPriorityFeePerGas, ); useEffect(() => { setDefaultSettingsSelected( Boolean(advancedGasFeeValues) && advancedGasFeeValues.maxBaseFee === maxBaseFee && advancedGasFeeValues.priorityFee === maxPriorityFeePerGas, ); }, [advancedGasFeeValues, maxBaseFee, maxPriorityFeePerGas]); const handleUpdateDefaultSettings = () => { if (isDefaultSettingsSelected) { dispatch(setAdvancedGasFee(null)); setDefaultSettingsSelected(false); updateTransactionEventFragment({ properties: { advanced_gas_defaults_updated_maxbasefee: null, advanced_gas_defaults_updated_priorityfee: null, }, }); } else { dispatch( setAdvancedGasFee({ maxBaseFee, priorityFee: maxPriorityFeePerGas, }), ); updateTransactionEventFragment({ properties: { advanced_gas_defaults_updated_maxbasefee: maxBaseFee, advanced_gas_defaults_updated_priorityfee: maxPriorityFeePerGas, }, }); } }; if (editGasMode === EditGasModes.swaps) { return null; } return ( ); }; export default AdvancedGasFeeDefaults;