1
1
import { Menu } from '@mantine/core'
2
- import React , { useContext } from 'react'
2
+ import React from 'react'
3
+ import walletState from 'frontend/state/WalletState'
4
+ import { observer } from 'mobx-react-lite'
5
+
3
6
import Wallet from 'frontend/components/UI/Wallet'
4
7
import styles from './index.module.scss'
5
8
import { NavLink } from 'react-router-dom'
6
9
import onboardingStore from 'frontend/store/OnboardingStore'
7
10
import { useTranslation } from 'react-i18next'
8
- import ContextProvider from 'frontend/state/ContextProvider '
11
+ import { PROVIDERS } from 'common/types/proxy-types '
9
12
10
- function NavigationMenuItem ( { label, to } : { label : string ; to : string } ) {
11
- const { showMetaMaskBrowserSidebarLinks } = useContext ( ContextProvider )
13
+ function NavigationMenuItem ( {
14
+ label,
15
+ to,
16
+ showMetaMaskExtensionLinks
17
+ } : {
18
+ label : string
19
+ to : string
20
+ showMetaMaskExtensionLinks : boolean
21
+ } ) {
12
22
return (
13
23
< Menu . Item
14
24
className = { styles . menuItem }
15
- id = {
16
- showMetaMaskBrowserSidebarLinks
17
- ? 'topMenuItemWalletDropdown'
18
- : undefined
19
- }
25
+ id = { showMetaMaskExtensionLinks ? 'topMenuItemWalletDropdown' : undefined }
20
26
>
21
27
< NavLink
22
28
to = { to }
23
- id = {
24
- showMetaMaskBrowserSidebarLinks
25
- ? 'topElementWalletDropdown'
26
- : undefined
27
- }
29
+ id = { showMetaMaskExtensionLinks ? 'topElementWalletDropdown' : undefined }
28
30
>
29
31
< div className = { `body ${ styles . itemContents } ` } > { label } </ div >
30
32
</ NavLink >
31
33
</ Menu . Item >
32
34
)
33
35
}
34
36
35
- export default function AccountDropdown ( ) {
37
+ const WalletDropdown : React . FC = observer ( ( ) => {
36
38
const { t } = useTranslation ( )
37
- const { showMetaMaskBrowserSidebarLinks } = useContext ( ContextProvider )
39
+ const showWalletConnectedLinks = walletState . isConnected
40
+ const showMetaMaskExtensionLinks =
41
+ walletState . isConnected &&
42
+ walletState . provider === PROVIDERS . METAMASK_EXTENSION
43
+
38
44
return (
39
45
< Menu position = "bottom" trigger = "hover" >
40
46
< Menu . Target >
@@ -50,48 +56,54 @@ export default function AccountDropdown() {
50
56
< Menu . Label className = { styles . menuLabel } >
51
57
{ t ( 'hyperplay.currentWallet' , `Current wallet` ) }
52
58
</ Menu . Label >
53
- { showMetaMaskBrowserSidebarLinks && (
59
+ { showMetaMaskExtensionLinks && (
54
60
< >
55
61
< NavigationMenuItem
56
62
label = { t ( 'hyperplay.viewFullscreen' , `View fullscreen` ) }
57
63
to = { '/metamaskHome' }
64
+ showMetaMaskExtensionLinks = { showMetaMaskExtensionLinks }
58
65
> </ NavigationMenuItem >
59
66
< NavigationMenuItem
60
67
label = { t ( 'hyperplay.viewItem' , {
61
68
defaultValue : 'View {{item}}' ,
62
69
item : 'Snaps'
63
70
} ) }
71
+ showMetaMaskExtensionLinks = { showMetaMaskExtensionLinks }
64
72
to = { '/metamaskSnaps' }
65
73
> </ NavigationMenuItem >
66
74
</ >
67
75
) }
68
- < Menu . Item
69
- className = { `${ styles . menuItem } ` }
70
- id = {
71
- ! showMetaMaskBrowserSidebarLinks
72
- ? 'topMenuItemWalletDropdown'
73
- : undefined
74
- }
75
- >
76
- < NavLink
77
- to = { '/metamaskPortfolio' }
76
+ { showWalletConnectedLinks && (
77
+ < Menu . Item
78
+ className = { `${ styles . menuItem } ` }
78
79
id = {
79
- ! showMetaMaskBrowserSidebarLinks
80
- ? 'topElementWalletDropdown '
80
+ ! showWalletConnectedLinks
81
+ ? 'topMenuItemWalletDropdown '
81
82
: undefined
82
83
}
83
84
>
84
- < div className = { `body ${ styles . itemContents } ` } >
85
- { t ( 'hyperplay.viewPortfolio' , `View portfolio` ) }
86
- </ div >
87
- </ NavLink >
88
- </ Menu . Item >
85
+ < NavLink
86
+ to = { '/metamaskPortfolio' }
87
+ id = {
88
+ ! showWalletConnectedLinks
89
+ ? 'topElementWalletDropdown'
90
+ : undefined
91
+ }
92
+ >
93
+ < div className = { `body ${ styles . itemContents } ` } >
94
+ { t ( 'hyperplay.viewPortfolio' , `View portfolio` ) }
95
+ </ div >
96
+ </ NavLink >
97
+ </ Menu . Item >
98
+ ) }
89
99
< Menu . Item
90
100
className = { `${ styles . menuItem } ` }
91
101
onClick = { ( ) => onboardingStore . openOnboarding ( ) }
92
102
>
93
103
< div className = { `body ${ styles . itemContents } ` } >
94
- { t ( 'hyperplay.changeWallet' , `Change wallet` ) }
104
+ { showWalletConnectedLinks
105
+ ? t ( 'hyperplay.changeWallet' , `Change wallet` )
106
+ : t ( 'hyperplay.connectWallet' , `Connect wallet` ) }
95
107
</ div >
96
108
</ Menu . Item >
97
109
< Menu . Label className = { styles . menuLabel } >
@@ -107,4 +119,6 @@ export default function AccountDropdown() {
107
119
</ Menu . Dropdown >
108
120
</ Menu >
109
121
)
110
- }
122
+ } )
123
+
124
+ export default WalletDropdown
0 commit comments