@@ -2,13 +2,15 @@ import { ChainId } from '@kyberswap/ks-sdk-core'
2
2
import { Trans } from '@lingui/macro'
3
3
import { rgba } from 'polished'
4
4
import { stringify } from 'querystring'
5
- import { useEffect } from 'react'
5
+ import { useEffect , useState } from 'react'
6
6
import { isMobile } from 'react-device-detect'
7
7
import { useLocation , useNavigate } from 'react-router-dom'
8
8
import { useMedia } from 'react-use'
9
9
import { Flex , Text } from 'rebass'
10
10
11
11
import { ReactComponent as DropdownSVG } from 'assets/svg/down.svg'
12
+ import ElasticHackedModal from 'components/ElasticHackedModal'
13
+ import { APP_PATHS } from 'constants/index'
12
14
import { CLASSIC_NOT_SUPPORTED , ELASTIC_NOT_SUPPORTED } from 'constants/networks'
13
15
import { VERSION } from 'constants/v2'
14
16
import { useActiveWeb3React } from 'hooks'
@@ -28,27 +30,41 @@ function ClassicElasticTab() {
28
30
const shouldShowFarmTab = ! ! farmPositions . length || ! ! claimInfo
29
31
const shouldShowPositionTab = ! ! positions . length
30
32
31
- const { tab : tabQS = VERSION . ELASTIC , ...qs } = useParsedQueryString < { tab : string } > ( )
33
+ const { tab : tabQS = VERSION . ELASTIC , skipAlert , ...qs } = useParsedQueryString < { tab : string } > ( )
32
34
33
35
const tab = isInEnum ( tabQS , VERSION ) ? tabQS : VERSION . ELASTIC
34
36
35
37
const { chainId } = useActiveWeb3React ( )
36
- const notSupportedMsg = ELASTIC_NOT_SUPPORTED [ chainId ]
38
+ const notSupportedElasticMsg = ELASTIC_NOT_SUPPORTED [ chainId ]
37
39
38
40
const notSupportedClassicMsg = CLASSIC_NOT_SUPPORTED [ chainId ]
39
41
40
42
const theme = useTheme ( )
41
43
const location = useLocation ( )
42
44
const navigate = useNavigate ( )
43
45
44
- const isFarmpage = location . pathname . includes ( '/farms' )
46
+ const isFarmPage = location . pathname . startsWith ( APP_PATHS . FARMS )
47
+ const isMyPoolPage = location . pathname . startsWith ( APP_PATHS . MY_POOLS )
48
+ const [ isOpenElasticHacked , setOpenElasticHacked ] = useState (
49
+ tab === VERSION . ELASTIC && ! notSupportedElasticMsg && ! skipAlert ,
50
+ )
51
+
52
+ useEffect ( ( ) => {
53
+ if ( notSupportedClassicMsg ) {
54
+ setOpenElasticHacked ( ! skipAlert )
55
+ }
56
+ if ( tab === VERSION . ELASTIC && ! notSupportedElasticMsg ) {
57
+ setOpenElasticHacked ( ! skipAlert )
58
+ }
59
+ // eslint-disable-next-line react-hooks/exhaustive-deps
60
+ } , [ chainId ] )
45
61
46
62
const upToMedium = useMedia ( `(max-width: ${ MEDIA_WIDTHS . upToMedium } px)` )
47
63
48
64
const dontShowLegacy = [ ChainId . ZKEVM , ChainId . BASE , ChainId . LINEA , ChainId . SCROLL ] . includes ( chainId )
49
65
50
66
const showLegacyExplicit =
51
- upToMedium || dontShowLegacy ? false : isFarmpage ? shouldShowFarmTab : shouldShowPositionTab
67
+ upToMedium || dontShowLegacy ? false : isFarmPage ? shouldShowFarmTab : shouldShowPositionTab
52
68
53
69
useEffect ( ( ) => {
54
70
if ( dontShowLegacy && tab === VERSION . ELASTIC_LEGACY ) {
@@ -77,13 +93,13 @@ function ClassicElasticTab() {
77
93
78
94
const handleSwitchTab = ( version : VERSION ) => {
79
95
if ( ! ! notSupportedClassicMsg && version === VERSION . CLASSIC ) return
80
- if ( ! ! notSupportedMsg && version !== VERSION . CLASSIC ) return
96
+ if ( ! ! notSupportedElasticMsg && version !== VERSION . CLASSIC ) return
81
97
const newQs = { ...qs , tab : version }
82
98
navigate ( { search : stringify ( newQs ) } , { replace : true } )
83
99
}
84
100
85
101
const getColorOfElasticTab = ( ) => {
86
- if ( ! ! notSupportedMsg ) {
102
+ if ( ! ! notSupportedElasticMsg ) {
87
103
return theme . disableText
88
104
}
89
105
@@ -114,7 +130,7 @@ function ClassicElasticTab() {
114
130
}
115
131
116
132
const getColorOfLegacyElasticTab = ( ) => {
117
- if ( ! ! notSupportedMsg ) {
133
+ if ( ! ! notSupportedElasticMsg ) {
118
134
return theme . disableText
119
135
}
120
136
@@ -128,11 +144,11 @@ function ClassicElasticTab() {
128
144
if ( ! ! notSupportedClassicMsg && tab === VERSION . CLASSIC ) {
129
145
const newQs = { ...qs , tab : VERSION . ELASTIC }
130
146
navigate ( { search : stringify ( newQs ) } , { replace : true } )
131
- } else if ( ! ! notSupportedMsg && tab !== VERSION . CLASSIC ) {
147
+ } else if ( ! ! notSupportedElasticMsg && tab !== VERSION . CLASSIC ) {
132
148
const newQs = { ...qs , tab : VERSION . CLASSIC }
133
149
navigate ( { search : stringify ( newQs ) } , { replace : true } )
134
150
}
135
- } , [ navigate , notSupportedMsg , notSupportedClassicMsg , qs , tab ] )
151
+ } , [ navigate , notSupportedElasticMsg , notSupportedClassicMsg , qs , tab ] )
136
152
137
153
return (
138
154
< Flex width = "max-content" >
@@ -144,7 +160,7 @@ function ClassicElasticTab() {
144
160
? ''
145
161
: tab === VERSION . CLASSIC && notSupportedClassicMsg
146
162
? notSupportedClassicMsg
147
- : notSupportedMsg ||
163
+ : notSupportedElasticMsg ||
148
164
( ! showLegacyExplicit ? (
149
165
< Flex flexDirection = "column" sx = { { gap : '16px' , padding : '8px' } } >
150
166
< Flex
@@ -156,7 +172,7 @@ function ClassicElasticTab() {
156
172
onClick = { ( ) => handleSwitchTab ( VERSION . ELASTIC ) }
157
173
>
158
174
< PoolElasticIcon size = { 16 } />
159
- { isFarmpage ? < Trans > Elastic Farms</ Trans > : < Trans > Elastic Pools</ Trans > }
175
+ { isFarmPage ? < Trans > Elastic Farms</ Trans > : < Trans > Elastic Pools</ Trans > }
160
176
</ Flex >
161
177
162
178
< Flex
@@ -168,7 +184,7 @@ function ClassicElasticTab() {
168
184
onClick = { ( ) => handleSwitchTab ( VERSION . ELASTIC_LEGACY ) }
169
185
>
170
186
< PoolElasticIcon size = { 16 } />
171
- { isFarmpage ? < Trans > Elastic Farms</ Trans > : < Trans > Elastic Pools</ Trans > }
187
+ { isFarmPage ? < Trans > Elastic Farms</ Trans > : < Trans > Elastic Pools</ Trans > }
172
188
{ legacyTag ( true ) }
173
189
</ Flex >
174
190
</ Flex >
@@ -192,10 +208,10 @@ function ClassicElasticTab() {
192
208
marginLeft = "4px"
193
209
role = "button"
194
210
style = { {
195
- cursor : ! ! notSupportedMsg ? 'not-allowed' : 'pointer' ,
211
+ cursor : ! ! notSupportedElasticMsg ? 'not-allowed' : 'pointer' ,
196
212
} }
197
213
>
198
- { isFarmpage ? < Trans > Elastic Farms</ Trans > : < Trans > Elastic Pools</ Trans > }
214
+ { isFarmPage ? < Trans > Elastic Farms</ Trans > : < Trans > Elastic Pools</ Trans > }
199
215
</ Text >
200
216
201
217
{ ! showLegacyExplicit && tab === VERSION . ELASTIC_LEGACY && legacyTag ( ) }
@@ -209,7 +225,7 @@ function ClassicElasticTab() {
209
225
210
226
{ showLegacyExplicit && (
211
227
< >
212
- < MouseoverTooltip text = { notSupportedMsg || '' } placement = "top" >
228
+ < MouseoverTooltip text = { notSupportedElasticMsg || '' } placement = "top" >
213
229
< Flex
214
230
sx = { { position : 'relative' } }
215
231
alignItems = { 'center' }
@@ -226,10 +242,10 @@ function ClassicElasticTab() {
226
242
marginLeft = "4px"
227
243
role = "button"
228
244
style = { {
229
- cursor : ! ! notSupportedMsg ? 'not-allowed' : 'pointer' ,
245
+ cursor : ! ! notSupportedElasticMsg ? 'not-allowed' : 'pointer' ,
230
246
} }
231
247
>
232
- { isFarmpage ? < Trans > Elastic Farms</ Trans > : < Trans > Elastic Pools</ Trans > }
248
+ { isFarmPage ? < Trans > Elastic Farms</ Trans > : < Trans > Elastic Pools</ Trans > }
233
249
</ Text >
234
250
{ legacyTag ( ) }
235
251
</ Flex >
@@ -257,10 +273,26 @@ function ClassicElasticTab() {
257
273
style = { { cursor : 'pointer' } }
258
274
role = "button"
259
275
>
260
- { isFarmpage ? < Trans > Classic Farms</ Trans > : < Trans > Classic Pools</ Trans > }
276
+ { isFarmPage ? < Trans > Classic Farms</ Trans > : < Trans > Classic Pools</ Trans > }
261
277
</ Text >
262
278
</ Flex >
263
279
</ MouseoverTooltip >
280
+
281
+ < ElasticHackedModal
282
+ isOpen = { isOpenElasticHacked }
283
+ onClose = { ( ) => {
284
+ setOpenElasticHacked ( false )
285
+ if ( ! isMyPoolPage ) {
286
+ handleSwitchTab ( VERSION . CLASSIC )
287
+ }
288
+ } }
289
+ onConfirm = { ( ) => {
290
+ setOpenElasticHacked ( false )
291
+ if ( ! isMyPoolPage ) {
292
+ navigate ( { pathname : APP_PATHS . MY_POOLS , search : 'skipAlert=1' } )
293
+ }
294
+ } }
295
+ />
264
296
</ Flex >
265
297
)
266
298
}
0 commit comments