Skip to content

Commit

Permalink
Track only typed messages as tx_created
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Nov 10, 2023
1 parent b04bb15 commit 0b8fcb0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
19 changes: 11 additions & 8 deletions src/components/tx-flow/flows/SignMessage/SignMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import InfoBox from '@/components/safe-messages/InfoBox'
import { DecodedMsg } from '@/components/safe-messages/DecodedMsg'
import TxCard from '@/components/tx-flow/common/TxCard'
import { dispatchPreparedSignature } from '@/services/safe-messages/safeMsgNotifications'
import { trackEvent } from '@/services/analytics'
import { TX_EVENTS, TX_TYPES } from '@/services/analytics/events/transactions'

const createSkeletonMessage = (confirmationsRequired: number): SafeMessage => {
return {
Expand Down Expand Up @@ -169,19 +171,14 @@ const SignMessage = ({ message, safeAppId, requestId }: ProposeProps | ConfirmPr
const { safe } = useSafeInfo()
const isOwner = useIsSafeOwner()
const wallet = useWallet()
useHighlightHiddenTab()

const { decodedMessage, safeMessageMessage, safeMessageHash } = useDecodedSafeMessage(message, safe)
const [safeMessage, setSafeMessage] = useSafeMessage(safeMessageHash)

useHighlightHiddenTab()

const decodedMessageAsString =
typeof decodedMessage === 'string' ? decodedMessage : JSON.stringify(decodedMessage, null, 2)

const isPlainTextMessage = typeof decodedMessage === 'string'
const decodedMessageAsString = isPlainTextMessage ? decodedMessage : JSON.stringify(decodedMessage, null, 2)
const hasSigned = !!safeMessage?.confirmations.some(({ owner }) => owner.value === wallet?.address)

const isFullySigned = !!safeMessage?.preparedSignature

const isDisabled = !isOwner || hasSigned

const { onSign, submitError } = useSyncSafeMessageSigner(
Expand All @@ -195,9 +192,15 @@ const SignMessage = ({ message, safeAppId, requestId }: ProposeProps | ConfirmPr

const handleSign = async () => {
const updatedMessage = await onSign()

if (updatedMessage) {
setSafeMessage(updatedMessage)
}

// Track first signature as creation
if (updatedMessage?.confirmations.length === 1) {
trackEvent({ ...TX_EVENTS.CREATE, label: TX_TYPES.typed_message })
}
}

const onContinue = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ const ReviewSignMessageOnChain = ({ message, method, requestId }: SignMessageOnC
const handleSubmit = async () => {
if (!safeTx || !onboard) return

trackEvent({ ...TX_EVENTS.CREATE, label: TX_TYPES.message })
// Track the creation of a typed message
if (isTypedMessage && safeTx.signatures.size === 1) {
trackEvent({ ...TX_EVENTS.CREATE, label: TX_TYPES.typed_message })
}

try {
await dispatchSafeAppsTx(safeTx, requestId, onboard, safe.chainId)
Expand Down
5 changes: 0 additions & 5 deletions src/hooks/messages/useSafeMsgTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useEffect } from 'react'

import { trackEvent, WALLET_EVENTS } from '@/services/analytics'
import { SafeMsgEvent, safeMsgSubscribe } from '@/services/safe-messages/safeMsgEvents'
import { TX_EVENTS, TX_TYPES } from '@/services/analytics/events/transactions'

const safeMsgEvents = {
[SafeMsgEvent.PROPOSE]: WALLET_EVENTS.SIGN_MESSAGE,
Expand All @@ -14,10 +13,6 @@ export const useSafeMsgTracking = (): void => {
const unsubFns = Object.entries(safeMsgEvents).map(([safeMsgEvent, analyticsEvent]) =>
safeMsgSubscribe(safeMsgEvent as SafeMsgEvent, () => {
trackEvent(analyticsEvent)

if (analyticsEvent === WALLET_EVENTS.SIGN_MESSAGE) {
trackEvent({ ...TX_EVENTS.CREATE, label: TX_TYPES.message })
}
}),
)

Expand Down
2 changes: 1 addition & 1 deletion src/services/analytics/events/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export enum TX_TYPES {
// Other
batch = 'batch',
rejection = 'rejection',
message = 'message',
typed_message = 'typed_message',
safeapps = 'safeapps',
walletconnect = 'walletconnect',
}
Expand Down

0 comments on commit 0b8fcb0

Please sign in to comment.