Skip to content

Commit

Permalink
update network switcher placment
Browse files Browse the repository at this point in the history
  • Loading branch information
aeddaqqa committed Nov 24, 2023
1 parent 67b554b commit 8974076
Show file tree
Hide file tree
Showing 10 changed files with 366 additions and 84 deletions.
16 changes: 16 additions & 0 deletions src/components/LongString.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Typography } from '@mui/material'
import React from 'react'
import { displayFirstPartLongString, displaySecondPartLongString } from '../utils/display-utils'
const LongString = ({ value }) => {
const content =
value && value.length < 12 ? (
<Typography>{value}</Typography>
) : (
<Typography>
{displayFirstPartLongString(value)}&hellip;
{displaySecondPartLongString(value)}
</Typography>
)
return <>{content}</>
}
export default LongString
195 changes: 195 additions & 0 deletions src/components/Navbar/Account.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
import { mdiCogOutline, mdiLogout } from '@mdi/js'
import Icon from '@mdi/react'
import { Chip, IconButton, MenuItem, MenuList, Select, Typography, useTheme } from '@mui/material'
import React, { useEffect } from 'react'
import { useNavigate } from 'react-router-dom'
import store from 'wallet/store'
import {
getNameOfMultiSigWallet,
getPchainAddress,
isMultiSigWallet,
} from '../../helpers/walletStore'
import { useAppDispatch, useAppSelector } from '../../hooks/reduxHooks'
import { changeActiveApp, getAccount, updateAccount } from '../../redux/slices/app-config'
import { updateAuthStatus } from '../../redux/slices/utils'
import MHidden from '../@material-extend/MHidden'
import { LoadAccountMenu } from '../LoadAccountMenu'
import AliasPicker from './AliasPicker'
import ThemeSwitcher from './ThemeSwitcher'

interface LoginIconProps {
handleCloseSidebar: () => void
}

export default function Account({ handleCloseSidebar }: LoginIconProps) {
const auth = useAppSelector(state => state.appConfig.isAuth)
const [walletName, setWalletName] = React.useState('')

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

View workflow job for this annotation

GitHub Actions / yarn-build

'walletName' is assigned a value but never used
const dispatch = useAppDispatch()
const navigate = useNavigate()
const account = useAppSelector(getAccount)
const theme = useTheme()
const logout = async () => {
handleCloseSidebar()
await store.dispatch('logout')
dispatch(updateAccount(null))
dispatch(updateAuthStatus(false))
dispatch(changeActiveApp('Network'))
navigate('/')
}

const navigateToSettings = () => {
navigate('/settings')
handleCloseSidebar()
}
useEffect(() => {
if (isMultiSigWallet()) {
setWalletName(getNameOfMultiSigWallet() || getPchainAddress())
} else setWalletName(getPchainAddress())
}, [auth])

const handleKeyDown = e => {
e.stopPropagation()
}

return (
<>
<MHidden width="smUp">
<MenuList sx={{ backgroundColor: 'transparent' }}>
<MenuItem onClick={navigateToSettings}>
<IconButton>
<Icon path={mdiCogOutline} size={0.8} />
</IconButton>
<Typography variant="body1">Settings</Typography>
</MenuItem>
{auth && <AliasPicker />}
<MenuItem>
<LoadAccountMenu type="kyc" />
</MenuItem>
<MenuItem sx={{ position: 'relative' }}>
<LoadAccountMenu type="kyb" />
<Chip
color="secondary"
size="small"
sx={{
position: 'absolute',
fontSize: '12px',
height: '16px',
top: 0,
right: { xs: '0.3rem', sm: 0 },
}}
label="beta"
/>
</MenuItem>
<MenuItem onClick={logout} sx={{ display: 'flex' }}>
<IconButton>
<Icon path={mdiLogout} size={0.8} />
</IconButton>
<Typography variant="body1">logout</Typography>
</MenuItem>
</MenuList>
</MHidden>
<MHidden width="smDown">
<>
{auth && (
<Select
value={
!account ? (
<Typography>Account</Typography>
) : (
<LoadAccountMenu type="" />
)
}
renderValue={() =>
account ? (
<LoadAccountMenu type="" />
) : (
<Typography>Account</Typography>
)
}
sx={{
maxWidth: '13rem',
'.MuiOutlinedInput-notchedOutline': { border: 'none' },
'.MuiSvgIcon-root': { color: theme.palette.text.primary },
}}
onKeyDown={e => {
handleKeyDown(e)
}}
>
<MenuItem
onKeyDown={e => {
handleKeyDown(e)
}}
sx={{ typography: 'body2', width: '100%', maxWidth: '326px' }}
>
<LoadAccountMenu type="kyc" />
</MenuItem>
<MenuItem
onKeyDown={e => {
handleKeyDown(e)
}}
sx={{
typography: 'body1',
width: '100%',
maxWidth: '326px',
position: 'relative',
}}
>
<Chip
color="secondary"
size="small"
sx={{
position: 'absolute',
fontSize: '12px',
height: '16px',
top: 0,
right: { xs: '0.3rem', sm: 0 },
}}
label="beta"
/>
<LoadAccountMenu type="kyb" />
</MenuItem>
<MenuItem
onClick={() => navigate('/settings')}
onKeyDown={e => {
handleKeyDown(e)
}}
sx={{
typography: 'body2',
width: '100%',
maxWidth: '326px',
justifyContent: { xs: 'flex-end', sm: 'center' },
}}
>
<IconButton>
<Icon path={mdiCogOutline} size={0.7} />
</IconButton>
<Typography variant="body1">Settings</Typography>
</MenuItem>
<AliasPicker />
<MenuItem>
<ThemeSwitcher />
</MenuItem>
<MenuItem
onKeyDown={e => handleKeyDown(e)}
onClick={logout}
sx={{
typography: 'body2',
width: '100%',
maxWidth: '326px',
display: 'flex',
justifyContent: { xs: 'flex-end', sm: 'center' },
gap: '0.3rem',
}}
>
<IconButton>
<Icon path={mdiLogout} size={0.7} />
</IconButton>
<Typography variant="body1">logout</Typography>
</MenuItem>
</Select>
)}
</>
</MHidden>
</>
)
}
28 changes: 19 additions & 9 deletions src/components/Navbar/AliasPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { mdiClose } from '@mdi/js'
import { mdiClose, mdiOpenInNew } from '@mdi/js'
import Icon from '@mdi/react'
import { Box, DialogContent, DialogTitle, Divider, Typography, IconButton } from '@mui/material'
import {
Box,
DialogContent,
DialogTitle,
Divider,
IconButton,
MenuItem,
Typography,
} from '@mui/material'
import React, { useEffect, useState } from 'react'
import store from 'wallet/store'
import { getMultisigAliases } from '../../api'
import { useAppSelector } from '../../hooks/reduxHooks'
import { getShowButton } from '../../redux/slices/app-config'
import DialogAnimate from '../Animate/DialogAnimate'
import MainButton from '../MainButton'
import LoadMyKeysComponent from './LoadMyKeysComponent'
import LoadSaveKeysComponent from './LoadSaveKeysComponent'

Expand All @@ -31,14 +38,17 @@ const AliasPicker = () => {
}, [showButtonState])
if (!load) return <></>
return (
<>
<MainButton
variant="outlined"
<MenuItem
sx={{ display: 'flex', alignItems: 'center', justifyContent: 'start', gap: '8px' }}
>
<Icon path={mdiOpenInNew} size={1} />
<Typography
variant="body2"
onClick={handleOpenModal}
style={{ width: '100%', whiteSpace: 'nowrap', padding: '0.5rem 1rem' }}
style={{ width: '100%', whiteSpace: 'nowrap' }}
>
Switch Wallet
</MainButton>
</Typography>
<DialogAnimate open={open} onClose={handleCloseModal}>
<DialogTitle sx={{ m: 0, p: 2 }}>
<Typography variant="h4" component="span">
Expand Down Expand Up @@ -74,7 +84,7 @@ const AliasPicker = () => {
<LoadMyKeysComponent />
</DialogContent>
</DialogAnimate>
</>
</MenuItem>
)
}

Expand Down
15 changes: 9 additions & 6 deletions src/components/Navbar/LoadMyKeysComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useRef } from 'react'
import { Box } from '@mui/material'
import { styled } from '@mui/system'
import React, { useEffect, useRef } from 'react'
import { mountKyesComponent } from 'wallet/mountKyesComponent'
import { useAppDispatch } from '../../hooks/reduxHooks'
import { updateNotificationStatus } from '../../redux/slices/app-config'
import { useEffectOnce } from '../../hooks/useEffectOnce'
import { styled } from '@mui/system'
import { Box } from '@mui/material'
import { updateNotificationStatus, updatePchainAddress } from '../../redux/slices/app-config'

const StyledBox = styled(Box)(({ theme }) => ({
display: 'flex',
Expand Down Expand Up @@ -40,13 +40,16 @@ const StyledBox = styled(Box)(({ theme }) => ({
const LoadMyKeysComponent = () => {
const ref = useRef(null)
const dispatch = useAppDispatch()

const [walletSwitched, setWalletSwitched] = React.useState('')
const dispatchNotification = ({ message, type }) =>
dispatch(updateNotificationStatus({ message, severity: type }))
useEffectOnce(() => {
mountKyesComponent(ref.current, { dispatchNotification })
mountKyesComponent(ref.current, { dispatchNotification, setWalletSwitched })
}) // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
dispatch(updatePchainAddress(walletSwitched))
}, [walletSwitched])

Check warning on line 52 in src/components/Navbar/LoadMyKeysComponent.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
return (
<StyledBox>
<div ref={ref} />
Expand Down
31 changes: 31 additions & 0 deletions src/components/Navbar/LoggedInAccount.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { mdiWalletOutline } from '@mdi/js'
import Icon from '@mdi/react'
import React, { useEffect, useState } from 'react'
import {
getNameOfMultiSigWallet,
getPchainAddress,
isMultiSigWallet,
} from '../../helpers/walletStore'
import { useAppSelector } from '../../hooks/reduxHooks'
import { getPChainAddress } from '../../redux/slices/app-config'
import { getActiveNetwork } from '../../redux/slices/network'
import LongString from '../LongString'

const LoggedInAccount = () => {
const [walletName, setWalletName] = useState('')
const pChainAddress = useAppSelector(getPChainAddress)
const activeNetwork = useAppSelector(getActiveNetwork)

useEffect(() => {
if (isMultiSigWallet()) {
setWalletName(getNameOfMultiSigWallet() || getPchainAddress()[0])
} else setWalletName(getPchainAddress()[0])
}, [pChainAddress, activeNetwork])
return (
<>
<Icon path={mdiWalletOutline} size={1} />
<LongString value={walletName} />
</>
)
}
export default LoggedInAccount
13 changes: 7 additions & 6 deletions src/components/Navbar/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import React from 'react'
import { useAppDispatch, useAppSelector } from '../../hooks/reduxHooks'
import { toggleTheme } from '../../redux/slices/theme'
import { Button, Typography, useTheme } from '@mui/material'
import { mdiWeatherSunny } from '@mdi/js'
import Icon from '@mdi/react'
import useWidth from '../../hooks/useWidth'
import { Button, Typography, useTheme } from '@mui/material'
import { useStore } from 'Explorer/useStore'
import { getTheme } from '../../redux/slices/theme'
import React from 'react'
import store from 'wallet/store'
import { useAppDispatch, useAppSelector } from '../../hooks/reduxHooks'
import useWidth from '../../hooks/useWidth'
import { getTheme, toggleTheme } from '../../redux/slices/theme'

export default function ThemeSwitcher() {
const { isDesktop } = useWidth()
const dispatch = useAppDispatch()
const theme = useTheme()
const currentTheme = useAppSelector(getTheme)
const { changeTheme } = useStore()
const auth = useAppSelector(state => state.appConfig.isAuth)

Check warning on line 17 in src/components/Navbar/ThemeSwitcher.tsx

View workflow job for this annotation

GitHub Actions / yarn-build

'auth' is assigned a value but never used
return (
<Button
variant="text"
Expand All @@ -32,6 +32,7 @@ export default function ThemeSwitcher() {
minWidth: 'auto',
'&:hover': { backgroundColor: 'transparent' },
'.MuiButton-startIcon': { mr: isDesktop ? '0.5rem' : '0rem' },
...(true && { width: '100%' }),
}}
>
{isDesktop && <Typography variant="body2">{theme.palette.mode}</Typography>}
Expand Down
Loading

0 comments on commit 8974076

Please sign in to comment.