Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
f09ded1a
Unverified
Commit
f09ded1a
authored
Oct 10, 2023
by
eddie
Committed by
GitHub
Oct 10, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: user prop updater staging (#7443)
fix: move user prop updater into statsigProvider
parent
e16348e2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
51 deletions
+59
-51
App.tsx
src/pages/App.tsx
+59
-51
No files found.
src/pages/App.tsx
View file @
f09ded1a
...
@@ -97,12 +97,10 @@ export default function App() {
...
@@ -97,12 +97,10 @@ export default function App() {
const
location
=
useLocation
()
const
location
=
useLocation
()
const
{
pathname
}
=
location
const
{
pathname
}
=
location
const
currentPage
=
getCurrentPageFromLocation
(
pathname
)
const
currentPage
=
getCurrentPageFromLocation
(
pathname
)
const
isDarkMode
=
useIsDarkMode
()
const
[
routerPreference
]
=
useRouterPreference
()
const
[
scrollY
,
setScrollY
]
=
useState
(
0
)
const
[
scrollY
,
setScrollY
]
=
useState
(
0
)
const
scrolledState
=
scrollY
>
0
const
scrolledState
=
scrollY
>
0
const
isUniswapXDefaultEnabled
=
useUniswapXDefaultEnabled
()
const
userOptedOutOfUniswapX
=
useUserOptedOutOfUniswapX
()
const
routerConfig
=
useRouterConfig
()
const
routerConfig
=
useRouterConfig
()
const
originCountry
=
useAppSelector
((
state
:
AppState
)
=>
state
.
user
.
originCountry
)
const
originCountry
=
useAppSelector
((
state
:
AppState
)
=>
state
.
user
.
originCountry
)
...
@@ -122,53 +120,6 @@ export default function App() {
...
@@ -122,53 +120,6 @@ export default function App() {
}
}
},
[
searchParams
,
setShouldDisableNFTRoutes
])
},
[
searchParams
,
setShouldDisableNFTRoutes
])
useEffect
(()
=>
{
// User properties *must* be set before sending corresponding event properties,
// so that the event contains the correct and up-to-date user properties.
user
.
set
(
CustomUserProperties
.
USER_AGENT
,
navigator
.
userAgent
)
user
.
set
(
CustomUserProperties
.
BROWSER
,
getBrowser
())
user
.
set
(
CustomUserProperties
.
SCREEN_RESOLUTION_HEIGHT
,
window
.
screen
.
height
)
user
.
set
(
CustomUserProperties
.
SCREEN_RESOLUTION_WIDTH
,
window
.
screen
.
width
)
user
.
set
(
CustomUserProperties
.
GIT_COMMIT_HASH
,
process
.
env
.
REACT_APP_GIT_COMMIT_HASH
??
'
unknown
'
)
// Service Worker analytics
const
isServiceWorkerInstalled
=
Boolean
(
window
.
navigator
.
serviceWorker
?.
controller
)
const
isServiceWorkerHit
=
Boolean
((
window
as
any
).
__isDocumentCached
)
const
serviceWorkerProperty
=
isServiceWorkerInstalled
?
(
isServiceWorkerHit
?
'
hit
'
:
'
miss
'
)
:
'
uninstalled
'
const
pageLoadProperties
=
{
service_worker
:
serviceWorkerProperty
}
sendInitializationEvent
(
SharedEventName
.
APP_LOADED
,
pageLoadProperties
)
const
sendWebVital
=
(
metric
:
string
)
=>
({
delta
}:
Metric
)
=>
sendAnalyticsEvent
(
SharedEventName
.
WEB_VITALS
,
{
...
pageLoadProperties
,
[
metric
]:
delta
})
getCLS
(
sendWebVital
(
'
cumulative_layout_shift
'
))
getFCP
(
sendWebVital
(
'
first_contentful_paint_ms
'
))
getFID
(
sendWebVital
(
'
first_input_delay_ms
'
))
getLCP
(
sendWebVital
(
'
largest_contentful_paint_ms
'
))
},
[])
useEffect
(()
=>
{
user
.
set
(
CustomUserProperties
.
DARK_MODE
,
isDarkMode
)
},
[
isDarkMode
])
useEffect
(()
=>
{
// If we're not in the transition period to UniswapX opt-out, set the router preference to whatever is specified.
if
(
!
isUniswapXDefaultEnabled
)
{
user
.
set
(
CustomUserProperties
.
ROUTER_PREFERENCE
,
routerPreference
)
return
}
// In the transition period, override the stored API preference to UniswapX if the user hasn't opted out.
if
(
routerPreference
===
RouterPreference
.
API
&&
!
userOptedOutOfUniswapX
)
{
user
.
set
(
CustomUserProperties
.
ROUTER_PREFERENCE
,
RouterPreference
.
X
)
return
}
// Otherwise, the user has opted out or their preference is UniswapX/client, so set the preference to whatever is specified.
user
.
set
(
CustomUserProperties
.
ROUTER_PREFERENCE
,
routerPreference
)
},
[
routerPreference
,
isUniswapXDefaultEnabled
,
userOptedOutOfUniswapX
])
useEffect
(()
=>
{
useEffect
(()
=>
{
const
scrollListener
=
()
=>
{
const
scrollListener
=
()
=>
{
setScrollY
(
window
.
scrollY
)
setScrollY
(
window
.
scrollY
)
...
@@ -221,6 +172,7 @@ export default function App() {
...
@@ -221,6 +172,7 @@ export default function App() {
api
:
process
.
env
.
REACT_APP_STATSIG_PROXY_URL
,
api
:
process
.
env
.
REACT_APP_STATSIG_PROXY_URL
,
}
}
}
}
>
>
<
UserPropertyUpdater
/>
{
renderUkBannner
&&
<
UkBanner
/>
}
{
renderUkBannner
&&
<
UkBanner
/>
}
<
HeaderWrapper
transparent=
{
isHeaderTransparent
}
bannerIsVisible=
{
renderUkBannner
}
scrollY=
{
scrollY
}
>
<
HeaderWrapper
transparent=
{
isHeaderTransparent
}
bannerIsVisible=
{
renderUkBannner
}
scrollY=
{
scrollY
}
>
<
NavBar
blur=
{
isHeaderTransparent
}
/>
<
NavBar
blur=
{
isHeaderTransparent
}
/>
...
@@ -255,3 +207,59 @@ export default function App() {
...
@@ -255,3 +207,59 @@ export default function App() {
</
ErrorBoundary
>
</
ErrorBoundary
>
)
)
}
}
function
UserPropertyUpdater
()
{
const
isDarkMode
=
useIsDarkMode
()
const
[
routerPreference
]
=
useRouterPreference
()
const
userOptedOutOfUniswapX
=
useUserOptedOutOfUniswapX
()
const
isUniswapXDefaultEnabled
=
useUniswapXDefaultEnabled
()
useEffect
(()
=>
{
// User properties *must* be set before sending corresponding event properties,
// so that the event contains the correct and up-to-date user properties.
user
.
set
(
CustomUserProperties
.
USER_AGENT
,
navigator
.
userAgent
)
user
.
set
(
CustomUserProperties
.
BROWSER
,
getBrowser
())
user
.
set
(
CustomUserProperties
.
SCREEN_RESOLUTION_HEIGHT
,
window
.
screen
.
height
)
user
.
set
(
CustomUserProperties
.
SCREEN_RESOLUTION_WIDTH
,
window
.
screen
.
width
)
user
.
set
(
CustomUserProperties
.
GIT_COMMIT_HASH
,
process
.
env
.
REACT_APP_GIT_COMMIT_HASH
??
'
unknown
'
)
// Service Worker analytics
const
isServiceWorkerInstalled
=
Boolean
(
window
.
navigator
.
serviceWorker
?.
controller
)
const
isServiceWorkerHit
=
Boolean
((
window
as
any
).
__isDocumentCached
)
const
serviceWorkerProperty
=
isServiceWorkerInstalled
?
(
isServiceWorkerHit
?
'
hit
'
:
'
miss
'
)
:
'
uninstalled
'
const
pageLoadProperties
=
{
service_worker
:
serviceWorkerProperty
}
sendInitializationEvent
(
SharedEventName
.
APP_LOADED
,
pageLoadProperties
)
const
sendWebVital
=
(
metric
:
string
)
=>
({
delta
}:
Metric
)
=>
sendAnalyticsEvent
(
SharedEventName
.
WEB_VITALS
,
{
...
pageLoadProperties
,
[
metric
]:
delta
})
getCLS
(
sendWebVital
(
'
cumulative_layout_shift
'
))
getFCP
(
sendWebVital
(
'
first_contentful_paint_ms
'
))
getFID
(
sendWebVital
(
'
first_input_delay_ms
'
))
getLCP
(
sendWebVital
(
'
largest_contentful_paint_ms
'
))
},
[])
useEffect
(()
=>
{
user
.
set
(
CustomUserProperties
.
DARK_MODE
,
isDarkMode
)
},
[
isDarkMode
])
useEffect
(()
=>
{
// If we're not in the transition period to UniswapX opt-out, set the router preference to whatever is specified.
if
(
!
isUniswapXDefaultEnabled
)
{
user
.
set
(
CustomUserProperties
.
ROUTER_PREFERENCE
,
routerPreference
)
return
}
// In the transition period, override the stored API preference to UniswapX if the user hasn't opted out.
if
(
routerPreference
===
RouterPreference
.
API
&&
!
userOptedOutOfUniswapX
)
{
user
.
set
(
CustomUserProperties
.
ROUTER_PREFERENCE
,
RouterPreference
.
X
)
return
}
// Otherwise, the user has opted out or their preference is UniswapX/client, so set the preference to whatever is specified.
user
.
set
(
CustomUserProperties
.
ROUTER_PREFERENCE
,
routerPreference
)
},
[
routerPreference
,
isUniswapXDefaultEnabled
,
userOptedOutOfUniswapX
])
return
null
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment