11import { useEffect , useRef , useState } from 'react' ;
22
3+ import { SHA256 } from 'crypto-js' ;
34import { useLocation } from 'react-router-dom' ;
45
56import {
@@ -19,7 +20,6 @@ import { getSelectedLocale } from '@/state/localizationSelectors';
1920import { getTradeFormValues } from '@/state/tradeFormSelectors' ;
2021
2122import { identify , track } from '@/lib/analytics/analytics' ;
22- import { runFn } from '@/lib/do' ;
2323
2424import { useAccounts } from './useAccounts' ;
2525import { useApiState } from './useApiState' ;
@@ -108,41 +108,20 @@ export const useAnalytics = () => {
108108 const [ analyticsUserId , setAnalyticsUserId ] = useState < string | null > ( null ) ;
109109
110110 useEffect ( ( ) => {
111- let dead = false ;
112-
113- runFn ( async ( ) => {
114- if ( dead ) return ;
115- if ( sourceAccount . walletInfo ?. connectorType === ConnectorType . Test ) {
116- setAnalyticsUserId ( null ) ;
117- }
111+ if ( sourceAccount . walletInfo ?. connectorType === ConnectorType . Test ) {
112+ setAnalyticsUserId ( null ) ;
113+ }
118114
119- if ( sourceAccount . walletInfo ?. connectorType === ConnectorType . Turnkey ) {
120- if ( sourceAccount . walletInfo . userEmail && typeof globalThis . crypto !== 'undefined' ) {
121- const normalizedEmail = sourceAccount . walletInfo . userEmail . trim ( ) . toLowerCase ( ) ;
122- const hashedEmail = await globalThis . crypto . subtle . digest (
123- 'SHA-256' ,
124- new TextEncoder ( ) . encode ( normalizedEmail )
125- ) ;
126-
127- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
128- if ( dead ) return ;
129-
130- setAnalyticsUserId (
131- Array . from ( new Uint8Array ( hashedEmail ) )
132- . map ( ( b ) => b . toString ( 16 ) . padStart ( 2 , '0' ) )
133- . join ( '' )
134- ) ;
135-
136- return ;
137- }
115+ if ( sourceAccount . walletInfo ?. connectorType === ConnectorType . Turnkey ) {
116+ if ( sourceAccount . walletInfo . userEmail ) {
117+ const normalizedEmail = sourceAccount . walletInfo . userEmail . trim ( ) . toLowerCase ( ) ;
118+ const hashedEmail = SHA256 ( normalizedEmail ) . toString ( ) ;
119+ setAnalyticsUserId ( hashedEmail ) ;
120+ return ;
138121 }
122+ }
139123
140- setAnalyticsUserId ( sourceAccount . address ?? null ) ;
141- } ) ;
142-
143- return ( ) => {
144- dead = true ;
145- } ;
124+ setAnalyticsUserId ( sourceAccount . address ?? null ) ;
146125 } , [ sourceAccount . address , sourceAccount . walletInfo ] ) ;
147126
148127 useEffect ( ( ) => {
0 commit comments