Skip to content

Commit

Permalink
fix: Add delegate transactions to track call (#4344)
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan authored Oct 9, 2024
1 parent 9d6cf75 commit e444326
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/components/tx/SignOrExecuteForm/DelegateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const DelegateForm = ({
disableSubmit = false,
txActions,
txSecurity,
onSubmit,
}: SignOrExecuteProps & {
txActions: ReturnType<typeof useTxActions>
txSecurity: ReturnType<typeof useTxSecurityContext>
Expand Down Expand Up @@ -51,7 +52,8 @@ export const DelegateForm = ({
setIsRejectedByUser(false)

try {
await signDelegateTx(safeTx)
const txId = await signDelegateTx(safeTx)
onSubmit?.(txId)
} catch (_err) {
const err = asError(_err)
if (isWalletRejection(err)) {
Expand Down
18 changes: 14 additions & 4 deletions src/components/tx/SignOrExecuteForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ const trackTxEvents = (
isCreation: boolean,
isExecuted: boolean,
isRoleExecution: boolean,
isDelegateCreation: boolean,
) => {
const creationEvent = isRoleExecution ? TX_EVENTS.CREATE_VIA_ROLE : TX_EVENTS.CREATE
const creationEvent = isRoleExecution
? TX_EVENTS.CREATE_VIA_ROLE
: isDelegateCreation
? TX_EVENTS.CREATE_VIA_DELEGATE
: TX_EVENTS.CREATE
const executionEvent = isRoleExecution ? TX_EVENTS.EXECUTE_VIA_ROLE : TX_EVENTS.EXECUTE
const event = isCreation ? creationEvent : isExecuted ? executionEvent : TX_EVENTS.CONFIRM
const txType = getTransactionTrackingType(details)
Expand Down Expand Up @@ -135,12 +140,12 @@ export const SignOrExecuteForm = ({
(props.onlyExecute || shouldExecute) && canExecuteThroughRole && (!canExecute || preferThroughRole)

const onFormSubmit = useCallback(
async (txId: string, isExecuted = false, isRoleExecution = false) => {
async (txId: string, isExecuted = false, isRoleExecution = false, isDelegateCreation = false) => {
onSubmit?.(txId, isExecuted)

const { data: details } = await trigger({ chainId, txId })
// Track tx event
trackTxEvents(details, isCreation, isExecuted, isRoleExecution)
trackTxEvents(details, isCreation, isExecuted, isRoleExecution, isDelegateCreation)
},
[chainId, isCreation, onSubmit, trigger],
)
Expand All @@ -150,6 +155,11 @@ export const SignOrExecuteForm = ({
[onFormSubmit],
)

const onDelegateFormSubmit = useCallback<typeof onFormSubmit>(
(txId, isExecuted) => onFormSubmit(txId, isExecuted, false, true),
[onFormSubmit],
)

return (
<>
<TxCard>
Expand Down Expand Up @@ -230,7 +240,7 @@ export const SignOrExecuteForm = ({
/>
)}

{isDelegate && <DelegateForm {...props} safeTx={safeTx} onSubmit={onFormSubmit} />}
{isDelegate && <DelegateForm {...props} safeTx={safeTx} onSubmit={onDelegateFormSubmit} />}
</TxCard>
</>
)
Expand Down
5 changes: 5 additions & 0 deletions src/services/analytics/events/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export const TX_EVENTS = {
action: 'Create via spending limit',
category: TX_CATEGORY,
},
CREATE_VIA_DELEGATE: {
event: EventType.TX_CREATED,
action: 'Create via delegate',
category: TX_CATEGORY,
},
CONFIRM: {
event: EventType.TX_CONFIRMED,
action: 'Confirm transaction',
Expand Down

0 comments on commit e444326

Please sign in to comment.