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: Metrics #390

Merged
merged 2 commits into from
Jul 24, 2024
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
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 @@
minedTx: 'not_mined',
minedHash: '',
},
accountHardwareType: 'Ledger Hardware',
accountType: 'hardware',
deviceModel: 'ledger',
},
];
};
Expand Down Expand Up @@ -262,6 +265,9 @@
'0x55ad39634ee10d417b6e190cfd3736098957e958879cffe78f1f00f4fd2654d6',
minedTx: 'success',
},
accountHardwareType: 'Ledger Hardware',
accountType: 'hardware',
deviceModel: 'ledger',
},
];
};
Expand Down Expand Up @@ -616,7 +622,21 @@
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 @@

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 Expand Up @@ -1223,13 +1260,13 @@

describe('setStatusRefreshInterval', () => {
it('sets refresh interval if different', () => {
smartTransactionsController.setStatusRefreshInterval(100);

Check warning on line 1263 in src/SmartTransactionsController.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 1263 in src/SmartTransactionsController.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
expect(smartTransactionsController.config.interval).toBe(100);
});

it('does not set refresh interval if they are the same', () => {
const configureSpy = jest.spyOn(smartTransactionsController, 'configure');
smartTransactionsController.setStatusRefreshInterval(DEFAULT_INTERVAL);

Check warning on line 1269 in src/SmartTransactionsController.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 1269 in src/SmartTransactionsController.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
expect(configureSpy).toHaveBeenCalledTimes(0);
});
});
Expand Down
12 changes: 8 additions & 4 deletions src/SmartTransactionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@
isSmartTransactionPending,
);
if (!this.timeoutHandle && pendingTransactions?.length > 0) {
this.poll();

Check warning on line 230 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 230 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
} else if (this.timeoutHandle && pendingTransactions?.length === 0) {
this.stop();

Check warning on line 232 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 232 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}
}

Expand Down Expand Up @@ -287,7 +287,7 @@
return;
}
this.timeoutHandle = setInterval(() => {
safelyExecute(async () => this.updateSmartTransactions());

Check warning on line 290 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 290 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}, this.config.interval);
await safelyExecute(async () => this.updateSmartTransactions());
}
Expand Down Expand Up @@ -323,9 +323,10 @@
this.trackMetaMetricsEvent({
event: MetaMetricsEventName.StxStatusUpdated,
category: MetaMetricsEventCategory.Transactions,
properties: getSmartTransactionMetricsProperties(smartTransaction),
sensitiveProperties:
getSmartTransactionMetricsSensitiveProperties(smartTransaction),
properties: getSmartTransactionMetricsProperties(updatedSmartTransaction),
sensitiveProperties: getSmartTransactionMetricsSensitiveProperties(
updatedSmartTransaction,
),
});
}

Expand Down Expand Up @@ -354,7 +355,7 @@
ethQuery = new EthQuery(networkClient.provider);
}

this.#createOrUpdateSmartTransaction(smartTransaction, {

Check warning on line 358 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 358 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
chainId,
ethQuery,
});
Expand Down Expand Up @@ -427,6 +428,10 @@
throw new Error(ETH_QUERY_ERROR_MSG);
}

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

this.trackStxStatusChange(
smartTransaction,
isNewSmartTransaction
Expand All @@ -435,7 +440,6 @@
);

if (isNewSmartTransaction) {
await this.#addMetaMetricsPropsToNewSmartTransaction(smartTransaction);
// add smart transaction
const cancelledNonceIndex = currentSmartTransactions?.findIndex(
(stx: SmartTransaction) =>
Expand Down Expand Up @@ -507,7 +511,7 @@
.map((smartTransaction) => smartTransaction.uuid);

if (transactionsToUpdate.length > 0) {
this.fetchSmartTransactionsStatus(transactionsToUpdate, {

Check warning on line 514 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 514 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
networkClientId,
});
}
Expand Down Expand Up @@ -671,7 +675,7 @@
nonceLock.releaseLock();
return {
...transaction,
nonce: `0x${nonce.toString(16)}`,

Check warning on line 678 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Invalid type "any" of template literal expression

Check warning on line 678 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Invalid type "any" of template literal expression
};
}

Expand Down
Loading