2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
4
import { MenuItem , MenuItemType } from '@subwallet/extension-web-ui/components/Layout/parts/SideMenu/MenuItem' ;
5
- import { FAQS_URL , SUPPORT_MAIL , TERMS_OF_SERVICE_URL } from '@subwallet/extension-web-ui/constants' ;
6
- import { useNotification , useTranslation } from '@subwallet/extension-web-ui/hooks' ;
5
+ import { FAQS_URL , MISSIONS_POOL_LIVE_ID , SUPPORT_MAIL , TERMS_OF_SERVICE_URL } from '@subwallet/extension-web-ui/constants' ;
6
+ import { useNotification , useSelector , useTranslation } from '@subwallet/extension-web-ui/hooks' ;
7
+ import { useLocalStorage } from '@subwallet/extension-web-ui/hooks/common/useLocalStorage' ;
7
8
import usePreloadView from '@subwallet/extension-web-ui/hooks/router/usePreloadView' ;
9
+ import { RootState } from '@subwallet/extension-web-ui/stores' ;
8
10
import { ThemeProps } from '@subwallet/extension-web-ui/types' ;
9
- import { openInNewTab } from '@subwallet/extension-web-ui/utils' ;
11
+ import { computeStatus , openInNewTab } from '@subwallet/extension-web-ui/utils' ;
10
12
import { Button , Icon , Image } from '@subwallet/react-ui' ;
11
13
import CN from 'classnames' ;
12
- import { ArrowCircleLeft , ArrowCircleRight , ArrowsLeftRight , Clock , Gear , MessengerLogo , NewspaperClipping , Vault , Wallet } from 'phosphor-react' ;
14
+ import { ArrowCircleLeft , ArrowCircleRight , ArrowsLeftRight , Clock , Gear , MessengerLogo , NewspaperClipping , Parachute , Vault , Wallet } from 'phosphor-react' ;
13
15
import React , { useCallback , useEffect , useMemo , useState } from 'react' ;
14
16
import { useLocation , useNavigate } from 'react-router-dom' ;
15
17
@@ -27,6 +29,20 @@ function Component ({ className,
27
29
const { t } = useTranslation ( ) ;
28
30
const notify = useNotification ( ) ;
29
31
32
+ const { missions } = useSelector ( ( state : RootState ) => state . missionPool ) ;
33
+
34
+ const [ storedLiveMissionIds , setStoredLiveMissionIds ] = useLocalStorage < number [ ] > ( MISSIONS_POOL_LIVE_ID , [ ] ) ;
35
+
36
+ const liveMissionIds = useMemo ( ( ) => {
37
+ return missions
38
+ . filter ( ( item ) => computeStatus ( item ) === 'live' )
39
+ . map ( ( mission ) => mission . id ) ;
40
+ } , [ missions ] ) ;
41
+
42
+ const latestLiveMissionIds = useMemo ( ( ) => {
43
+ return liveMissionIds . filter ( ( id ) => ! storedLiveMissionIds . includes ( id ) ) ;
44
+ } , [ liveMissionIds , storedLiveMissionIds ] ) ;
45
+
30
46
usePreloadView ( [
31
47
'Home' ,
32
48
'Tokens' ,
@@ -73,23 +89,23 @@ function Component ({ className,
73
89
// weight: 'fill'
74
90
// }
75
91
// },
76
- // {
77
- // label: t('Mission Pools'),
78
- // value: '/home/mission-pools',
79
- // icon: {
80
- // type: 'customIcon',
81
- // customIcon: (
82
- // <>
83
- // <Icon
84
- // phosphorIcon={Parachute}
85
- // type='phosphor'
86
- // weight='fill'
87
- // />
88
- // {(latestLiveMissionIds.length > 0) && <div className={CN('__active-count')}>{latestLiveMissionIds.length}</div> }
89
- // </>
90
- // )
91
- // }
92
- // },
92
+ {
93
+ label : t ( 'Mission Pools' ) ,
94
+ value : '/home/mission-pools' ,
95
+ icon : {
96
+ type : 'customIcon' ,
97
+ customIcon : (
98
+ < >
99
+ < Icon
100
+ phosphorIcon = { Parachute }
101
+ type = 'phosphor'
102
+ weight = 'fill'
103
+ />
104
+ { ( latestLiveMissionIds . length > 0 ) && < div className = { CN ( '__active-count' ) } > { latestLiveMissionIds . length } </ div > }
105
+ </ >
106
+ )
107
+ }
108
+ } ,
93
109
// {
94
110
// label: t('Crowdloans'),
95
111
// value: '/home/crowdloans',
@@ -136,7 +152,7 @@ function Component ({ className,
136
152
}
137
153
}
138
154
] ;
139
- } , [ t ] ) ;
155
+ } , [ latestLiveMissionIds . length , t ] ) ;
140
156
141
157
const staticMenuItems = useMemo < MenuItemType [ ] > ( ( ) => {
142
158
return [
@@ -194,8 +210,12 @@ function Component ({ className,
194
210
return ;
195
211
}
196
212
213
+ if ( value === '/home/mission-pools' && latestLiveMissionIds . length > 0 ) {
214
+ setStoredLiveMissionIds ( liveMissionIds ) ;
215
+ }
216
+
197
217
navigate ( `${ value } ` ) ;
198
- } , [ navigate , showComingSoon ] ) ;
218
+ } , [ latestLiveMissionIds . length , liveMissionIds , navigate , setStoredLiveMissionIds , showComingSoon ] ) ;
199
219
200
220
const goHome = useCallback ( ( ) => {
201
221
navigate ( '/home' ) ;
0 commit comments