Skip to content

Commit 34167fa

Browse files
authored
Add tracking for eoa detection (#891)
* add event names * capture events * feat: changeset * cleaner logs
1 parent 1c617e7 commit 34167fa

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

.changeset/tasty-rivers-itch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@relayprotocol/relay-kit-ui': patch
3+
---
4+
5+
Add tracking for eoa detection

packages/ui/src/components/widgets/SwapWidgetRenderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
isValidAddress,
4141
findSupportedWallet
4242
} from '../../utils/address.js'
43-
import { adaptViemWallet, getDeadAddress } from '@relayprotocol/relay-sdk'
43+
import { adaptViemWallet } from '@relayprotocol/relay-sdk'
4444
import { errorToJSON } from '../../utils/errors.js'
4545
import { useSwapButtonCta } from '../../hooks/widget/useSwapButtonCta.js'
4646
import { sha256 } from '../../utils/hashing.js'

packages/ui/src/hooks/useEOADetection.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ const useEOADetection = (
117117
}
118118

119119
const detectEOA = async () => {
120+
const baseEventData = {
121+
chain_id: chainId,
122+
address: userAddress,
123+
wallet_type: wallet?.vmType
124+
}
125+
120126
try {
121127
if (!wallet || !wallet?.isEOA) {
122128
setDetectionState((current) =>
@@ -132,6 +138,8 @@ const useEOADetection = (
132138
abortController.abort()
133139
}, 1000)
134140

141+
const startTime = performance.now()
142+
135143
try {
136144
const eoaResult = await Promise.race([
137145
wallet.isEOA(chainId!),
@@ -153,14 +161,39 @@ const useEOADetection = (
153161
)
154162
} catch (eoaError: any) {
155163
clearTimeout(timeoutId)
164+
const duration = performance.now() - startTime
165+
const isTimeout = eoaError?.message === 'EOA_DETECTION_TIMEOUT'
166+
167+
if (isTimeout) {
168+
console.error('[EOA Detection]', {
169+
...baseEventData,
170+
error_type: 'timeout',
171+
duration_ms: Math.round(duration)
172+
})
173+
} else {
174+
console.error('[EOA Detection]', {
175+
...baseEventData,
176+
error_type: 'error',
177+
duration_ms: Math.round(duration),
178+
error_message: eoaError?.message || 'Unknown error',
179+
error_name: eoaError?.name
180+
})
181+
}
156182

157183
setDetectionState((current) =>
158184
current.conditionKey === conditionKey
159185
? { value: true, conditionKey }
160186
: current
161187
)
162188
}
163-
} catch (error) {
189+
} catch (error: any) {
190+
console.error('[EOA Detection]', {
191+
...baseEventData,
192+
error_type: 'error',
193+
error_message: error?.message || 'Unknown error',
194+
error_name: error?.name
195+
})
196+
164197
setDetectionState((current) =>
165198
current.conditionKey === conditionKey
166199
? { value: true, conditionKey }
@@ -170,7 +203,7 @@ const useEOADetection = (
170203
}
171204

172205
detectEOA()
173-
}, [conditionKey, shouldDetect, wallet, chainId])
206+
}, [conditionKey, shouldDetect, wallet, chainId, userAddress])
174207

175208
if (!shouldDetect && chainVmType === 'evm') {
176209
return explicitDeposit ?? true

0 commit comments

Comments
 (0)