Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dropdown acount menu #206

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/LoadAccountMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,25 @@ const StyledBox = styled(Box)(({ theme }) => ({
}))
export const LoadAccountMenu = (props: {
type: string
setOpen?: React.Dispatch<React.SetStateAction<boolean>>
selectedAlias?: string
updateAlias?: any
}) => {
const ref = useRef(null)
const dispatch = useAppDispatch()
const setAccount = account => dispatch(updateAccount(account))
const { updateStore } = useWallet()
function closeSelect() {
props.setOpen(v => !v)
}
const dispatchNotification = ({ message, type }) =>
dispatch(updateNotificationStatus({ message, severity: type }))
useEffectOnce(() => {
mountAccountMenu(ref.current, {
...props,
setAccount,
dispatchNotification,

closeSelect,
updateStore,
})
}) // eslint-disable-line react-hooks/exhaustive-deps
Expand Down
45 changes: 29 additions & 16 deletions src/components/Navbar/Account.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Chip, MenuItem, MenuList, Select, Typography, useTheme } from '@mui/material'
import React, { useEffect } from 'react'
import { mdiCog, mdiLogout } from '@mdi/js'
import { Box, Chip, MenuItem, MenuList, Select, Typography, useTheme } from '@mui/material'
import React, { useEffect, useState } from 'react'
import { getNameOfWallet, getPchainAddress } from '../../helpers/walletStore'
import { useAppDispatch, useAppSelector } from '../../hooks/reduxHooks'
import {
changeActiveApp,
getAccount,
updateAccount,
updatePchainAddress,
} from '../../redux/slices/app-config'
import { getNameOfWallet, getPchainAddress } from '../../helpers/walletStore'
import { mdiCog, mdiLogout } from '@mdi/js'
import { useAppDispatch, useAppSelector } from '../../hooks/reduxHooks'

import AliasPicker from './AliasPicker'
import Icon from '@mdi/react'
import { LoadAccountMenu } from '../LoadAccountMenu'
import MHidden from '../@material-extend/MHidden'
import { LoadAccountMenu } from '../LoadAccountMenu'
import AliasPicker from './AliasPicker'
import ThemeSwitcher from './ThemeSwitcher'
// @ts-ignore
import { useNavigate } from 'react-router-dom'
import store from 'wallet/store'
import { updateAuthStatus } from '../../redux/slices/utils'
import { useNavigate } from 'react-router-dom'

interface LoginIconProps {
handleCloseSidebar: () => void
Expand Down Expand Up @@ -47,11 +47,11 @@
dispatch(
updatePchainAddress({ address: getPchainAddress(), walletName: getNameOfWallet() }),
)
}, [auth])

Check warning on line 50 in src/components/Navbar/Account.tsx

View workflow job for this annotation

GitHub Actions / yarn-build

React Hook useEffect has a missing dependency: 'dispatch'. Either include it or remove the dependency array
const handleKeyDown = e => {
e.stopPropagation()
}

const [open, setOpen] = useState(false)
return (
<>
<MHidden width="smUp">
Expand Down Expand Up @@ -108,16 +108,21 @@
<>
{auth && (
<Select
open={open}
value={
!account ? (
<Typography>Account</Typography>
) : (
<LoadAccountMenu type="" />
<Box onClick={() => setOpen(v => !v)}>
<LoadAccountMenu type="" />
</Box>
)
}
renderValue={() =>
account ? (
<LoadAccountMenu type="" />
<Box onClick={() => setOpen(v => !v)}>
<LoadAccountMenu type="" />
</Box>
) : (
<Typography>Account</Typography>
)
Expand All @@ -130,14 +135,19 @@
onKeyDown={e => {
handleKeyDown(e)
}}
MenuProps={{
onClick: e => {
e.preventDefault()
},
}}
>
<MenuItem
onKeyDown={e => {
handleKeyDown(e)
}}
sx={{ typography: 'body2', width: '100%', maxWidth: '326px' }}
>
<LoadAccountMenu type="kyc" />
<LoadAccountMenu type="kyc" setOpen={setOpen} />
</MenuItem>
<MenuItem
onKeyDown={e => {
Expand All @@ -164,10 +174,13 @@
}}
label="beta"
/>
<LoadAccountMenu type="kyb" />
<LoadAccountMenu type="kyb" setOpen={setOpen} />
</MenuItem>
<MenuItem
onClick={() => navigate('/settings')}
onClick={() => {
navigate('/settings')
setOpen(v => !v)
}}
onKeyDown={e => {
handleKeyDown(e)
}}
Expand All @@ -184,9 +197,9 @@
<Icon path={mdiCog} size={1} />
<Typography variant="body2">Settings</Typography>
</MenuItem>
<AliasPicker handleKeyDown={handleKeyDown} />
<AliasPicker setOpenSelect={setOpen} handleKeyDown={handleKeyDown} />
<MenuItem>
<ThemeSwitcher />
<ThemeSwitcher setOpen={setOpen} />
</MenuItem>
<MenuItem
onKeyDown={e => handleKeyDown(e)}
Expand Down
9 changes: 8 additions & 1 deletion src/components/Navbar/AliasPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ import DialogAnimate from '../Animate/DialogAnimate'
import LoadMyKeysComponent from './LoadMyKeysComponent'
import LoadSaveKeysComponent from './LoadSaveKeysComponent'

const AliasPicker = ({ handleKeyDown }: { handleKeyDown: (e: any) => void }) => {
const AliasPicker = ({
handleKeyDown,
setOpenSelect,
}: {
handleKeyDown: (e: any) => void
setOpenSelect: React.Dispatch<React.SetStateAction<boolean>>
}) => {
const [open, setOpen] = useState(false)
const [load, setLoad] = useState(false)
const handleOpenModal = () => {
Expand All @@ -32,6 +38,7 @@ const AliasPicker = ({ handleKeyDown }: { handleKeyDown: (e: any) => void }) =>
}
const handleCloseModal = () => {
setOpen(false)
setOpenSelect(v => !v)
}
useEffect(() => {
showButton()
Expand Down
11 changes: 6 additions & 5 deletions src/components/Navbar/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Button, Typography, useTheme } from '@mui/material'
import { getTheme, toggleTheme } from '../../redux/slices/theme'
import { useAppDispatch, useAppSelector } from '../../hooks/reduxHooks'
import { getTheme, toggleTheme } from '../../redux/slices/theme'

import Icon from '@mdi/react'
import React from 'react'
import { mdiWhiteBalanceSunny } from '@mdi/js'
import store from 'wallet/store'
import Icon from '@mdi/react'
import { useStore } from 'Explorer/useStore'
import React, { Dispatch, SetStateAction } from 'react'
import store from 'wallet/store'
import useWidth from '../../hooks/useWidth'

export default function ThemeSwitcher() {
export default function ThemeSwitcher({ setOpen }: { setOpen: Dispatch<SetStateAction<boolean>> }) {
const { isDesktop, isMobile } = useWidth()
const dispatch = useAppDispatch()
const theme = useTheme()
Expand All @@ -23,6 +23,7 @@ export default function ThemeSwitcher() {
changeTheme(currentTheme === 'light' ? 'dark' : 'light')
store.commit('updateTheme')
dispatch(toggleTheme())
setOpen(v => !v)
}

return (
Expand Down
Loading