diff --git a/src/custom/components/AccountDetails/index.tsx b/src/custom/components/AccountDetails/index.tsx index 188758d28c..dc280887e9 100644 --- a/src/custom/components/AccountDetails/index.tsx +++ b/src/custom/components/AccountDetails/index.tsx @@ -123,7 +123,7 @@ interface AccountDetailsProps { confirmedTransactions: string[] ENSName?: string toggleWalletModal: () => void - closeOrdersPanel: () => void + handleCloseOrdersPanel: () => void } export default function AccountDetails({ @@ -131,7 +131,7 @@ export default function AccountDetails({ confirmedTransactions = [], ENSName, toggleWalletModal, - closeOrdersPanel, + handleCloseOrdersPanel, }: AccountDetailsProps) { const { account, connector, chainId: connectedChainId } = useActiveWeb3React() const chainId = supportedChainId(connectedChainId) @@ -148,7 +148,7 @@ export default function AccountDetails({ const handleDisconnectClick = () => { ;(connector as any).close() localStorage.removeItem(STORAGE_KEY_LAST_PROVIDER) - closeOrdersPanel() + handleCloseOrdersPanel() toggleWalletModal() } diff --git a/src/custom/components/Header/index.tsx b/src/custom/components/Header/index.tsx index 0abab38ef9..90f6ef6c22 100644 --- a/src/custom/components/Header/index.tsx +++ b/src/custom/components/Header/index.tsx @@ -6,7 +6,7 @@ import ReactGA from 'react-ga4' import { useActiveWeb3React } from 'hooks/web3' import { useNativeCurrencyBalances } from 'state/wallet/hooks' import { useDarkModeManager } from 'state/user/hooks' -import { useMediaQuery, upToSmall, upToLarge } from 'hooks/useMediaQuery' +import { useMediaQuery, upToSmall, upToMedium, upToLarge, LargeAndUp } from 'hooks/useMediaQuery' import { AMOUNT_PRECISION } from 'constants/index' import { MAIN_MENU, MAIN_MENU_TYPE } from 'constants/mainMenu' import { supportedChainId } from 'utils/supportedChainId' @@ -77,32 +77,47 @@ export default function Header() { }, [toggleDarkModeAux, darkMode]) const [isOrdersPanelOpen, setIsOrdersPanelOpen] = useState(false) - const closeOrdersPanel = () => setIsOrdersPanelOpen(false) - const openOrdersPanel = () => account && setIsOrdersPanelOpen(true) + const handleOpenOrdersPanel = () => { + account && setIsOrdersPanelOpen(true) + account && isOrdersPanelOpen && addBodyClass('noScroll') + } + const handleCloseOrdersPanel = () => { + setIsOrdersPanelOpen(false) + !isOrdersPanelOpen && removeBodyClass('noScroll') + } const history = useHistory() const handleBalanceButtonClick = () => history.push('/account') const isUpToLarge = useMediaQuery(upToLarge) + const isUpToMedium = useMediaQuery(upToMedium) const isUpToSmall = useMediaQuery(upToSmall) + const isLargeAndUp = useMediaQuery(LargeAndUp) const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false) - const handleMobileMenuOnClick = useCallback( - () => isUpToLarge && setIsMobileMenuOpen(!isMobileMenuOpen), - [isUpToLarge, isMobileMenuOpen] - ) + const handleMobileMenuOnClick = useCallback(() => { + isUpToLarge && setIsMobileMenuOpen(!isMobileMenuOpen) + }, [isUpToLarge, isMobileMenuOpen]) + + const [isTouch, setIsTouch] = useState(false) // Toggle the 'noScroll' class on body, whenever the orders panel is open. // This removes the inner scrollbar on the page body, to prevent showing double scrollbars. useEffect(() => { - isUpToLarge && isMobileMenuOpen ? addBodyClass('noScroll') : removeBodyClass('noScroll') - isOrdersPanelOpen ? addBodyClass('noScroll') : removeBodyClass('noScroll') - }, [isOrdersPanelOpen, isMobileMenuOpen, isUpToLarge]) + isMobileMenuOpen ? addBodyClass('noScroll') : removeBodyClass('noScroll') + // Set if device has touch capabilities + setIsTouch('ontouchstart' in document.documentElement) + }, [isOrdersPanelOpen, isMobileMenuOpen, isUpToLarge, isUpToMedium, isUpToSmall, isLargeAndUp]) const getMainMenu = useMemo( () => MAIN_MENU.map(({ title, url, externalURL, items }: MAIN_MENU_TYPE, index) => !items && !externalURL && url ? ( - + {title} ) : !items && externalURL && url ? ( @@ -120,8 +135,8 @@ export default function Header() {