Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tasty-rivers-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@relayprotocol/relay-kit-ui': patch
---

Add tracking for eoa detection
2 changes: 1 addition & 1 deletion packages/ui/src/components/widgets/SwapWidgetRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
isValidAddress,
findSupportedWallet
} from '../../utils/address.js'
import { adaptViemWallet, getDeadAddress } from '@relayprotocol/relay-sdk'
import { adaptViemWallet } from '@relayprotocol/relay-sdk'
import { errorToJSON } from '../../utils/errors.js'
import { useSwapButtonCta } from '../../hooks/widget/useSwapButtonCta.js'
import { sha256 } from '../../utils/hashing.js'
Expand Down
37 changes: 35 additions & 2 deletions packages/ui/src/hooks/useEOADetection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ const useEOADetection = (
}

const detectEOA = async () => {
const baseEventData = {
chain_id: chainId,
address: userAddress,
wallet_type: wallet?.vmType
}

try {
if (!wallet || !wallet?.isEOA) {
setDetectionState((current) =>
Expand All @@ -132,6 +138,8 @@ const useEOADetection = (
abortController.abort()
}, 1000)

const startTime = performance.now()

try {
const eoaResult = await Promise.race([
wallet.isEOA(chainId!),
Expand All @@ -153,14 +161,39 @@ const useEOADetection = (
)
} catch (eoaError: any) {
clearTimeout(timeoutId)
const duration = performance.now() - startTime
const isTimeout = eoaError?.message === 'EOA_DETECTION_TIMEOUT'

if (isTimeout) {
console.error('[EOA Detection]', {
...baseEventData,
error_type: 'timeout',
duration_ms: Math.round(duration)
})
} else {
console.error('[EOA Detection]', {
...baseEventData,
error_type: 'error',
duration_ms: Math.round(duration),
error_message: eoaError?.message || 'Unknown error',
error_name: eoaError?.name
})
}

setDetectionState((current) =>
current.conditionKey === conditionKey
? { value: true, conditionKey }
: current
)
}
} catch (error) {
} catch (error: any) {
console.error('[EOA Detection]', {
...baseEventData,
error_type: 'error',
error_message: error?.message || 'Unknown error',
error_name: error?.name
})

setDetectionState((current) =>
current.conditionKey === conditionKey
? { value: true, conditionKey }
Expand All @@ -170,7 +203,7 @@ const useEOADetection = (
}

detectEOA()
}, [conditionKey, shouldDetect, wallet, chainId])
}, [conditionKey, shouldDetect, wallet, chainId, userAddress])

if (!shouldDetect && chainVmType === 'evm') {
return explicitDeposit ?? true
Expand Down