Skip to content

Commit f47f2f6

Browse files
authored
test(confirmations): cover deposit_limit in alert metrics (#47580)
## **Description** Counterpart to the Mobile work in [CONF-2194](https://consensyssoftware.atlassian.net/browse/CONF-2194) ([metamask-mobile#38715](MetaMask/metamask-mobile#38715)), where the `deposit_limit` alert was **completely absent** from Mixpanel — zero `Transaction Added` / `Submitted` / `Rejected` / `Finalized` events carried it between 2025-01-01 and 2026-10-26. **The headline result: that bug does not reproduce here, so this PR contains no production code change.** I verified each of the three Mobile defects against this codebase: | Mobile defect | Extension status | |---|---| | Alert never registered in `useConfirmationAlerts` | Already registered — `useConfirmationAlerts.ts:58` | | Hook only read an explicit `pendingAmount` arg, so bare calls saw `0` | Already falls back to `primaryRequiredToken.amountFiat ?? amountUsd` — `useTransactionDepositLimitAlert.ts:42-54` | | `trackAlertMetrics` lived in a `Footer` that early-returns `null` for money-account deposits | Mounted in the `ConfirmAlerts` **provider** at `confirm.tsx:32`, above `<Footer />` at `confirm.tsx:48` | That third point is the important one. The Footer here *does* diverge for money-account deposits — `isSingleActionFooterConfirmation` (`footer.tsx:94-124`) routes `moneyAccountDeposit`, `moneyAccountWithdraw`, `musdConversion`, `perpsDeposit`, `perpsWithdraw` to a `SingleActionFooter`, which is the same failure shape as Mobile. But because the metrics hook sits two levels up in a pass-through provider with **no early returns, no conditionals** (`confirm-alerts.tsx:8-28`), the Footer's divergence cannot suppress the metric. There is also a structural reason the Mobile "uncommitted amount" problem can't occur: Mobile gates the commit behind a Done button that the cap itself disables, so an over-cap amount is never persisted. Here `useTransactionCustomAmount` auto-commits on a debounce (`:198-221`) with no blocking gate, so the over-cap value does reach `primaryRequiredToken` and the committed fallback sees it. ### What this PR actually does The one real gap was **test coverage**: nothing pinned `AlertsName.DepositLimit` to its `'deposit_limit'` metrics name, or asserted it survives the per-transaction-type exclusion filter. So a future edit to `ALERTS_NAME_METRICS` (`useConfirmationAlertMetrics.ts:28`), to `EXCLUDED_ALERT_KEYS_BY_TRANSACTION_TYPE` (`:53-58`), or to where `ConfirmAlerts` is mounted could silently reintroduce the Mobile regression with nothing failing. Three tests added to `useConfirmationAlertMetrics.test.ts`: 1. an over-cap money-account deposit reports `alert_triggered: ['deposit_limit']` 2. the alert is **not** swept up by the exclusion that drops `hexDataWhileInteractingWithNonContractAddress` for this transaction type 3. it is reported in `alert_resolved` once confirmed These pass against current `main`, which is the evidence that the pipeline already works end to end rather than an assertion that it should. ### Two differences from Mobile worth noting for reviewers - **Property names differ.** Extension emits `alert_triggered` / `alert_triggered_count`; Mobile emits `alert_trigger_name` / `alert_trigger_count`. Anyone querying both clients needs both names. - **`fiat_buy_amount_limit` does not exist here at all** — no `useFiatBuyLimitAlert`, no `AlertsName` member. On Mobile that alert was *also* dark and got fixed incidentally. Nothing to port. ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: [CONF-2222](https://consensyssoftware.atlassian.net/browse/CONF-2222) Refs: [CONF-2194](https://consensyssoftware.atlassian.net/browse/CONF-2194) · [metamask-mobile#38715](MetaMask/metamask-mobile#38715) ## **Manual testing steps** No user-facing change; the production behaviour is already correct. To confirm the instrumentation by hand: 1. Set `confirmations_pay_extended.depositLimit.moneyAccountDeposit` to a low value (e.g. `100`). 2. Open a Money account deposit confirmation. 3. Enter an amount above that limit. 4. Confirm the blocking "Max deposit: $X" alert appears on the amount row and Confirm is disabled. 5. Inspect the transaction event fragment / Segment payload and confirm `alert_triggered` contains `deposit_limit`. 6. Back out of the confirmation and confirm the resulting rejected event still carries the property. Automated: `yarn jest ui/pages/confirmations/hooks/useConfirmationAlertMetrics.test.ts` — 16 passed. ## **Screenshots/Recordings** N/A — test-only change, no UI impact. ### **Before** N/A ### **After** N/A ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. [CONF-2194]: https://consensyssoftware.atlassian.net/browse/CONF-2194?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ [CONF-2222]: https://consensyssoftware.atlassian.net/browse/CONF-2222?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Test-only change with no runtime or analytics pipeline modifications. > > **Overview** > This PR adds **test-only** coverage for the money-account **deposit limit** alert in `useConfirmationAlertMetrics` — no production code changes. > > A new **`deposit limit`** describe block adds three cases: over-cap money-account deposits emit **`alert_triggered: ['deposit_limit']`**, **`deposit_limit` is not filtered** by the same per-type exclusion that drops **`hexDataWhileInteractingWithNonContractAddress`**, and a user-confirmed deposit limit alert appears in **`alert_resolved`**. Together they lock the existing **`AlertsName.DepositLimit` → `deposit_limit`** mapping and behavior so future edits to metrics naming or exclusion rules cannot silently drop the alert (as happened on Mobile). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit cc3c76a. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 387f2ac commit f47f2f6

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

‎ui/pages/confirmations/hooks/useConfirmationAlertMetrics.test.ts‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,74 @@ describe('useConfirmationAlertMetrics', () => {
358358
expect(properties.alert_triggered_count).toBe(1);
359359
});
360360
});
361+
362+
describe('deposit limit', () => {
363+
const DEPOSIT_LIMIT_ALERT_MOCK = {
364+
key: AlertsName.DepositLimit,
365+
field: 'Amount',
366+
severity: Severity.Danger,
367+
message: 'Max deposit: $100,000',
368+
reason: 'Max deposit: $100,000',
369+
isBlocking: true,
370+
};
371+
372+
it('reports an over-cap money account deposit as deposit_limit', () => {
373+
renderHookWithConfirmContextProvider(
374+
() => useConfirmationAlertMetrics(),
375+
buildState([DEPOSIT_LIMIT_ALERT_MOCK], MONEY_ACCOUNT_DEPOSIT_OVERRIDES),
376+
);
377+
378+
const { properties } =
379+
mockUpdateTransactionEventFragment.mock.calls.at(-1)[0];
380+
381+
expect(properties.alert_triggered).toStrictEqual(['deposit_limit']);
382+
expect(properties.alert_triggered_count).toBe(1);
383+
});
384+
385+
it('is not excluded for money account deposits', () => {
386+
renderHookWithConfirmContextProvider(
387+
() => useConfirmationAlertMetrics(),
388+
buildState(
389+
[DEPOSIT_LIMIT_ALERT_MOCK, NON_CONTRACT_ALERT_MOCK],
390+
MONEY_ACCOUNT_DEPOSIT_OVERRIDES,
391+
),
392+
);
393+
394+
const { properties } =
395+
mockUpdateTransactionEventFragment.mock.calls.at(-1)[0];
396+
397+
// The non-contract alert is excluded for this type; deposit_limit is not.
398+
expect(properties.alert_triggered).toStrictEqual(['deposit_limit']);
399+
});
400+
401+
it('records the alert as resolved once confirmed', () => {
402+
const state = getMockConfirmStateForTransaction(
403+
{
404+
...contractInteraction,
405+
...MONEY_ACCOUNT_DEPOSIT_OVERRIDES,
406+
id: OWNER_ID_MOCK,
407+
} as TransactionMeta,
408+
{
409+
metamask: {},
410+
confirmAlerts: {
411+
alerts: { [OWNER_ID_MOCK]: [DEPOSIT_LIMIT_ALERT_MOCK] },
412+
confirmed: {
413+
[OWNER_ID_MOCK]: { [AlertsName.DepositLimit]: true },
414+
},
415+
},
416+
},
417+
);
418+
419+
renderHookWithConfirmContextProvider(
420+
() => useConfirmationAlertMetrics(),
421+
state,
422+
);
423+
424+
const { properties } =
425+
mockUpdateTransactionEventFragment.mock.calls.at(-1)[0];
426+
427+
expect(properties.alert_resolved).toStrictEqual(['deposit_limit']);
428+
expect(properties.alert_resolved_count).toBe(1);
429+
});
430+
});
361431
});

0 commit comments

Comments
 (0)