@@ -8,13 +8,16 @@ import {
8
8
updateDailyRaysData ,
9
9
} from 'components/portfolio/helpers/getRaysDailyChallenge'
10
10
import { SkeletonLine } from 'components/Skeleton'
11
- import { jwtAuthGetToken } from 'features/shared/jwt'
11
+ import { currentContent } from 'features/content'
12
+ import { checkAcceptanceFromApi$ } from 'features/termsOfService/termsAcceptanceApi'
12
13
import { TermsOfService } from 'features/termsOfService/TermsOfService'
13
14
import { useWalletManagement } from 'features/web3OnBoard/useConnection'
14
15
import { bonusRaysAmount , dailyRaysAmount , explodeRays } from 'helpers/dailyRays'
15
16
import { getGradientColor , summerBrandGradient } from 'helpers/getGradientColor'
17
+ import { useObservable } from 'helpers/observableHook'
16
18
import { staticFilesRuntimeUrl } from 'helpers/staticPaths'
17
- import React , { useEffect , useState } from 'react'
19
+ import React , { useEffect , useMemo , useState } from 'react'
20
+ import { EMPTY } from 'rxjs'
18
21
import { rays } from 'theme/icons'
19
22
import { Box , Button , Divider , Flex , Grid , Image , Text } from 'theme-ui'
20
23
@@ -34,16 +37,21 @@ const flashButton = ({
34
37
} , 400 )
35
38
} )
36
39
37
- const SignTosComponent = ( { wallet } : { wallet ?: string } ) => {
40
+ const SignTosComponent = ( { isAuthorized } : { isAuthorized ?: boolean } ) => {
38
41
const [ signTosEnabled , setSignTosEnabled ] = useState ( false )
39
- const jwtToken = wallet ? jwtAuthGetToken ( wallet ) : ''
40
- if ( ! jwtToken && ! signTosEnabled ) {
42
+
43
+ if ( isAuthorized || isAuthorized === undefined ) {
44
+ return null
45
+ }
46
+
47
+ if ( ! isAuthorized && ! signTosEnabled ) {
41
48
return (
42
49
< Button variant = "outlineSmall" onClick = { ( ) => setSignTosEnabled ( true ) } sx = { { mt : 3 } } >
43
50
Sign Terms of service
44
51
</ Button >
45
52
)
46
53
}
54
+
47
55
return < TermsOfService refreshAfterSign />
48
56
}
49
57
@@ -70,7 +78,13 @@ export const PortfolioDailyRays = ({
70
78
loaded : false ,
71
79
} )
72
80
const [ loadingBaseRaysChallengeData , setloadingBaseRaysChallengeData ] = useState ( false )
73
- const jwtToken = wallet ?. address ? jwtAuthGetToken ( wallet . address ) : ''
81
+ const _checkAcceptanceFromApi$ = useMemo (
82
+ ( ) => ( wallet ? checkAcceptanceFromApi$ ( currentContent . tos . version , wallet . address ) : EMPTY ) ,
83
+ [ wallet ?. address ] ,
84
+ )
85
+ const [ checkAcceptanceFromApiData ] = useObservable ( _checkAcceptanceFromApi$ )
86
+
87
+ const isAuthorized = checkAcceptanceFromApiData ?. authorized
74
88
75
89
useEffect ( ( ) => {
76
90
if ( ! loadingBaseRaysChallengeData && ! baseRaysChallengeData . loaded && wallet ?. address ) {
@@ -84,14 +98,13 @@ export const PortfolioDailyRays = ({
84
98
}
85
99
} , [ baseRaysChallengeData , wallet ?. address , loadingBaseRaysChallengeData ] )
86
100
87
- const requiredItems = wallet ?. address && wallet ?. chainId && baseRaysChallengeData && jwtToken
101
+ const requiredItems = wallet ?. address && wallet ?. chainId && baseRaysChallengeData && isAuthorized
88
102
89
103
const updateDailyRays = ( ) => {
90
104
setIsAddingPoints ( true )
91
105
requiredItems &&
92
106
void updateDailyRaysData ( {
93
107
wallet,
94
- token : jwtToken ,
95
108
callback : ( res ) => {
96
109
setIsAddingPoints ( false )
97
110
if ( res . isJwtValid ) {
@@ -117,7 +130,7 @@ export const PortfolioDailyRays = ({
117
130
setUserError ( false )
118
131
void flashButton ( { setIsExploding, small : true } ) . then ( ( ) => {
119
132
if ( requiredItems && baseRaysChallengeData . loaded ) {
120
- if ( ! jwtToken ) {
133
+ if ( ! isAuthorized ) {
121
134
setUserError ( true )
122
135
return
123
136
}
@@ -175,45 +188,46 @@ export const PortfolioDailyRays = ({
175
188
borderRadius : 'round' ,
176
189
} }
177
190
>
178
- { jwtToken ? (
179
- < Button
180
- variant = "outlineSmall"
181
- disabled = { ! requiredItems || baseRaysChallengeData ?. alreadyClaimed || isAddingPoints }
182
- sx = { {
183
- display : 'flex' ,
184
- alignItems : 'center' ,
185
- mt : 3 ,
186
- transition : 'box-shadow 0.5s cubic-bezier(0,1.81,.41,1.37)' ,
187
- userSelect : 'none' ,
188
- boxShadow : isExploding
189
- ? '-10px -6px 14px -8px #007da3,14px -8px 15px -8px #e7a77f,-11px 14px 15px -14px #e97047'
190
- : '0px' ,
191
- animation : 'animateGradient 10s infinite linear alternate' ,
192
- ...getGradientColor ( summerBrandGradient ) ,
193
- backgroundSize : '400px' ,
194
- '@keyframes animateGradient' : {
195
- '0%' : {
196
- backgroundPositionX : '50px' ,
197
- } ,
198
- '100%' : {
199
- backgroundPositionX : '-160px' ,
191
+ < >
192
+ { isAuthorized && (
193
+ < Button
194
+ variant = "outlineSmall"
195
+ disabled = { ! requiredItems || baseRaysChallengeData ?. alreadyClaimed || isAddingPoints }
196
+ sx = { {
197
+ display : 'flex' ,
198
+ alignItems : 'center' ,
199
+ mt : 3 ,
200
+ transition : 'box-shadow 0.5s cubic-bezier(0,1.81,.41,1.37)' ,
201
+ userSelect : 'none' ,
202
+ boxShadow : isExploding
203
+ ? '-10px -6px 14px -8px #007da3,14px -8px 15px -8px #e7a77f,-11px 14px 15px -14px #e97047'
204
+ : '0px' ,
205
+ animation : 'animateGradient 10s infinite linear alternate' ,
206
+ ...getGradientColor ( summerBrandGradient ) ,
207
+ backgroundSize : '400px' ,
208
+ '@keyframes animateGradient' : {
209
+ '0%' : {
210
+ backgroundPositionX : '50px' ,
211
+ } ,
212
+ '100%' : {
213
+ backgroundPositionX : '-160px' ,
214
+ } ,
200
215
} ,
201
- } ,
202
- } }
203
- onClick = {
204
- requiredItems && ! baseRaysChallengeData ?. alreadyClaimed
205
- ? explodeRaysHandler
206
- : ( ) => null
207
- }
208
- >
209
- < Icon icon = { rays } color = "primary60" sx = { { mr : 3 } } />
210
- Claim { dailyRaysAmount } Rays now
211
- </ Button >
212
- ) : (
216
+ } }
217
+ onClick = {
218
+ requiredItems && ! baseRaysChallengeData ?. alreadyClaimed
219
+ ? explodeRaysHandler
220
+ : ( ) => null
221
+ }
222
+ >
223
+ < Icon icon = { rays } color = "primary60" sx = { { mr : 3 } } />
224
+ Claim { dailyRaysAmount } Rays now
225
+ </ Button >
226
+ ) }
213
227
< FunctionalContextHandler >
214
- < SignTosComponent wallet = { wallet ?. address } />
228
+ < SignTosComponent isAuthorized = { isAuthorized } />
215
229
</ FunctionalContextHandler >
216
- ) }
230
+ </ >
217
231
</ Box >
218
232
{ userError && (
219
233
< Text as = "p" variant = "paragraph3" color = "warning100" sx = { { mt : 3 } } >
0 commit comments