Skip to content

Commit

Permalink
fix: Metrics (#390)
Browse files Browse the repository at this point in the history
* fix: Update metrics
* Improve tests
  • Loading branch information
dan437 authored Jul 24, 2024
1 parent da59b11 commit a594536
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
45 changes: 41 additions & 4 deletions src/SmartTransactionsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ const createStateAfterPending = () => {
minedTx: 'not_mined',
minedHash: '',
},
accountHardwareType: 'Ledger Hardware',
accountType: 'hardware',
deviceModel: 'ledger',
},
];
};
Expand Down Expand Up @@ -262,6 +265,9 @@ const createStateAfterSuccess = () => {
'0x55ad39634ee10d417b6e190cfd3736098957e958879cffe78f1f00f4fd2654d6',
minedTx: 'success',
},
accountHardwareType: 'Ledger Hardware',
accountType: 'hardware',
deviceModel: 'ledger',
},
];
};
Expand Down Expand Up @@ -616,7 +622,21 @@ describe('SmartTransactionsController', () => {
smartTransactionsController.trackStxStatusChange(
smartTransaction as SmartTransaction,
);
expect(trackMetaMetricsEventSpy).toHaveBeenCalled();
expect(trackMetaMetricsEventSpy).toHaveBeenCalledWith(
expect.objectContaining({
event: 'STX Status Updated',
category: 'Transactions',
properties: expect.objectContaining({
stx_status: SmartTransactionStatuses.PENDING,
is_smart_transaction: true,
}),
sensitiveProperties: expect.objectContaining({
account_hardware_type: 'Ledger Hardware',
account_type: 'hardware',
device_model: 'ledger',
}),
}),
);
});

it('does not track if smartTransaction and prevSmartTransaction have the same status', () => {
Expand All @@ -630,15 +650,32 @@ describe('SmartTransactionsController', () => {

it('tracks status change if smartTransaction and prevSmartTransaction have different statuses', () => {
const smartTransaction = {
...createStateAfterPending()[0],
...createStateAfterSuccess()[0],
swapMetaData: {},
};
const prevSmartTransaction = { ...smartTransaction, status: '' };
const prevSmartTransaction = {
...smartTransaction,
status: SmartTransactionStatuses.PENDING,
};
smartTransactionsController.trackStxStatusChange(
smartTransaction as SmartTransaction,
prevSmartTransaction as SmartTransaction,
);
expect(trackMetaMetricsEventSpy).toHaveBeenCalled();
expect(trackMetaMetricsEventSpy).toHaveBeenCalledWith(
expect.objectContaining({
event: 'STX Status Updated',
category: 'Transactions',
properties: expect.objectContaining({
stx_status: SmartTransactionStatuses.SUCCESS,
is_smart_transaction: true,
}),
sensitiveProperties: expect.objectContaining({
account_hardware_type: 'Ledger Hardware',
account_type: 'hardware',
device_model: 'ledger',
}),
}),
);
});
});

Expand Down
12 changes: 8 additions & 4 deletions src/SmartTransactionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,10 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
this.trackMetaMetricsEvent({
event: MetaMetricsEventName.StxStatusUpdated,
category: MetaMetricsEventCategory.Transactions,
properties: getSmartTransactionMetricsProperties(smartTransaction),
sensitiveProperties:
getSmartTransactionMetricsSensitiveProperties(smartTransaction),
properties: getSmartTransactionMetricsProperties(updatedSmartTransaction),
sensitiveProperties: getSmartTransactionMetricsSensitiveProperties(
updatedSmartTransaction,
),
});
}

Expand Down Expand Up @@ -427,6 +428,10 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
throw new Error(ETH_QUERY_ERROR_MSG);
}

if (isNewSmartTransaction) {
await this.#addMetaMetricsPropsToNewSmartTransaction(smartTransaction);
}

this.trackStxStatusChange(
smartTransaction,
isNewSmartTransaction
Expand All @@ -435,7 +440,6 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
);

if (isNewSmartTransaction) {
await this.#addMetaMetricsPropsToNewSmartTransaction(smartTransaction);
// add smart transaction
const cancelledNonceIndex = currentSmartTransactions?.findIndex(
(stx: SmartTransaction) =>
Expand Down

0 comments on commit a594536

Please sign in to comment.