1
- import react , { useEffect , useMemo } from 'react' ;
1
+ import react , { useEffect , useMemo , useState } from 'react' ;
2
2
import { BrowserRouter as Router , Link , Route , Routes , useLocation , useNavigate } from 'react-router-dom' ;
3
3
import './App.css' ;
4
4
import 'antd/dist/reset.css' ;
@@ -19,7 +19,7 @@ import {
19
19
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
20
20
import { faBroadcastTower , faHandHolding , faIdCard , faWallet , } from '@fortawesome/free-solid-svg-icons' ;
21
21
22
- import { Badge , Breadcrumb , Layout , Menu , Switch as ToggleSwitch } from 'antd' ;
22
+ import { Badge , Breadcrumb , Layout , Menu , MenuProps , Switch as ToggleSwitch } from 'antd' ;
23
23
import { AccountState } from "./Components/AccountSelector" ;
24
24
import { Workbox } from "workbox-window" ;
25
25
import AppVersion , { useUpdateAvailable } from "./Pages/AppVersion" ;
@@ -38,9 +38,11 @@ const App = () => {
38
38
const navigate = useNavigate ( ) ;
39
39
const location = useLocation ( ) ;
40
40
const updateAvailable = useUpdateAvailable ( ) ;
41
+ const [ navigateTo , setNavigateTo ] = useState ( '/account/' ) ;
41
42
function goHome ( ) {
42
43
navigate ( "/account/" ) ;
43
44
}
45
+
44
46
const refreshApp = ( ) => {
45
47
const workbox = new Workbox ( process . env . PUBLIC_URL + "/service-worker.js" ) ;
46
48
workbox . addEventListener ( 'controlling' , ( ) => {
@@ -62,6 +64,9 @@ const App = () => {
62
64
if ( [ AccountState . valid ] . includes ( accountInformation . state ! ) ) navigate ( `/${ page } /${ accountInformation . account ! . id } ` , { replace : true } ) ;
63
65
}
64
66
} , [ accountInformation , navigate , location . pathname ] ) ;
67
+ useEffect ( ( ) => {
68
+ navigate ( navigateTo ) ;
69
+ } , [ navigate , navigateTo ] ) ;
65
70
66
71
const worker = useMemo ( ( ) =>
67
72
new Worker ( new URL ( './updateAccountWorker.tsx' , import . meta. url ) , { type : "module" } ) ,
@@ -96,6 +101,86 @@ const App = () => {
96
101
// eslint-disable-next-line
97
102
} , [ accountInformation . account , usePublicNetwork ] ) ;
98
103
104
+
105
+ type AntMenuItem = Required < MenuProps > [ 'items' ] [ number ] ;
106
+ const menuItems : AntMenuItem [ ] = [
107
+ {
108
+ key : 'account' ,
109
+ label : 'Stellar Account' ,
110
+ icon : < FontAwesomeIcon icon = { faWallet } /> ,
111
+ onClick : ( ) => setNavigateTo ( '/account/' ) ,
112
+ children : [
113
+ {
114
+ key : 'account:overview' ,
115
+ label : 'Account overview' ,
116
+ icon : < FontAwesomeIcon icon = { faIdCard } /> ,
117
+ onClick : ( ) => setNavigateTo ( '/account/' ) ,
118
+ } ,
119
+ {
120
+ key : 'account:claim' ,
121
+ label : 'Claim balances' ,
122
+ icon : < FontAwesomeIcon icon = { faIdCard } /> ,
123
+ onClick : ( ) => setNavigateTo ( '/claim/' ) ,
124
+ } ,
125
+ ]
126
+ } ,
127
+ {
128
+ key : 'settings' ,
129
+ label : 'Settings' ,
130
+ icon : < SettingOutlined /> ,
131
+ children : [
132
+ {
133
+ type : 'group' ,
134
+ label : 'Network' ,
135
+ children : [
136
+ {
137
+ label : 'Network' ,
138
+ key : 'settings:toggleNetwork' ,
139
+ icon : < FontAwesomeIcon icon = { faBroadcastTower } /> ,
140
+ children : [
141
+ {
142
+ icon : < ToggleSwitch checkedChildren = "Public" unCheckedChildren = "Testnet" onChange = { setUsePublicNetwork } checked = { usePublicNetwork } />
143
+ }
144
+ ]
145
+ } as AntMenuItem
146
+ ] ,
147
+ } ,
148
+ {
149
+ type : 'group' ,
150
+ label : 'Account overview' ,
151
+ children : [
152
+ {
153
+ label : 'Load market for balances' ,
154
+ key : 'settings:loadMarket' ,
155
+ } ,
156
+ {
157
+ label : 'Paginate balances list' ,
158
+ key : 'settings:paginateBalances' ,
159
+ }
160
+ ] ,
161
+ }
162
+ ] ,
163
+ } ,
164
+ {
165
+ key : 'about' ,
166
+ label : 'About this site' ,
167
+ icon : < InfoCircleOutlined /> ,
168
+ onClick : ( ) => setNavigateTo ( '/about' ) ,
169
+ } ,
170
+ {
171
+ key : 'privacy' ,
172
+ label : 'Privacy information' ,
173
+ icon : < SafetyOutlined /> ,
174
+ onClick : ( ) => setNavigateTo ( '/privacy' ) ,
175
+ } ,
176
+ {
177
+ key : 'app:version' ,
178
+ label : "App Version" + ( updateAvailable ?" - update available" :"" ) ,
179
+ icon : < Badge count = { menuCollapsed && updateAvailable ?1 :0 } dot offset = { [ 0 , 8 ] } > < ApiOutlined style = { { color : "lightgray" } } /> </ Badge > ,
180
+ children : [ < AppVersion style = { { color : "lightgray" } } /> ]
181
+ } as AntMenuItem
182
+ ] ;
183
+
99
184
return (
100
185
< Layout className = "App" >
101
186
< Sider
@@ -110,7 +195,7 @@ const App = () => {
110
195
left : 0 ,
111
196
} } >
112
197
{ /*<div><img src={logo} className="App-logo" alt="logo"/></div>*/ }
113
- < Menu forceSubMenuRender = { true } theme = "dark" mode = "vertical" selectable = { false } >
198
+ < Menu forceSubMenuRender = { true } theme = "dark" mode = "vertical" selectable = { false } items = { menuItems } >
114
199
< SubMenu title = "Stellar Account" key = "account" icon = { < FontAwesomeIcon icon = { faWallet } /> } onTitleClick = { goHome } >
115
200
< MenuItem title = "Account overview" icon = { < FontAwesomeIcon icon = { faIdCard } /> } key = "account:overview" >
116
201
< Link to = "/account/" > Account overview</ Link >
0 commit comments