From cdc96be20e13bbcfe66cc6e61adcef654e892cd7 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Mon, 23 Sep 2024 17:32:57 +0100 Subject: [PATCH] fix: Hide contract interaction redesign --- .../snap-account-contract-interaction.spec.ts | 2 +- .../contract-interaction-redesign.spec.ts | 2 +- .../transactions/metrics.spec.ts | 2 +- .../contract-interaction.test.tsx | 2 +- .../header/__snapshots__/header.test.tsx.snap | 14 --- .../usePendingTransactionAlerts.test.ts | 17 +-- .../useSigningOrSubmittingAlerts.test.ts | 23 ++-- .../hooks/useConfirmationAlertMetrics.test.ts | 111 +----------------- .../hooks/useCurrentConfirmation.test.ts | 8 +- ui/pages/confirmations/utils/confirm.ts | 2 +- 10 files changed, 22 insertions(+), 161 deletions(-) diff --git a/test/e2e/accounts/snap-account-contract-interaction.spec.ts b/test/e2e/accounts/snap-account-contract-interaction.spec.ts index 4588d014802c..a11236aa94ef 100644 --- a/test/e2e/accounts/snap-account-contract-interaction.spec.ts +++ b/test/e2e/accounts/snap-account-contract-interaction.spec.ts @@ -17,7 +17,7 @@ import FixtureBuilder from '../fixture-builder'; import { SMART_CONTRACTS } from '../seeder/smart-contracts'; import { installSnapSimpleKeyring, importKeyAndSwitch } from './common'; -describe('Snap Account Contract interaction', function () { +describe.skip('Snap Account Contract interaction', function () { const smartContract = SMART_CONTRACTS.PIGGYBANK; it('deposits to piggybank contract', async function () { diff --git a/test/e2e/tests/confirmations/transactions/contract-interaction-redesign.spec.ts b/test/e2e/tests/confirmations/transactions/contract-interaction-redesign.spec.ts index fc6ca9e2ff4e..aadcd8352850 100644 --- a/test/e2e/tests/confirmations/transactions/contract-interaction-redesign.spec.ts +++ b/test/e2e/tests/confirmations/transactions/contract-interaction-redesign.spec.ts @@ -26,7 +26,7 @@ const FixtureBuilder = require('../../../fixture-builder'); const { SMART_CONTRACTS } = require('../../../seeder/smart-contracts'); const { CHAIN_IDS } = require('../../../../../shared/constants/network'); -describe('Confirmation Redesign Contract Interaction Component', function () { +describe.skip('Confirmation Redesign Contract Interaction Component', function () { const smartContract = SMART_CONTRACTS.PIGGYBANK; describe('Create a deposit transaction @no-mmi', function () { diff --git a/test/e2e/tests/confirmations/transactions/metrics.spec.ts b/test/e2e/tests/confirmations/transactions/metrics.spec.ts index f362196a50f6..6709d74c17ef 100644 --- a/test/e2e/tests/confirmations/transactions/metrics.spec.ts +++ b/test/e2e/tests/confirmations/transactions/metrics.spec.ts @@ -23,7 +23,7 @@ const { } = require('../../../helpers'); const FixtureBuilder = require('../../../fixture-builder'); -describe('Metrics @no-mmi', function () { +describe.skip('Metrics @no-mmi', function () { it('Sends a contract interaction type 2 transaction (EIP1559) with the right properties in the metric events', async function () { await withFixtures( { diff --git a/test/integration/confirmations/transactions/contract-interaction.test.tsx b/test/integration/confirmations/transactions/contract-interaction.test.tsx index 75fbc41ce81d..97ec85f37fbc 100644 --- a/test/integration/confirmations/transactions/contract-interaction.test.tsx +++ b/test/integration/confirmations/transactions/contract-interaction.test.tsx @@ -141,7 +141,7 @@ const getMetaMaskStateWithMaliciousUnapprovedContractInteraction = ( }; }; -describe('Contract Interaction Confirmation', () => { +describe.skip('Contract Interaction Confirmation', () => { beforeEach(() => { jest.resetAllMocks(); setupSubmitRequestToBackgroundMocks(); diff --git a/ui/pages/confirmations/components/confirm/header/__snapshots__/header.test.tsx.snap b/ui/pages/confirmations/components/confirm/header/__snapshots__/header.test.tsx.snap index 2d1ac826aa65..dee1361e4c9f 100644 --- a/ui/pages/confirmations/components/confirm/header/__snapshots__/header.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/header/__snapshots__/header.test.tsx.snap @@ -216,20 +216,6 @@ exports[`Header should match snapshot with transaction confirmation 1`] = ` -
- -
diff --git a/ui/pages/confirmations/hooks/alerts/transactions/usePendingTransactionAlerts.test.ts b/ui/pages/confirmations/hooks/alerts/transactions/usePendingTransactionAlerts.test.ts index cfd840f98bab..b964f6dde19c 100644 --- a/ui/pages/confirmations/hooks/alerts/transactions/usePendingTransactionAlerts.test.ts +++ b/ui/pages/confirmations/hooks/alerts/transactions/usePendingTransactionAlerts.test.ts @@ -3,10 +3,8 @@ import { TransactionStatus, TransactionType, } from '@metamask/transaction-controller'; -import { Severity } from '../../../../../helpers/constants/design-system'; -import { renderHookWithProvider } from '../../../../../../test/lib/render-helpers'; import mockState from '../../../../../../test/data/mock-state.json'; -import { RowAlertKey } from '../../../../../components/app/confirm/info/row/constants'; +import { renderHookWithProvider } from '../../../../../../test/lib/render-helpers'; import { usePendingTransactionAlerts } from './usePendingTransactionAlerts'; const ACCOUNT_ADDRESS = '0x123'; @@ -120,21 +118,12 @@ describe('usePendingTransactionAlerts', () => { ).toEqual([]); }); - it('returns alert if submitted transaction', () => { + it('returns no alert if submitted transaction because transaction type is not valid', () => { const alerts = runHook({ currentConfirmation: CONFIRMATION_MOCK, transactions: [TRANSACTION_META_MOCK], }); - expect(alerts).toEqual([ - { - field: RowAlertKey.Speed, - key: 'pendingTransactions', - message: - 'This transaction won’t go through until a previous transaction is complete. Learn how to cancel or speed up a transaction.', - reason: 'Pending transaction', - severity: Severity.Warning, - }, - ]); + expect(alerts).toEqual([]); }); }); diff --git a/ui/pages/confirmations/hooks/alerts/transactions/useSigningOrSubmittingAlerts.test.ts b/ui/pages/confirmations/hooks/alerts/transactions/useSigningOrSubmittingAlerts.test.ts index d52e66f77aa8..91372b735ebe 100644 --- a/ui/pages/confirmations/hooks/alerts/transactions/useSigningOrSubmittingAlerts.test.ts +++ b/ui/pages/confirmations/hooks/alerts/transactions/useSigningOrSubmittingAlerts.test.ts @@ -3,9 +3,8 @@ import { TransactionStatus, TransactionType, } from '@metamask/transaction-controller'; -import { Severity } from '../../../../../helpers/constants/design-system'; -import { renderHookWithProvider } from '../../../../../../test/lib/render-helpers'; import mockState from '../../../../../../test/data/mock-state.json'; +import { renderHookWithProvider } from '../../../../../../test/lib/render-helpers'; import { useSigningOrSubmittingAlerts } from './useSigningOrSubmittingAlerts'; const TRANSACTION_META_MOCK: Partial = { @@ -13,14 +12,6 @@ const TRANSACTION_META_MOCK: Partial = { chainId: '0x5', }; -const EXPECTED_ALERT = { - isBlocking: true, - key: 'signingOrSubmitting', - message: - 'This transaction will only go through once your previous transaction is complete.', - severity: Severity.Warning, -}; - const CONFIRMATION_MOCK = { type: TransactionType.contractInteraction, }; @@ -77,7 +68,7 @@ describe('useSigningOrSubmittingAlerts', () => { ).toEqual([]); }); - it('returns alerts if transaction on different chain', () => { + it('doesnt return alerts if transaction on different chain because transaction type is not valid', () => { expect( runHook({ currentConfirmation: CONFIRMATION_MOCK, @@ -89,7 +80,7 @@ describe('useSigningOrSubmittingAlerts', () => { }, ], }), - ).toEqual([EXPECTED_ALERT]); + ).toEqual([]); }); it('returns no alerts if transaction has alternate status', () => { @@ -112,7 +103,7 @@ describe('useSigningOrSubmittingAlerts', () => { ).toEqual([]); }); - it('returns alert if signed transaction', () => { + it('doesnt return alert if signed transaction because type is not valid', () => { const alerts = runHook({ currentConfirmation: CONFIRMATION_MOCK, transactions: [ @@ -120,10 +111,10 @@ describe('useSigningOrSubmittingAlerts', () => { ], }); - expect(alerts).toEqual([EXPECTED_ALERT]); + expect(alerts).toEqual([]); }); - it('returns alert if approved transaction', () => { + it('doesnt return alert if approved transaction because type is not valid', () => { const alerts = runHook({ currentConfirmation: CONFIRMATION_MOCK, transactions: [ @@ -131,6 +122,6 @@ describe('useSigningOrSubmittingAlerts', () => { ], }); - expect(alerts).toEqual([EXPECTED_ALERT]); + expect(alerts).toEqual([]); }); }); diff --git a/ui/pages/confirmations/hooks/useConfirmationAlertMetrics.test.ts b/ui/pages/confirmations/hooks/useConfirmationAlertMetrics.test.ts index 35a608c7c411..829f4f01d687 100644 --- a/ui/pages/confirmations/hooks/useConfirmationAlertMetrics.test.ts +++ b/ui/pages/confirmations/hooks/useConfirmationAlertMetrics.test.ts @@ -1,14 +1,10 @@ -import { act } from '@testing-library/react-hooks'; import { TransactionType } from '@metamask/transaction-controller'; -import { renderHookWithProvider } from '../../../../test/lib/render-helpers'; import mockState from '../../../../test/data/mock-state.json'; +import { renderHookWithProvider } from '../../../../test/lib/render-helpers'; import { Severity } from '../../../helpers/constants/design-system'; -import { - useConfirmationAlertMetrics, - ALERTS_NAME_METRICS, -} from './useConfirmationAlertMetrics'; -import * as transactionEventFragmentHook from './useTransactionEventFragment'; import { AlertsName } from './alerts/constants'; +import { useConfirmationAlertMetrics } from './useConfirmationAlertMetrics'; +import * as transactionEventFragmentHook from './useTransactionEventFragment'; jest.mock('./useTransactionEventFragment'); @@ -17,7 +13,6 @@ const mockUpdateTransactionEventFragment = jest.fn(); const OWNER_ID_MOCK = '123'; const KEY_ALERT_KEY_MOCK = 'Key'; const ALERT_MESSAGE_MOCK = 'Alert 1'; -const ALERT_NAME_METRICS_MOCK = ALERTS_NAME_METRICS[AlertsName.GasFeeLow]; const UUID_ALERT_KEY_MOCK = '550e8400-e29b-41d4-a716-446655440000'; const alertsMock = [ { @@ -58,20 +53,6 @@ const STATE_MOCK = { }, }; -const EXPECTED_PROPERTIES_BASE = { - alert_action_clicked: [], - alert_key_clicked: [], - alert_resolved: [], - alert_resolved_count: 0, - alert_triggered: [ - ALERT_NAME_METRICS_MOCK, - ALERTS_NAME_METRICS[AlertsName.Blockaid], - ], - alert_triggered_count: 2, - alert_visualized: [], - alert_visualized_count: 0, -}; - beforeEach(() => { jest.clearAllMocks(); ( @@ -92,90 +73,4 @@ describe('useConfirmationAlertMetrics', () => { expect(result.current.trackInlineAlertClicked).toBeInstanceOf(Function); expect(result.current.trackAlertActionClicked).toBeInstanceOf(Function); }); - - it('calls updateTransactionEventFragment with correct properties on initialization', () => { - renderHookWithProvider(() => useConfirmationAlertMetrics(), STATE_MOCK); - - expect(mockUpdateTransactionEventFragment).toHaveBeenCalledWith( - { properties: EXPECTED_PROPERTIES_BASE }, - OWNER_ID_MOCK, - ); - }); - - const testCases = [ - { - description: 'updates metrics properties when trackAlertRender is called', - alertKey: AlertsName.GasFeeLow, - action: 'trackAlertRender', - expectedProperties: { - alert_visualized: [ALERT_NAME_METRICS_MOCK], - alert_visualized_count: 1, - }, - }, - { - description: - 'updates metrics properties when trackInlineAlertClicked is called', - alertKey: AlertsName.GasFeeLow, - action: 'trackInlineAlertClicked', - expectedProperties: { - alert_key_clicked: [ALERT_NAME_METRICS_MOCK], - }, - }, - { - description: - 'updates metrics properties when trackAlertActionClicked is called', - alertKey: AlertsName.GasFeeLow, - action: 'trackAlertActionClicked', - expectedProperties: { - alert_action_clicked: [ALERT_NAME_METRICS_MOCK], - }, - }, - { - description: - 'updates metrics properties when receives alertKey as a valid UUID', - alertKey: UUID_ALERT_KEY_MOCK, - action: 'trackAlertRender', - expectedProperties: { - alert_visualized: [ALERTS_NAME_METRICS[AlertsName.Blockaid]], - alert_visualized_count: 1, - }, - }, - ]; - - // @ts-expect-error This is missing from the Mocha type definitions - it.each(testCases)( - '$description', - ({ - alertKey, - action, - expectedProperties, - }: { - description: string; - alertKey: string; - action: - | 'trackAlertRender' - | 'trackInlineAlertClicked' - | 'trackAlertActionClicked'; - expectedProperties: Record; - }) => { - const finalExpectedProperties = { - ...EXPECTED_PROPERTIES_BASE, - ...expectedProperties, - }; - - const { result } = renderHookWithProvider( - () => useConfirmationAlertMetrics(), - STATE_MOCK, - ); - - act(() => { - result.current[action](alertKey); - }); - - expect(mockUpdateTransactionEventFragment).toHaveBeenCalledWith( - { properties: finalExpectedProperties }, - OWNER_ID_MOCK, - ); - }, - ); }); diff --git a/ui/pages/confirmations/hooks/useCurrentConfirmation.test.ts b/ui/pages/confirmations/hooks/useCurrentConfirmation.test.ts index a71b14c13ce9..e2512a075b7e 100644 --- a/ui/pages/confirmations/hooks/useCurrentConfirmation.test.ts +++ b/ui/pages/confirmations/hooks/useCurrentConfirmation.test.ts @@ -128,7 +128,7 @@ describe('useCurrentConfirmation', () => { isRedesignedConfirmationsDeveloperEnabled: true, }); - expect(currentConfirmation).toStrictEqual(TRANSACTION_MOCK); + expect(currentConfirmation).toBeUndefined(); }); it('returns message matching ID param', () => { @@ -266,10 +266,10 @@ describe('useCurrentConfirmation', () => { isRedesignedConfirmationsDeveloperEnabled: true, }); - expect(currentConfirmation).toStrictEqual(TRANSACTION_MOCK); + expect(currentConfirmation).toBeUndefined(); }); - it('returns if env var and user settings are enabled and transaction has correct type', () => { + it('returns undefined if env var and user settings are enabled and transaction type is not supported', () => { const currentConfirmation = runHook({ pendingApprovals: [{ ...APPROVAL_MOCK, type: ApprovalType.Transaction }], transaction: { @@ -280,7 +280,7 @@ describe('useCurrentConfirmation', () => { isRedesignedConfirmationsDeveloperEnabled: true, }); - expect(currentConfirmation).toStrictEqual(TRANSACTION_MOCK); + expect(currentConfirmation).toStrictEqual(undefined); }); describe('useCurrentConfirmation with env var', () => { diff --git a/ui/pages/confirmations/utils/confirm.ts b/ui/pages/confirmations/utils/confirm.ts index be0907481631..c9ea8bd68ad5 100644 --- a/ui/pages/confirmations/utils/confirm.ts +++ b/ui/pages/confirmations/utils/confirm.ts @@ -16,7 +16,7 @@ export const REDESIGN_APPROVAL_TYPES = [ ApprovalType.PersonalSign, ]; -export const REDESIGN_TRANSACTION_TYPES = []; +export const REDESIGN_TRANSACTION_TYPES: TransactionType[] = []; const SIGNATURE_APPROVAL_TYPES = [ ApprovalType.PersonalSign,