import React, { useEffect, useState } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import Box from '../../../ui/box'; import Typography from '../../../ui/typography'; import CheckBox from '../../../ui/check-box'; import { COLORS, DISPLAY, FLEX_DIRECTION, TYPOGRAPHY, } from '../../../../helpers/constants/design-system'; import { getAdvancedGasFeeValues } from '../../../../selectors'; import { setAdvancedGasFee } from '../../../../store/actions'; import { useAdvancedGasFeePopoverContext } from '../context'; import { useI18nContext } from '../../../../hooks/useI18nContext'; const AdvancedGasFeeDefaults = () => { const t = useI18nContext(); const dispatch = useDispatch(); const { hasErrors, maxBaseFee, maxPriorityFeePerGas, } = useAdvancedGasFeePopoverContext(); const advancedGasFeeValues = useSelector(getAdvancedGasFeeValues); 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); } else { dispatch( setAdvancedGasFee({ maxBaseFee, priorityFee: maxPriorityFeePerGas, }), ); setDefaultSettingsSelected(true); } }; return ( ); }; export default AdvancedGasFeeDefaults;