1- import { Box , IconButton , Toolbar } from '@mui/material'
2- import { Button , NavLink } from '../library'
1+ import { Box , Toolbar } from '@mui/material'
32import { styled } from '@mui/material/styles'
4- import { useEffect , useMemo } from 'react'
53import MuiAppBar from '@mui/material/AppBar'
6- import MultiProxySelection from '../select/MultiProxySelection'
7- import { useAccounts } from '../../contexts/AccountsContext'
8- import { HiOutlineWallet , HiOutlineBars3 as MenuIcon } from 'react-icons/hi2'
9- import { MENU_ROUTES } from '../../pages/routes'
10- import { isEmptyArray } from '../../utils/arrayUtils'
11- import NetworkSelection from '../select/NetworkSelection'
124import multixLogo from '../../logos/multix-logo.svg'
13- import useWalletConnectEventsManager from '../../hooks/useWalletConnectEventsManager'
14- import { Link , createSearchParams , useSearchParams } from 'react-router'
15- import { useSwitchAddress } from '../../hooks/useSwitchAddress'
16- import { ConnectionDialog } from 'dot-connect/react.js'
17-
18- interface Props {
19- handleDrawerOpen : ( ) => void
20- }
21-
22- const Header = ( { handleDrawerOpen } : Props ) => {
23- const {
24- selectedAccount,
25- ownAccountList,
26- selectAccount,
27- isConnectionDialogOpen,
28- setIsConnectionDialogOpen,
29- allowConnectionToExtension
30- } = useAccounts ( )
31- const isAccountConnected = useMemo ( ( ) => ! isEmptyArray ( ownAccountList ) , [ ownAccountList ] )
32- const [ params ] = useSearchParams ( )
33-
34- useWalletConnectEventsManager ( )
35- useSwitchAddress ( )
36-
37- useEffect ( ( ) => {
38- if ( ! selectedAccount ?. address && ownAccountList . length > 0 ) {
39- selectAccount ( ownAccountList [ 0 ] )
40- setIsConnectionDialogOpen ( false )
41- }
42- } , [ ownAccountList , selectAccount , selectedAccount ?. address , setIsConnectionDialogOpen ] )
5+ import { Link } from 'react-router'
436
7+ const Header = ( ) => {
448 return (
45- < >
46- < MuiAppBarStyled position = "sticky" >
47- < Toolbar >
48- < LogoWrapperStyled >
49- < HomeLinkStyled to = "/" >
50- < LogoStyled
51- src = { multixLogo }
52- alt = { `Multix logo` }
53- />
54- </ HomeLinkStyled >
55- </ LogoWrapperStyled >
56- < DesktopMenuStyled data-cy = "menu-desktop" >
57- < MenuWrapperStyled >
58- { MENU_ROUTES . map ( ( { path, name, isDisplayWhenNoWallet } ) => {
59- const paramsString = createSearchParams ( params ) . toString ( )
60-
61- return isAccountConnected || isDisplayWhenNoWallet ? (
62- < NavLink
63- key = { name }
64- to = { `${ path } ?${ paramsString } ` }
65- data-cy = { `button-navigate-${ name . toLowerCase ( ) . replace ( / / g, '-' ) } ` }
66- >
67- { name }
68- </ NavLink >
69- ) : null
70- } ) }
71- </ MenuWrapperStyled >
72- < RightButtonsWrapperStyled >
73- { ownAccountList . length === 0 && (
74- < ConnectButtonStyled
75- data-cy = "button-menu-connect"
76- onClick = { ( ) => {
77- setIsConnectionDialogOpen ( true )
78- allowConnectionToExtension ( )
79- } }
80- variant = "primary"
81- >
82- Connect
83- </ ConnectButtonStyled >
84- ) }
85- < MultiProxySelection testId = "desktop" />
86- < NetworkSelectionStyled />
87- { ownAccountList . length > 0 && (
88- < IconButtonStyled
89- data-cy = "button-wallet"
90- aria-label = "wallet"
91- onClick = { ( ) => setIsConnectionDialogOpen ( true ) }
92- >
93- < HiOutlineWallet size = { 20 } />
94- </ IconButtonStyled >
95- ) }
96- </ RightButtonsWrapperStyled >
97- </ DesktopMenuStyled >
98- < MobileIconButtonStyled
99- color = "inherit"
100- aria-label = "open drawer"
101- edge = "end"
102- onClick = { handleDrawerOpen }
103- >
104- < MenuIcon />
105- </ MobileIconButtonStyled >
106- </ Toolbar >
107- </ MuiAppBarStyled >
108- { isConnectionDialogOpen && (
109- < ConnectionDialog
110- data-cy = "dialog-connection"
111- open = { isConnectionDialogOpen }
112- onClose = { ( ) => setIsConnectionDialogOpen ( false ) }
113- />
114- ) }
115- </ >
9+ < MuiAppBarStyled position = "sticky" >
10+ < Toolbar >
11+ < LogoWrapperStyled >
12+ < HomeLinkStyled to = "/" >
13+ < LogoStyled
14+ src = { multixLogo }
15+ alt = { `Multix logo` }
16+ />
17+ </ HomeLinkStyled >
18+ </ LogoWrapperStyled >
19+ </ Toolbar >
20+ </ MuiAppBarStyled >
11621 )
11722}
11823
@@ -129,39 +34,6 @@ const HomeLinkStyled = styled(Link)`
12934 display: flex;
13035`
13136
132- const ConnectButtonStyled = styled ( Button ) `
133- margin-right: 1rem;
134- `
135-
136- const RightButtonsWrapperStyled = styled ( Box ) `
137- width: 100%;
138- display: flex;
139- align-items: center;
140- justify-content: flex-end;
141- flex: 1;
142- `
143-
144- const MenuWrapperStyled = styled ( Box ) `
145- width: 100%;
146- display: flex;
147- align-items: center;
148- `
149-
150- const DesktopMenuStyled = styled ( Box ) `
151- display: none;
152-
153- @media (min-width: ${ ( { theme } ) => theme . breakpoints . values . md } px) {
154- width: 100%;
155- flex-grow: 0;
156- display: flex;
157- align-items: center;
158- }
159-
160- @media (min-width: ${ ( { theme } ) => theme . breakpoints . values . lg } px) {
161- flex-grow: 1;
162- }
163- `
164-
16537const LogoWrapperStyled = styled ( Box ) `
16638 display: flex;
16739 align-items: center;
@@ -177,25 +49,7 @@ const LogoWrapperStyled = styled(Box)`
17749 }
17850`
17951
180- const NetworkSelectionStyled = styled ( NetworkSelection ) `
181- margin-left: 0.5rem;
182- `
183-
18452const LogoStyled = styled ( 'img' ) `
18553 height: 3rem;
18654`
187-
188- const IconButtonStyled = styled ( IconButton ) `
189- margin-left: 1rem;
190- `
191-
192- const MobileIconButtonStyled = styled ( IconButton ) `
193- display: block;
194- color: black;
195-
196- @media (min-width: ${ ( { theme } ) => theme . breakpoints . values . md } px) {
197- display: none;
198- }
199- `
200-
20155export default Header
0 commit comments