Skip to content

chore: include regular tx events during the stx status changes #119

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
33 changes: 31 additions & 2 deletions src/SmartTransactionsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,22 @@ describe('SmartTransactionsController', () => {
expect(trackMetaMetricsEventSpy).not.toHaveBeenCalled();
});

it('tracks status change if smartTransaction and prevSmartTransaction have different statuses', () => {
it('tracks status change if smartTransaction and prevSmartTransaction have different statuses and status is not pending', () => {
const smartTransaction = {
...createStateAfterPending()[0],
status: 'success',
swapMetaData: {},
};
const prevSmartTransaction = { ...smartTransaction, status: 'pending' };

smartTransactionsController.trackStxStatusChange(
smartTransaction as SmartTransaction,
prevSmartTransaction as SmartTransaction,
);
expect(trackMetaMetricsEventSpy).toHaveBeenCalledTimes(1);
});

it('tracks status change if smartTransaction and prevSmartTransaction and status is pending', () => {
const smartTransaction = {
...createStateAfterPending()[0],
swapMetaData: {},
Expand All @@ -409,7 +424,21 @@ describe('SmartTransactionsController', () => {
smartTransaction as SmartTransaction,
prevSmartTransaction as SmartTransaction,
);
expect(trackMetaMetricsEventSpy).toHaveBeenCalled();
expect(trackMetaMetricsEventSpy).toHaveBeenCalledTimes(2);
});

it('tracks status change if smartTransaction and prevSmartTransaction and status is cancelled', () => {
const smartTransaction = {
...createStateAfterPending()[0],
status: 'cancelled',
swapMetaData: {},
};
const prevSmartTransaction = { ...smartTransaction, status: 'pending' };
smartTransactionsController.trackStxStatusChange(
smartTransaction as SmartTransaction,
prevSmartTransaction as SmartTransaction,
);
expect(trackMetaMetricsEventSpy).toHaveBeenCalledTimes(2);
});
});

Expand Down
41 changes: 40 additions & 1 deletion src/SmartTransactionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export default class SmartTransactionsController extends BaseController<
}

const sensitiveProperties = {
stx_status: updatedSmartTransaction.status,
stx_status: updatedSmartTransaction.status as SmartTransactionStatuses,
token_from_symbol: updatedSmartTransaction.sourceTokenSymbol,
token_to_symbol: updatedSmartTransaction.destinationTokenSymbol,
processing_time: getStxProcessingTime(updatedSmartTransaction.time),
Expand All @@ -239,6 +239,45 @@ export default class SmartTransactionsController extends BaseController<
stx_user_opt_in: true,
};

// for reporting reasons we are logging also stx statuses mapped to regular tx statuses
// resulting in 2 events being logged for each stx status change
// the category: swaps and the category: Transactions
const txEventData = {
category: 'Transactions',
properties: {
chain_id: updatedSmartTransaction.chainId,
referrer: updatedSmartTransaction.origin,
network: updatedSmartTransaction.metamaskNetworkId,
// Hardcoded properties since we don't have access to the transaction object at this point
// These properties are the same for all STX
account_type: 'MetaMask',
transaction_type: 'contractInteraction',
source: 'user',
token_standard: 'NONE',
},
sensitiveProperties: {
status: sensitiveProperties.stx_status,
first_seen: updatedSmartTransaction.time,
completion_time: sensitiveProperties.processing_time,
},
};

if (sensitiveProperties.stx_status === SmartTransactionStatuses.PENDING) {
this.trackMetaMetricsEvent({
event: 'Transaction Submitted',
...txEventData,
});
} else if (
sensitiveProperties.stx_status.includes(
SmartTransactionStatuses.CANCELLED,
)
) {
this.trackMetaMetricsEvent({
event: 'Transaction Finalized',
...txEventData,
});
}

this.trackMetaMetricsEvent({
event: 'STX Status Updated',
category: 'swaps',
Expand Down