Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(Tx notes): fire analytics on tx submit + adjust design #4771

Merged
merged 4 commits into from
Jan 15, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import ConfirmationView from '../confirmation-views'
import { SignerForm } from './SignerForm'
import { useSigner } from '@/hooks/wallets/useWallet'
import { trackTxEvents } from './tracking'
import { TxNoteForm, encodeTxNote } from '@/features/tx-notes'
import { TxNoteForm, encodeTxNote, trackAddNote } from '@/features/tx-notes'

export type SubmitCallback = (txId: string, isExecuted?: boolean) => void

Expand Down Expand Up @@ -112,8 +112,12 @@ export const SignOrExecuteForm = ({
!!signer?.isSafe,
customOrigin,
)

if (customOrigin !== props.origin) {
trackAddNote()
}
Comment on lines +116 to +118
Copy link
Member

@usame-algan usame-algan Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the user didn't add a note and its not a safe apps transaction. Are both values undefined and we would try to track something? Actually no we are checking for inequality so this shouldn't be an issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying to understand why we initialize customOrigin with props.origin instead of just leaving it undefined and if it exists we track an event.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined equals undefined though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, simply to avoid doing customOrigin || props.origin when passing it down.

},
[chainId, isCreation, onSubmit, trigger, signer?.isSafe, customOrigin],
[chainId, isCreation, onSubmit, trigger, signer?.isSafe, customOrigin, props.origin],
)

const onRoleExecutionSubmit = useCallback<typeof onFormSubmit>(
Expand All @@ -126,7 +130,7 @@ export const SignOrExecuteForm = ({
[onFormSubmit],
)

const onNoteSubmit = useCallback(
const onNoteChange = useCallback(
(note: string) => {
setCustomOrigin(encodeTxNote(note, props.origin))
},
Expand Down Expand Up @@ -194,7 +198,7 @@ export const SignOrExecuteForm = ({

{!isCounterfactualSafe && !props.isRejection && <TxChecks />}

<TxNoteForm isCreation={isCreation ?? false} onSubmit={onNoteSubmit} txDetails={props.txDetails} />
<TxNoteForm isCreation={isCreation ?? false} onChange={onNoteChange} txDetails={props.txDetails} />

<SignerForm willExecute={willExecute} />

Expand Down
11 changes: 8 additions & 3 deletions apps/web/src/features/tx-notes/TxNoteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import { TxNoteInput } from './TxNoteInput'
export function TxNoteForm({
isCreation,
txDetails,
onSubmit,
onChange,
}: {
isCreation: boolean
txDetails?: TransactionDetails
onSubmit: (note: string) => void
onChange: (note: string) => void
}) {
return <TxCard>{isCreation ? <TxNoteInput onSubmit={onSubmit} /> : <TxNote txDetails={txDetails} />}</TxCard>
// @FIXME: update CGW types to include note
const note = (txDetails as TransactionDetails & { note: string | null })?.note

if (!isCreation && !note) return null

return <TxCard>{isCreation ? <TxNoteInput onChange={onChange} /> : <TxNote txDetails={txDetails} />}</TxCard>
}
32 changes: 14 additions & 18 deletions apps/web/src/features/tx-notes/TxNoteInput.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
import { useCallback, useState } from 'react'
import { InputAdornment, Stack, TextField, Typography } from '@mui/material'
import InfoIcon from '@/public/images/notifications/info.svg'
import { MODALS_EVENTS, trackEvent } from '@/services/analytics'
import { InputAdornment, Stack, TextField, Typography, Alert } from '@mui/material'

const MAX_NOTE_LENGTH = 120
const MAX_NOTE_LENGTH = 60

export const TxNoteInput = ({ onSubmit }: { onSubmit: (note: string) => void }) => {
export const TxNoteInput = ({ onChange }: { onChange: (note: string) => void }) => {
const [note, setNote] = useState('')

const onInput = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
setNote(e.target.value)
}, [])

const onChange = useCallback(
const onInputChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
onSubmit(e.target.value.slice(0, MAX_NOTE_LENGTH))
trackEvent(MODALS_EVENTS.ADD_TX_NOTE)
onChange(e.target.value.slice(0, MAX_NOTE_LENGTH))
},
[onSubmit],
[onChange],
)

return (
<>
<Stack direction="row" alignItems="flex-end" gap={1}>
<Typography variant="h5">What does this transaction do?</Typography>
<Typography variant="h5">Optional note</Typography>
<Typography variant="body2" color="text.secondary">
Optional
Experimental
</Typography>
</Stack>

<Alert severity="info">
The notes are <b>publicly visible</b>, do not share any private or sensitive details.
</Alert>

<TextField
name="note"
label="Add note"
label="Note"
fullWidth
slotProps={{
htmlInput: { maxLength: MAX_NOTE_LENGTH },
Expand All @@ -46,13 +47,8 @@ export const TxNoteInput = ({ onSubmit }: { onSubmit: (note: string) => void })
},
}}
onInput={onInput}
onChange={onChange}
onChange={onInputChange}
/>

<Typography variant="caption" color="text.secondary" display="flex" alignItems="center">
<InfoIcon height="1.2em" />
This note will be publicly visible and accessible to anyone.
</Typography>
</>
)
}
6 changes: 2 additions & 4 deletions apps/web/src/features/tx-notes/encodeTxNote.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const MAX_ORIGIN_LENGTH = 200

const stringifyOrigin = (origin: Record<string, string>): string => JSON.stringify(origin, null, 0)

export function encodeTxNote(note: string, origin = ''): string {
let originalOrigin = {}

Expand All @@ -13,13 +11,13 @@ export function encodeTxNote(note: string, origin = ''): string {
}
}

let result = stringifyOrigin({
let result = JSON.stringify({
...originalOrigin,
note,
})

if (result.length > MAX_ORIGIN_LENGTH) {
result = stringifyOrigin({
result = JSON.stringify({
...originalOrigin,
note: note.slice(0, MAX_ORIGIN_LENGTH - origin.length),
})
Expand Down
5 changes: 5 additions & 0 deletions apps/web/src/features/tx-notes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { featureToggled, FEATURES } from '@/utils/featureToggled'
import { TxNote as TxNoteComponent } from './TxNote'
import { TxNoteForm as TxNoteFormComponent } from './TxNoteForm'
import { MODALS_EVENTS, trackEvent } from '@/services/analytics'

export const TxNote = featureToggled(TxNoteComponent, FEATURES.TX_NOTES)
export const TxNoteForm = featureToggled(TxNoteFormComponent, FEATURES.TX_NOTES)
export * from './encodeTxNote'

export function trackAddNote() {
trackEvent(MODALS_EVENTS.SUBMIT_TX_NOTE)
}
4 changes: 2 additions & 2 deletions apps/web/src/services/analytics/events/modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export const MODALS_EVENTS = {
category: MODALS_CATEGORY,
event: EventType.CLICK,
},
ADD_TX_NOTE: {
action: 'Add tx note',
SUBMIT_TX_NOTE: {
action: 'Submit tx note',
category: MODALS_CATEGORY,
event: EventType.CLICK,
},
Expand Down
Loading