Skip to content

Commit a594536

Browse files
authored
fix: Metrics (#390)
* fix: Update metrics * Improve tests
1 parent da59b11 commit a594536

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

src/SmartTransactionsController.test.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ const createStateAfterPending = () => {
233233
minedTx: 'not_mined',
234234
minedHash: '',
235235
},
236+
accountHardwareType: 'Ledger Hardware',
237+
accountType: 'hardware',
238+
deviceModel: 'ledger',
236239
},
237240
];
238241
};
@@ -262,6 +265,9 @@ const createStateAfterSuccess = () => {
262265
'0x55ad39634ee10d417b6e190cfd3736098957e958879cffe78f1f00f4fd2654d6',
263266
minedTx: 'success',
264267
},
268+
accountHardwareType: 'Ledger Hardware',
269+
accountType: 'hardware',
270+
deviceModel: 'ledger',
265271
},
266272
];
267273
};
@@ -616,7 +622,21 @@ describe('SmartTransactionsController', () => {
616622
smartTransactionsController.trackStxStatusChange(
617623
smartTransaction as SmartTransaction,
618624
);
619-
expect(trackMetaMetricsEventSpy).toHaveBeenCalled();
625+
expect(trackMetaMetricsEventSpy).toHaveBeenCalledWith(
626+
expect.objectContaining({
627+
event: 'STX Status Updated',
628+
category: 'Transactions',
629+
properties: expect.objectContaining({
630+
stx_status: SmartTransactionStatuses.PENDING,
631+
is_smart_transaction: true,
632+
}),
633+
sensitiveProperties: expect.objectContaining({
634+
account_hardware_type: 'Ledger Hardware',
635+
account_type: 'hardware',
636+
device_model: 'ledger',
637+
}),
638+
}),
639+
);
620640
});
621641

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

631651
it('tracks status change if smartTransaction and prevSmartTransaction have different statuses', () => {
632652
const smartTransaction = {
633-
...createStateAfterPending()[0],
653+
...createStateAfterSuccess()[0],
634654
swapMetaData: {},
635655
};
636-
const prevSmartTransaction = { ...smartTransaction, status: '' };
656+
const prevSmartTransaction = {
657+
...smartTransaction,
658+
status: SmartTransactionStatuses.PENDING,
659+
};
637660
smartTransactionsController.trackStxStatusChange(
638661
smartTransaction as SmartTransaction,
639662
prevSmartTransaction as SmartTransaction,
640663
);
641-
expect(trackMetaMetricsEventSpy).toHaveBeenCalled();
664+
expect(trackMetaMetricsEventSpy).toHaveBeenCalledWith(
665+
expect.objectContaining({
666+
event: 'STX Status Updated',
667+
category: 'Transactions',
668+
properties: expect.objectContaining({
669+
stx_status: SmartTransactionStatuses.SUCCESS,
670+
is_smart_transaction: true,
671+
}),
672+
sensitiveProperties: expect.objectContaining({
673+
account_hardware_type: 'Ledger Hardware',
674+
account_type: 'hardware',
675+
device_model: 'ledger',
676+
}),
677+
}),
678+
);
642679
});
643680
});
644681

src/SmartTransactionsController.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,10 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
323323
this.trackMetaMetricsEvent({
324324
event: MetaMetricsEventName.StxStatusUpdated,
325325
category: MetaMetricsEventCategory.Transactions,
326-
properties: getSmartTransactionMetricsProperties(smartTransaction),
327-
sensitiveProperties:
328-
getSmartTransactionMetricsSensitiveProperties(smartTransaction),
326+
properties: getSmartTransactionMetricsProperties(updatedSmartTransaction),
327+
sensitiveProperties: getSmartTransactionMetricsSensitiveProperties(
328+
updatedSmartTransaction,
329+
),
329330
});
330331
}
331332

@@ -427,6 +428,10 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
427428
throw new Error(ETH_QUERY_ERROR_MSG);
428429
}
429430

431+
if (isNewSmartTransaction) {
432+
await this.#addMetaMetricsPropsToNewSmartTransaction(smartTransaction);
433+
}
434+
430435
this.trackStxStatusChange(
431436
smartTransaction,
432437
isNewSmartTransaction
@@ -435,7 +440,6 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
435440
);
436441

437442
if (isNewSmartTransaction) {
438-
await this.#addMetaMetricsPropsToNewSmartTransaction(smartTransaction);
439443
// add smart transaction
440444
const cancelledNonceIndex = currentSmartTransactions?.findIndex(
441445
(stx: SmartTransaction) =>

0 commit comments

Comments
 (0)