Skip to content

Commit

Permalink
Fix: WalletConnect - track only tx and signature requests
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Nov 2, 2023
1 parent 90aaa5c commit e3710c2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/components/walletconnect/WcSessionMananger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ const WcSessionManager = ({ sessions, uri }: WcSessionManagerProps) => {

// Track errors
useEffect(() => {
if (error && open) {
trackEvent({ ...WALLETCONNECT_EVENTS.SHOW_ERROR, label: splitError(error.message || '')[0] })
if (error) {
// The summary of the error
const label = splitError(error.message || '')[0]
trackEvent({ ...WALLETCONNECT_EVENTS.SHOW_ERROR, label })
}
}, [error, open])
}, [error])

//
// UI states
Expand Down
7 changes: 3 additions & 4 deletions src/services/walletconnect/WalletConnectContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import WalletConnectWallet from './WalletConnectWallet'
import { asError } from '../exceptions/utils'
import { getPeerName, stripEip155Prefix } from './utils'
import { IS_PRODUCTION } from '@/config/constants'
import { trackEvent } from '../analytics'
import { WALLETCONNECT_EVENTS } from '../analytics/events/walletconnect'
import { SafeAppsTag } from '@/config/constants'
import { useRemoteSafeApps } from '@/hooks/safe-apps/useRemoteSafeApps'
import { trackRequest } from './tracking'

enum Errors {
WRONG_CHAIN = '%%dappName%% made a request on a different chain than the one you are connected to',
Expand Down Expand Up @@ -82,9 +81,9 @@ export const WalletConnectProvider = ({ children }: { children: ReactNode }) =>
const session = walletConnect.getActiveSessions().find((s) => s.topic === topic)
const requestChainId = stripEip155Prefix(event.params.chainId)

// Track all requests
// Track requests
if (session) {
trackEvent({ ...WALLETCONNECT_EVENTS.REQUEST, label: session.peer.metadata.url })
trackRequest(session.peer.metadata.url, event.params.request.method)
}

const getResponse = () => {
Expand Down
16 changes: 16 additions & 0 deletions src/services/walletconnect/tracking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { trackEvent } from '../analytics'
import { WALLETCONNECT_EVENTS } from '../analytics/events/walletconnect'

const trackedRequests = [
'personal_sign',
'eth_sign',
'eth_signTypedData',
'eth_signTypedData_v4',
'eth_sendTransaction',
]

export const trackRequest = (peerUrl: string, method: string) => {
if (trackedRequests.includes(method)) {
trackEvent({ ...WALLETCONNECT_EVENTS.REQUEST, label: peerUrl })
}
}

0 comments on commit e3710c2

Please sign in to comment.