Skip to content

Commit

Permalink
close drawer when sub item menu clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
reallybeard committed May 6, 2024
1 parent daac3b4 commit 213fd70
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
23 changes: 13 additions & 10 deletions src/components/Layout/Header/NavBar/Native/NativeMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
import { ChevronRightIcon, EditIcon } from '@chakra-ui/icons'
import { Button, MenuDivider, MenuItem } from '@chakra-ui/react'
import { useCallback } from 'react'
import React, { useCallback } from 'react'
import { useTranslate } from 'react-polyglot'
import { Text } from 'components/Text'
import { useFeatureFlag } from 'hooks/useFeatureFlag/useFeatureFlag'
import { useModal } from 'hooks/useModal/useModal'

const chevronRightIcon = <ChevronRightIcon />
const editIcon = <EditIcon />
type NativeMenuProps = {
onClose?: () => void
}

export const NativeMenu = () => {
export const NativeMenu: React.FC<NativeMenuProps> = ({ onClose }) => {
const translate = useTranslate()
const isAccountManagementEnabled = useFeatureFlag('AccountManagement')

const backupNativePassphrase = useModal('backupNativePassphrase')
const accountManagementPopover = useModal('manageAccounts')

const handleBackupMenuItemClick = useCallback(
() => backupNativePassphrase.open({}),
[backupNativePassphrase],
)
const handleBackupMenuItemClick = useCallback(() => {
onClose && onClose()
backupNativePassphrase.open({})
}, [backupNativePassphrase, onClose])

const handleManageAccountsMenuItemClick = useCallback(
() => accountManagementPopover.open({}),
[accountManagementPopover],
)
const handleManageAccountsMenuItemClick = useCallback(() => {
onClose && onClose()
accountManagementPopover.open({})
}, [accountManagementPopover, onClose])

return (
<>
Expand Down
3 changes: 3 additions & 0 deletions src/components/Layout/Header/NavBar/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const NoWallet = ({ onClick }: { onClick: () => void }) => {
export type WalletConnectedProps = {
onDisconnect: () => void
onSwitchProvider: () => void
onClose?: () => void
} & Pick<InitialState, 'walletInfo' | 'isConnected' | 'connectedType'>

export const WalletConnected = (props: WalletConnectedProps) => {
Expand All @@ -60,6 +61,7 @@ export const WalletConnected = (props: WalletConnectedProps) => {
onDisconnect={props.onDisconnect}
onSwitchProvider={props.onSwitchProvider}
connectedType={props.connectedType}
onClose={props.onClose}
/>
</MemoryRouter>
)
Expand Down Expand Up @@ -191,6 +193,7 @@ export const UserMenu: React.FC<{ onClick?: () => void }> = memo(({ onClick }) =
onDisconnect={disconnect}
onSwitchProvider={handleConnect}
connectedType={connectedType}
onClose={onClick}
/>
) : (
<NoWallet onClick={handleConnect} />
Expand Down
5 changes: 4 additions & 1 deletion src/components/Layout/Header/NavBar/WalletConnectedMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const ConnectedMenu = memo(
walletInfo,
onDisconnect,
onSwitchProvider,
onClose,
}: WalletConnectedProps & {
connectedWalletMenuRoutes: boolean
}) => {
Expand Down Expand Up @@ -74,7 +75,7 @@ const ConnectedMenu = memo(
{translate('connectWallet.menu.connecting')}
</MenuItem>
)}
{ConnectMenuComponent && <ConnectMenuComponent />}
{ConnectMenuComponent && <ConnectMenuComponent onClose={onClose} />}
<MenuDivider />
<MenuItem icon={repeatIcon} onClick={onSwitchProvider}>
{translate('connectWallet.menu.switchWallet')}
Expand All @@ -94,6 +95,7 @@ export const WalletConnectedMenu = ({
walletInfo,
isConnected,
connectedType,
onClose,
}: WalletConnectedProps) => {
const location = useLocation()

Expand Down Expand Up @@ -128,6 +130,7 @@ export const WalletConnectedMenu = ({
walletInfo={walletInfo}
onDisconnect={onDisconnect}
onSwitchProvider={onSwitchProvider}
onClose={onClose}
/>
</SubMenuContainer>
</Route>
Expand Down

0 comments on commit 213fd70

Please sign in to comment.