diff --git a/src/components/Dialog/index.tsx b/src/components/Dialog/index.tsx index 99c6c9df..a172dd5f 100644 --- a/src/components/Dialog/index.tsx +++ b/src/components/Dialog/index.tsx @@ -5,7 +5,7 @@ import { CloseButton } from '../buttons/CloseButton'; interface DialogProps { visible: boolean; - onClose: () => void; + onClose?: () => void; headerText?: string; content: JSX.Element; actions?: JSX.Element; @@ -14,10 +14,23 @@ interface DialogProps { className?: string; }; id?: string; + disableNativeEvents?: boolean; + hideCloseButton?: boolean; } -export const Dialog: FC = ({ visible, onClose, headerText, content, actions, id, form }) => { +export const Dialog: FC = ({ + visible, + onClose, + headerText, + content, + actions, + id, + form, + disableNativeEvents = false, + hideCloseButton = false, +}) => { const ref = useRef(null); + const dialog = ref.current; // If it was the form submission we want to only close the dialog without calling onClose const [isSubmitting, setIsSubmitting] = useState(false); @@ -31,7 +44,7 @@ export const Dialog: FC = ({ visible, onClose, headerText, content, } dialog.close(); - onClose(); + onClose && onClose(); }, [isSubmitting, onClose], ); @@ -45,7 +58,6 @@ export const Dialog: FC = ({ visible, onClose, headerText, content, // Manage native events and visibility useEffect(() => { - const dialog = ref.current; if (dialog) { dialog.addEventListener('close', closeListener); if (visible && !dialog.open) { @@ -58,7 +70,25 @@ export const Dialog: FC = ({ visible, onClose, headerText, content, dialog.removeEventListener('close', closeListener); }; } - }, [visible, closeListener, headerText]); + }, [visible, closeListener, headerText, dialog]); + + // This useEffect handles disableNativeEvents ( prevents the dialog from closing on Escape key press ) + useEffect(() => { + if (!disableNativeEvents || !dialog) return; + + const handleKeyDown = (e: KeyboardEvent) => { + if (disableNativeEvents && e.key === 'Escape') { + e.preventDefault(); + return; + } + }; + + dialog.addEventListener('keydown', handleKeyDown); + + return () => { + dialog.removeEventListener('keydown', handleKeyDown); + }; + }, [disableNativeEvents, headerText, dialog]); const handleFormSubmit = (event: Event) => { if (form) { @@ -79,9 +109,14 @@ export const Dialog: FC = ({ visible, onClose, headerText, content, ); return createPortal( - + - {headerText} + {headerText} {hideCloseButton ? <> : } {form ? (
diff --git a/src/components/TermsAndConditions/index.tsx b/src/components/TermsAndConditions/index.tsx new file mode 100644 index 00000000..89dce6b3 --- /dev/null +++ b/src/components/TermsAndConditions/index.tsx @@ -0,0 +1,50 @@ +import { useState } from 'preact/compat'; +import { Button, Checkbox, Link } from 'react-daisyui'; +import { useLocalStorage } from '../../hooks/useLocalStorage'; +import { Dialog } from '../Dialog'; + +export const TermsAndConditions = () => { + const { set, state } = useLocalStorage({ key: 'TERMS_AND_CONDITIONS' }); + const [checked, setChecked] = useState(false); + + const acceptTerms = () => { + set('accepted'); + }; + + const content = ( + <> +
+ + View Terms and Conditions + +
+
+ setChecked(!checked)} color="primary" size="md" /> + I have read and accept the terms and conditions +
+ + ); + + const actions = ( + + ); + + return ( + + ); +}; diff --git a/src/pages/swap/index.tsx b/src/pages/swap/index.tsx index 9debc865..8a6d17d1 100644 --- a/src/pages/swap/index.tsx +++ b/src/pages/swap/index.tsx @@ -23,6 +23,7 @@ import { useMainProcess } from '../../hooks/useMainProcess'; import { ProgressPage } from '../progress'; import { SuccessPage } from '../success'; import { FailurePage } from '../failure'; +import { TermsAndConditions } from '../../components/TermsAndConditions'; import { useInputTokenBalance } from '../../hooks/useInputTokenBalance'; import { UserBalance } from '../../components/UserBalance'; @@ -209,13 +210,17 @@ export const SwapPage = () => { })); const modals = ( - setModalType(undefined)} - /> + <> + + setModalType(undefined)} + isLoading={false} + /> + ); if (offrampingPhase === 'success') {