fix: closes settings state when MP is closed (#7065)

* fix: close settings menu on drawer close

* migrate change to default menu

* remove indent

* add cleanup
This commit is contained in:
Brendan Wong 2023-08-02 19:06:57 -04:00 committed by GitHub
parent f90066263e
commit 2c1e608f84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

@ -1,7 +1,7 @@
import { useWeb3React } from '@web3-react/core'
import Column from 'components/Column'
import WalletModal from 'components/WalletModal'
import { useCallback, useState } from 'react'
import { useCallback, useEffect, useState } from 'react'
import styled from 'styled-components/macro'
import AuthenticatedHeader from './AuthenticatedHeader'
@ -17,7 +17,7 @@ enum MenuState {
SETTINGS,
}
function DefaultMenu() {
function DefaultMenu({ drawerOpen }: { drawerOpen: boolean }) {
const { account } = useWeb3React()
const isAuthenticated = !!account
@ -25,6 +25,17 @@ function DefaultMenu() {
const openSettings = useCallback(() => setMenu(MenuState.SETTINGS), [])
const closeSettings = useCallback(() => setMenu(MenuState.DEFAULT), [])
useEffect(() => {
if (!drawerOpen && menu === MenuState.SETTINGS) {
// wait for the drawer to close before resetting the menu
const timer = setTimeout(() => {
closeSettings()
}, 250)
return () => clearTimeout(timer)
}
return
}, [drawerOpen, menu, closeSettings])
return (
<DefaultMenuWrap>
{menu === MenuState.DEFAULT &&

@ -257,7 +257,7 @@ function AccountDrawer() {
>
{/* id used for child InfiniteScrolls to reference when it has reached the bottom of the component */}
<AccountDrawerScrollWrapper ref={scrollRef} id="wallet-dropdown-scroll-wrapper">
<DefaultMenu />
<DefaultMenu drawerOpen={walletDrawerOpen} />
</AccountDrawerScrollWrapper>
</AccountDrawerWrapper>
</Container>