Skip to content

Commit

Permalink
Track safe apps tx creation
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Nov 20, 2023
1 parent 18122e6 commit d97f40e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
8 changes: 2 additions & 6 deletions src/components/dashboard/FeaturedApps/FeaturedApps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import { SafeAppsTag } from '@/config/constants'
import { useRemoteSafeApps } from '@/hooks/safe-apps/useRemoteSafeApps'
import SafeAppIconCard from '@/components/safe-apps/SafeAppIconCard'
import { WalletConnectContext } from '@/services/walletconnect/WalletConnectContext'

const isWalletConnectSafeApp = (app: SafeAppData): boolean => {
const WALLET_CONNECT = /wallet-connect/
return WALLET_CONNECT.test(app.url)
}
import { isWalletConnectSafeApp } from '@/services/walletconnect/utils'

const FeaturedAppCard = ({ app }: { app: SafeAppData }) => (
<Card>
Expand Down Expand Up @@ -62,7 +58,7 @@ export const FeaturedApps = ({ stackedLayout }: { stackedLayout: boolean }): Rea
>
{featuredApps?.map((app) => (
<Grid item xs md key={app.id}>
{isWalletConnectSafeApp(app) ? (
{isWalletConnectSafeApp(app.url) ? (
<a onClick={onWcWidgetClick} style={{ cursor: 'pointer' }}>
<FeaturedAppCard app={app} />
</a>
Expand Down
11 changes: 11 additions & 0 deletions src/components/tx-flow/flows/SafeAppsTx/ReviewSafeAppsTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import ApprovalEditor from '@/components/tx/ApprovalEditor'
import { getInteractionTitle, isTxValid } from '@/components/safe-apps/utils'
import ErrorMessage from '@/components/tx/ErrorMessage'
import { asError } from '@/services/exceptions/utils'
import { trackEvent } from '@/services/analytics'
import { TX_EVENTS, TX_TYPES } from '@/services/analytics/events/transactions'
import { isWalletConnectSafeApp } from '@/services/walletconnect/utils'

type ReviewSafeAppsTxProps = {
safeAppsTx: SafeAppsTxParams
Expand Down Expand Up @@ -63,6 +66,14 @@ const ReviewSafeAppsTx = ({
setSafeTxError(asError(error))
}

// Track tx creation
if (safeTx.signatures.size === 1) {
trackEvent({
...TX_EVENTS.CREATE,
label: isWalletConnectSafeApp(app?.url || '') ? TX_TYPES.walletconnect : TX_TYPES.safeapps,
})
}

onSubmit?.(txId, safeTxHash)
}

Expand Down
5 changes: 0 additions & 5 deletions src/services/safe-wallet-provider/useSafeWalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import SignMessageOnChainFlow from '@/components/tx-flow/flows/SignMessageOnChai
import { useAppSelector } from '@/store'
import { selectOnChainSigning } from '@/store/settingsSlice'
import { isOffchainEIP1271Supported } from '@/utils/safe-messages'
import { TX_EVENTS, TX_TYPES } from '../analytics/events/transactions'
import { trackEvent } from '../analytics'

export const _useTxFlowApi = (chainId: string, safeAddress: string): WalletSDK | undefined => {
const { safe } = useSafeInfo()
Expand Down Expand Up @@ -138,9 +136,6 @@ export const _useTxFlowApi = (chainId: string, safeAddress: string): WalletSDK |
const onSubmit = (txId: string, safeTxHash: string) => {
const txHash = pendingTxs.current[txId]
onClose = () => {}

trackEvent({ ...TX_EVENTS.CREATE, label: TX_TYPES.walletconnect })

resolve({ safeTxHash, txHash })
}

Expand Down
5 changes: 5 additions & 0 deletions src/services/walletconnect/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ export const getPeerName = (peer: SessionTypes.Struct['peer'] | ProposalTypes.St
export const splitError = (message: string): string[] => {
return message.split(/: (.+)/).slice(0, 2)
}

export const isWalletConnectSafeApp = (url: string): boolean => {
const WALLET_CONNECT = /wallet-connect/
return WALLET_CONNECT.test(url)
}

0 comments on commit d97f40e

Please sign in to comment.