diff --git a/src/components/LongString.tsx b/src/components/LongString.tsx new file mode 100644 index 00000000..922e5756 --- /dev/null +++ b/src/components/LongString.tsx @@ -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 ? ( + {value} + ) : ( + + {displayFirstPartLongString(value)}… + {displaySecondPartLongString(value)} + + ) + return <>{content} +} +export default LongString diff --git a/src/components/Navbar/Account.tsx b/src/components/Navbar/Account.tsx new file mode 100644 index 00000000..9ebfe9b8 --- /dev/null +++ b/src/components/Navbar/Account.tsx @@ -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('') + 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 ( + <> + + + + + + + Settings + + {auth && } + + + + + + + + + + + + logout + + + + + <> + {auth && ( + + )} + + + + ) +} diff --git a/src/components/Navbar/AliasPicker.tsx b/src/components/Navbar/AliasPicker.tsx index 9e74e5d0..52a4aee8 100644 --- a/src/components/Navbar/AliasPicker.tsx +++ b/src/components/Navbar/AliasPicker.tsx @@ -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' @@ -31,14 +38,17 @@ const AliasPicker = () => { }, [showButtonState]) if (!load) return <> return ( - <> - + + Switch Wallet - + @@ -74,7 +84,7 @@ const AliasPicker = () => { - + ) } diff --git a/src/components/Navbar/LoadMyKeysComponent.tsx b/src/components/Navbar/LoadMyKeysComponent.tsx index f5b01f9f..b6828948 100644 --- a/src/components/Navbar/LoadMyKeysComponent.tsx +++ b/src/components/Navbar/LoadMyKeysComponent.tsx @@ -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', @@ -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]) return (
diff --git a/src/components/Navbar/LoggedInAccount.tsx b/src/components/Navbar/LoggedInAccount.tsx new file mode 100644 index 00000000..6834fac1 --- /dev/null +++ b/src/components/Navbar/LoggedInAccount.tsx @@ -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 ( + <> + + + + ) +} +export default LoggedInAccount diff --git a/src/components/Navbar/ThemeSwitcher.tsx b/src/components/Navbar/ThemeSwitcher.tsx index a35929ec..c060fceb 100644 --- a/src/components/Navbar/ThemeSwitcher.tsx +++ b/src/components/Navbar/ThemeSwitcher.tsx @@ -1,13 +1,12 @@ -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() @@ -15,6 +14,7 @@ export default function ThemeSwitcher() { const theme = useTheme() const currentTheme = useAppSelector(getTheme) const { changeTheme } = useStore() + const auth = useAppSelector(state => state.appConfig.isAuth) return (