From 4c9eff1e8de61d21f62e3b72020a4d788964e081 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Thu, 30 May 2024 07:29:50 -0230 Subject: [PATCH 1/2] fix: Remove basic configuration translations, which need to be updated after 6b2b88af (#24894) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** 190f4e5591d2477a89a94dd7645696e81453df19 added translations for the `basicConfigurationDescription` message, and then the next commit modified the english version of that message 2ecc82b99a6f344f2c723ea5fc56f48661ff1e79 Those original translations should be removed so that they can be translated again. Also, because the updated translation added a description for `basicConfigurationDescription` in english but not for the other locales, `yarn verify-locales` (which is part of `yarn lint`) is failing on develop. This PR fixes that. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24894?quickstart=1) ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.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. --- app/_locales/de/messages.json | 3 --- app/_locales/el/messages.json | 3 --- app/_locales/es/messages.json | 3 --- app/_locales/fr/messages.json | 3 --- app/_locales/hi/messages.json | 3 --- app/_locales/id/messages.json | 3 --- app/_locales/ja/messages.json | 3 --- app/_locales/ko/messages.json | 3 --- app/_locales/pt/messages.json | 3 --- app/_locales/ru/messages.json | 3 --- app/_locales/tl/messages.json | 3 --- app/_locales/tr/messages.json | 3 --- app/_locales/vi/messages.json | 3 --- app/_locales/zh_CN/messages.json | 3 --- 14 files changed, 42 deletions(-) diff --git a/app/_locales/de/messages.json b/app/_locales/de/messages.json index d86b9c25623d..f2614381e196 100644 --- a/app/_locales/de/messages.json +++ b/app/_locales/de/messages.json @@ -597,9 +597,6 @@ "basicConfigurationBannerTitle": { "message": "Grundfunktionalität ist ausgeschaltet" }, - "basicConfigurationDescription": { - "message": "Enthält Token-Daten und -Werte, optimale Gas-Einstellungen und mehr. Wenn Sie diese Dienste nutzen, wird Ihre IP-Adresse wie beim Besuch einer Website mit MetaMask geteilt." - }, "basicConfigurationLabel": { "message": "Grundfunktionalität" }, diff --git a/app/_locales/el/messages.json b/app/_locales/el/messages.json index 4e35f21f994e..4883af66d45d 100644 --- a/app/_locales/el/messages.json +++ b/app/_locales/el/messages.json @@ -597,9 +597,6 @@ "basicConfigurationBannerTitle": { "message": "Οι βασικές λειτουργίες είναι απενεργοποιημένες" }, - "basicConfigurationDescription": { - "message": "Περιλαμβάνει δεδομένα και τιμές για tokens, βέλτιστες ρυθμίσεις τέλών συναλλαγών και πολλά άλλα. Η χρήση αυτών των υπηρεσιών κοινοποιεί τη διεύθυνση IP σας στο MetaMask, όπως ακριβώς όταν επισκέπτεστε έναν ιστότοπο." - }, "basicConfigurationLabel": { "message": "Βασικές λειτουργίες" }, diff --git a/app/_locales/es/messages.json b/app/_locales/es/messages.json index a0c754fce62a..9044cadb3e90 100644 --- a/app/_locales/es/messages.json +++ b/app/_locales/es/messages.json @@ -594,9 +594,6 @@ "basicConfigurationBannerTitle": { "message": "La funcionalidad básica está desactivada" }, - "basicConfigurationDescription": { - "message": "Incluye datos y valor de los tokens, configuración óptima de gas y mucho más. Al usar estos servicios, comparte su dirección IP con MetaMask, al igual que cuando visita un sitio web." - }, "basicConfigurationLabel": { "message": "Funcionalidad básica" }, diff --git a/app/_locales/fr/messages.json b/app/_locales/fr/messages.json index 778a5d008daa..538f73209f27 100644 --- a/app/_locales/fr/messages.json +++ b/app/_locales/fr/messages.json @@ -597,9 +597,6 @@ "basicConfigurationBannerTitle": { "message": "La fonctionnalité de base est désactivée" }, - "basicConfigurationDescription": { - "message": "Comprend les données et la valeur des jetons, les réglages optimaux du gaz, et plus encore. Si vous utilisez ces services, votre adresse IP sera partagée avec MetaMask, comme lorsque vous visitez un site web." - }, "basicConfigurationLabel": { "message": "Fonctionnalité de base" }, diff --git a/app/_locales/hi/messages.json b/app/_locales/hi/messages.json index 74798ac18d73..d3b746822497 100644 --- a/app/_locales/hi/messages.json +++ b/app/_locales/hi/messages.json @@ -594,9 +594,6 @@ "basicConfigurationBannerTitle": { "message": "बेसिक फंक्शनलिटी बंद है" }, - "basicConfigurationDescription": { - "message": "इसमें टोकन डेटा और मूल्य, ऑप्टीमल गैस सेटिंग्स और बहुत कुछ शामिल है। इन सेवाओं का उपयोग करने से आपका आईपी ​​एड्रेस MetaMask के साथ शेयर हो जाता है, ठीक उसी तरह जब आप किसी वेबसाइट पर जाते हैं।" - }, "basicConfigurationLabel": { "message": "बेसिक फंक्शनलिटी" }, diff --git a/app/_locales/id/messages.json b/app/_locales/id/messages.json index bc299b5edb01..87b338086eec 100644 --- a/app/_locales/id/messages.json +++ b/app/_locales/id/messages.json @@ -597,9 +597,6 @@ "basicConfigurationBannerTitle": { "message": "Fungsionalitas dasar tidak aktif" }, - "basicConfigurationDescription": { - "message": "Meliputi nilai dan data token, pengaturan gas optimal, dan banyak lagi. MetaMask akan mengetahui alamat IP Anda saat menggunakan layanan ini, seperti halnya saat mengunjungi situs web." - }, "basicConfigurationLabel": { "message": "Fungsionalitas dasar" }, diff --git a/app/_locales/ja/messages.json b/app/_locales/ja/messages.json index 134485036c61..1574d7cae161 100644 --- a/app/_locales/ja/messages.json +++ b/app/_locales/ja/messages.json @@ -594,9 +594,6 @@ "basicConfigurationBannerTitle": { "message": "基本機能はオフになっています" }, - "basicConfigurationDescription": { - "message": "トークンのデータと値、最適なガス設定などを含みます。これらのサービスを使用すると、Webサイトにアクセスした場合と同様に、MetaMaskにIPアドレスが共有されます。" - }, "basicConfigurationLabel": { "message": "基本機能" }, diff --git a/app/_locales/ko/messages.json b/app/_locales/ko/messages.json index e3024c521aaa..bb1266db6bd1 100644 --- a/app/_locales/ko/messages.json +++ b/app/_locales/ko/messages.json @@ -594,9 +594,6 @@ "basicConfigurationBannerTitle": { "message": "기본 기능이 꺼져 있습니다." }, - "basicConfigurationDescription": { - "message": "토큰 데이터, 및 값, 최적의 가스 설정 등을 포함합니다. 이 서비스를 사용하면 웹사이트를 방문할 때와 마찬가지로 사용자의 IP 주소를 MetaMask와 공유하게 됩니다." - }, "basicConfigurationLabel": { "message": "기본 기능" }, diff --git a/app/_locales/pt/messages.json b/app/_locales/pt/messages.json index 90d53cedb4de..1fd337ea6005 100644 --- a/app/_locales/pt/messages.json +++ b/app/_locales/pt/messages.json @@ -597,9 +597,6 @@ "basicConfigurationBannerTitle": { "message": "A funcionalidade básica está desativada" }, - "basicConfigurationDescription": { - "message": "Inclui os dados e o valor dos tokens, as configurações ideais de gás e mais. Se você utilizar esses serviços, seu endereço IP será informado à MetaMask, assim como quando você visita um site." - }, "basicConfigurationLabel": { "message": "Funcionalidade básica" }, diff --git a/app/_locales/ru/messages.json b/app/_locales/ru/messages.json index 6643f143e476..dfb900e06e2a 100644 --- a/app/_locales/ru/messages.json +++ b/app/_locales/ru/messages.json @@ -597,9 +597,6 @@ "basicConfigurationBannerTitle": { "message": "Базовый функционал отключен" }, - "basicConfigurationDescription": { - "message": "Включает данные и стоимость токена, оптимальные настройки газа и многое другое. При использовании этих сервисов ваш IP-адрес передается MetaMask, как при посещении веб-сайта." - }, "basicConfigurationLabel": { "message": "Базовый функционал" }, diff --git a/app/_locales/tl/messages.json b/app/_locales/tl/messages.json index afc0fb04dd01..82667711e3c6 100644 --- a/app/_locales/tl/messages.json +++ b/app/_locales/tl/messages.json @@ -594,9 +594,6 @@ "basicConfigurationBannerTitle": { "message": "Naka-off ang batayang kapakinabangan" }, - "basicConfigurationDescription": { - "message": "Kasama ang data at halaga ng token, optimal na settings sa gas, at marami pang iba. Ang paggamit ng mga serbisyong ito ay nagbabahagi ng iyong IP address sa MetaMask, tulad kapag bumisita ka sa website." - }, "basicConfigurationLabel": { "message": "Batayang kapakinabangan" }, diff --git a/app/_locales/tr/messages.json b/app/_locales/tr/messages.json index 7449736cb09a..4289449f1b74 100644 --- a/app/_locales/tr/messages.json +++ b/app/_locales/tr/messages.json @@ -597,9 +597,6 @@ "basicConfigurationBannerTitle": { "message": "Temel işlevsellik kapalı" }, - "basicConfigurationDescription": { - "message": "Token verileri ve değeri, en iyi gaz ayarları ve daha fazlasını içerir. Bu hizmetleri kullanırken tıpkı bir web sitesini ziyaret ederken olduğu gibi IP adresiniz MetaMask ile paylaşılır." - }, "basicConfigurationLabel": { "message": "Temel işlevsellik" }, diff --git a/app/_locales/vi/messages.json b/app/_locales/vi/messages.json index e723de8ae789..e969d1fe9f93 100644 --- a/app/_locales/vi/messages.json +++ b/app/_locales/vi/messages.json @@ -594,9 +594,6 @@ "basicConfigurationBannerTitle": { "message": "Chức năng cơ bản đã tắt" }, - "basicConfigurationDescription": { - "message": "Bao gồm dữ liệu và giá trị của token, cài đặt gas tối ưu, v.v. Sử dụng các dịch vụ này sẽ chia sẻ địa chỉ IP của bạn với MetaMask, giống như khi bạn truy cập một trang web." - }, "basicConfigurationLabel": { "message": "Chức năng cơ bản" }, diff --git a/app/_locales/zh_CN/messages.json b/app/_locales/zh_CN/messages.json index 67fe1bcc168d..3d67ce8b8ffb 100644 --- a/app/_locales/zh_CN/messages.json +++ b/app/_locales/zh_CN/messages.json @@ -594,9 +594,6 @@ "basicConfigurationBannerTitle": { "message": "基本功能已关闭" }, - "basicConfigurationDescription": { - "message": "包括代币数据和值、最优燃料设置等。使用这些服务会与 MetaMask 共享您的 IP 地址,就像您访问网站一样。" - }, "basicConfigurationLabel": { "message": "基本功能" }, From e4bf8b3339771eb8958ef0175599f9f3fb454c94 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Thu, 30 May 2024 16:43:37 +0530 Subject: [PATCH 2/2] feat: implementing alerts for typed sign data signatures (#24702) --- app/_locales/en/messages.json | 6 ++ .../alert-modal/alert-modal.test.tsx | 2 +- .../alert-system/alert-modal/alert-modal.tsx | 25 ++++--- .../confirm-alert-modal.test.tsx | 66 ++++++++++--------- .../confirm-alert-modal.tsx | 31 ++++----- .../multiple-alert-modal.tsx | 2 +- ui/hooks/useAlerts.test.ts | 38 +++++++++-- ui/hooks/useAlerts.ts | 19 +++++- .../confirm/blockaid-alert/blockaid-alert.tsx | 40 ----------- .../confirm/blockaid-alert/index.tsx | 1 - .../components/confirm/footer/footer.test.tsx | 20 ++++-- .../components/confirm/footer/footer.tsx | 38 ++++------- .../confirm/footer/useIsDangerButton.ts | 23 ------- ui/pages/confirmations/confirm/confirm.tsx | 9 --- ...lerts.test.ts => useBlockaidAlert.test.ts} | 10 +-- ...sonalSignAlerts.ts => useBlockaidAlert.ts} | 19 +++--- .../confirmations/hooks/alerts/utils.test.ts | 6 +- ui/pages/confirmations/hooks/alerts/utils.ts | 2 +- .../hooks/useConfirmationAlerts.test.ts | 10 +-- .../hooks/useConfirmationAlerts.ts | 6 +- .../useSignatureSecurityAlertResponse.ts | 26 -------- ui/pages/confirmations/utils/confirm.test.ts | 21 +++++- ui/pages/confirmations/utils/confirm.ts | 9 +++ 23 files changed, 208 insertions(+), 221 deletions(-) delete mode 100644 ui/pages/confirmations/components/confirm/blockaid-alert/blockaid-alert.tsx delete mode 100644 ui/pages/confirmations/components/confirm/blockaid-alert/index.tsx delete mode 100644 ui/pages/confirmations/components/confirm/footer/useIsDangerButton.ts rename ui/pages/confirmations/hooks/alerts/{usePersonalSignAlerts.test.ts => useBlockaidAlert.test.ts} (92%) rename ui/pages/confirmations/hooks/alerts/{usePersonalSignAlerts.ts => useBlockaidAlert.ts} (80%) delete mode 100644 ui/pages/confirmations/hooks/useSignatureSecurityAlertResponse.ts diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 454396a829eb..b99c3976b8c9 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -669,6 +669,9 @@ "blockaid": { "message": "Blockaid" }, + "blockaidAlertInfo": { + "message": "If you sign in, a third party known for scams might take all your assets. Please review the alerts before you proceed." + }, "blockaidDescriptionApproveFarming": { "message": "If you approve this request, a third party known for scams might take all your assets." }, @@ -851,6 +854,9 @@ "confirmAlertModalAcknowledge": { "message": "I have acknowledged the alerts and still want to proceed" }, + "confirmAlertModalAcknowledgeBlockaid": { + "message": "I have acknowledged the alert and still want to proceed" + }, "confirmAlertModalDetails": { "message": "If you sign in, a third party known for scams might take all your assets. Please review the alerts before you proceed." }, diff --git a/ui/components/app/alert-system/alert-modal/alert-modal.test.tsx b/ui/components/app/alert-system/alert-modal/alert-modal.test.tsx index 6f496eced9df..dcd3a6fbb7a1 100644 --- a/ui/components/app/alert-system/alert-modal/alert-modal.test.tsx +++ b/ui/components/app/alert-system/alert-modal/alert-modal.test.tsx @@ -158,7 +158,7 @@ describe('AlertModal', () => { }, }); - useAlertsSpy.mockReturnValue({ + (useAlertsSpy as jest.Mock).mockReturnValue({ setAlertConfirmed: setAlertConfirmedMock, alerts: [alertsMock[1]], generalAlerts: [], diff --git a/ui/components/app/alert-system/alert-modal/alert-modal.tsx b/ui/components/app/alert-system/alert-modal/alert-modal.tsx index 8d1d296fb45a..df6cb2b0e647 100644 --- a/ui/components/app/alert-system/alert-modal/alert-modal.tsx +++ b/ui/components/app/alert-system/alert-modal/alert-modal.tsx @@ -1,5 +1,7 @@ import React, { useCallback } from 'react'; import { ButtonVariant } from '@metamask/snaps-sdk'; + +import { SecurityProvider } from '../../../../../shared/constants/security-provider'; import { Box, Button, @@ -133,6 +135,11 @@ function AlertHeader({ ); } +function BlockaidAlertDetails() { + const t = useI18nContext(); + return {t('blockaidAlertInfo')}; +} + function AlertDetails({ selectedAlert, customDetails, @@ -277,11 +284,7 @@ export function AlertModal({ customAcknowledgeButton, enableProvider = true, }: AlertModalProps) { - const { - isAlertConfirmed, - setAlertConfirmed, - fieldAlerts: alerts, - } = useAlerts(ownerId); + const { isAlertConfirmed, setAlertConfirmed, alerts } = useAlerts(ownerId); const handleClose = useCallback(() => { onClose(); @@ -311,10 +314,14 @@ export function AlertModal({ /> - + {selectedAlert?.provider === SecurityProvider.Blockaid ? ( + + ) : ( + + )} {customAcknowledgeCheckbox ?? ( { expect(onSubmitMock).toHaveBeenCalledTimes(1); }); - it('calls open multiple alert modal when review alerts link is clicked', () => { - const { getByTestId } = renderWithProvider( - , - mockStore, - ); + // todo: following 2 tests have been temporarily commented out + // we can un-comment as we add more alert providers - fireEvent.click(getByTestId('confirm-alert-modal-review-all-alerts')); - expect(getByTestId('alert-modal-button')).toBeInTheDocument(); - }); + // it('calls open multiple alert modal when review alerts link is clicked', () => { + // const { getByTestId } = renderWithProvider( + // , + // mockStore, + // ); - describe('when there are multiple alerts', () => { - it('renders the next alert when the "Got it" button is clicked', () => { - const mockStoreAcknowledgeAlerts = configureMockStore([])({ - ...STATE_MOCK, - confirmAlerts: { - alerts: { [OWNER_ID_MOCK]: alertsMock }, - confirmed: { - [OWNER_ID_MOCK]: { - [FROM_ALERT_KEY_MOCK]: true, - [DATA_ALERT_KEY_MOCK]: false, - }, - }, - }, - }); - const { getByTestId, getByText } = renderWithProvider( - , - mockStoreAcknowledgeAlerts, - ); - fireEvent.click(getByTestId('alert-modal-button')); - - expect(getByText(DATA_ALERT_MESSAGE_MOCK)).toBeInTheDocument(); - }); - }); + // fireEvent.click(getByTestId('confirm-alert-modal-review-all-alerts')); + // expect(getByTestId('alert-modal-button')).toBeInTheDocument(); + // }); + + // describe('when there are multiple alerts', () => { + // it('renders the next alert when the "Got it" button is clicked', () => { + // const mockStoreAcknowledgeAlerts = configureMockStore([])({ + // ...STATE_MOCK, + // confirmAlerts: { + // alerts: { [OWNER_ID_MOCK]: alertsMock }, + // confirmed: { + // [OWNER_ID_MOCK]: { + // [FROM_ALERT_KEY_MOCK]: true, + // [DATA_ALERT_KEY_MOCK]: false, + // }, + // }, + // }, + // }); + // const { getByTestId, getByText } = renderWithProvider( + // , + // mockStoreAcknowledgeAlerts, + // ); + // fireEvent.click(getByTestId('confirm-alert-modal-review-all-alerts')); + // fireEvent.click(getByTestId('alert-modal-button')); + + // expect(getByText(DATA_ALERT_MESSAGE_MOCK)).toBeInTheDocument(); + // }); + // }); }); diff --git a/ui/components/app/alert-system/confirm-alert-modal/confirm-alert-modal.tsx b/ui/components/app/alert-system/confirm-alert-modal/confirm-alert-modal.tsx index 157941c9c5e7..e31d9c853e2e 100644 --- a/ui/components/app/alert-system/confirm-alert-modal/confirm-alert-modal.tsx +++ b/ui/components/app/alert-system/confirm-alert-modal/confirm-alert-modal.tsx @@ -1,4 +1,6 @@ import React, { useCallback, useState } from 'react'; + +import { SecurityProvider } from '../../../../../shared/constants/security-provider'; import { Box, Button, @@ -13,7 +15,6 @@ import { } from '../../../component-library'; import { AlignItems, - Severity, TextAlign, TextVariant, } from '../../../../helpers/constants/design-system'; @@ -22,7 +23,6 @@ import useAlerts from '../../../../hooks/useAlerts'; import { AlertModal } from '../alert-modal'; import { AcknowledgeCheckboxBase } from '../alert-modal/alert-modal'; import { MultipleAlertModal } from '../multiple-alert-modal'; -import { Alert } from '../../../../ducks/confirm-alerts/confirm-alerts'; export type ConfirmAlertModalProps = { /** The unique key representing the specific alert field. */ @@ -56,7 +56,7 @@ function ConfirmButtons({ variant={ButtonVariant.Secondary} data-testid="confirm-alert-modal-cancel-button" > - {t('cancel')} + {t('reject')} ); -} +}; const Footer = () => { const dispatch = useDispatch(); diff --git a/ui/pages/confirmations/components/confirm/footer/useIsDangerButton.ts b/ui/pages/confirmations/components/confirm/footer/useIsDangerButton.ts deleted file mode 100644 index 73d626f26cdf..000000000000 --- a/ui/pages/confirmations/components/confirm/footer/useIsDangerButton.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { useSelector } from 'react-redux'; -import useSignatureSecurityAlertResponse from '../../../hooks/useSignatureSecurityAlertResponse'; -import { currentConfirmationSelector } from '../../../selectors'; -import { SecurityAlertResponse } from '../../../types/confirm'; -import { BlockaidResultType } from '../../../../../../shared/constants/security-provider'; - -const useIsDangerButton = () => { - const currentConfirmation = useSelector(currentConfirmationSelector); - - const currentSecurityAlertId = ( - currentConfirmation?.securityAlertResponse as SecurityAlertResponse - )?.securityAlertId; - - const signatureSecurityAlertResponse = useSignatureSecurityAlertResponse( - currentSecurityAlertId, - ); - - return ( - signatureSecurityAlertResponse?.result_type === BlockaidResultType.Malicious - ); -}; - -export default useIsDangerButton; diff --git a/ui/pages/confirmations/confirm/confirm.tsx b/ui/pages/confirmations/confirm/confirm.tsx index ff3c576d4859..8dd75a692def 100644 --- a/ui/pages/confirmations/confirm/confirm.tsx +++ b/ui/pages/confirmations/confirm/confirm.tsx @@ -13,9 +13,6 @@ import { Title } from '../components/confirm/title'; import { Page } from '../../../components/multichain/pages/page'; import setCurrentConfirmation from '../hooks/setCurrentConfirmation'; import syncConfirmPath from '../hooks/syncConfirmPath'; -///: BEGIN:ONLY_INCLUDE_IF(blockaid) -import { BlockaidAlert } from '../components/confirm/blockaid-alert'; -///: END:ONLY_INCLUDE_IF import { LedgerInfo } from '../components/confirm/ledger-info'; import setConfirmationAlerts from '../hooks/setConfirmationAlerts'; import useConfirmationAlertActions from '../hooks/useConfirmationAlertActions'; @@ -38,12 +35,6 @@ const Confirm = () => { } - { - // todo: section below is to be removed once new alerts implementation is there - ///: BEGIN:ONLY_INCLUDE_IF(blockaid) - - ///: END:ONLY_INCLUDE_IF - } <Info /> </ScrollToBottom> diff --git a/ui/pages/confirmations/hooks/alerts/usePersonalSignAlerts.test.ts b/ui/pages/confirmations/hooks/alerts/useBlockaidAlert.test.ts similarity index 92% rename from ui/pages/confirmations/hooks/alerts/usePersonalSignAlerts.test.ts rename to ui/pages/confirmations/hooks/alerts/useBlockaidAlert.test.ts index 998ccd905b33..ad8054e898a8 100644 --- a/ui/pages/confirmations/hooks/alerts/usePersonalSignAlerts.test.ts +++ b/ui/pages/confirmations/hooks/alerts/useBlockaidAlert.test.ts @@ -7,7 +7,7 @@ import { import { Severity } from '../../../../helpers/constants/design-system'; import { renderHookWithProvider } from '../../../../../test/lib/render-helpers'; import mockState from '../../../../../test/data/mock-state.json'; -import usePersonalSignAlerts from './usePersonalSignAlerts'; +import useBlockaidAlert from './useBlockaidAlert'; const mockSecurityAlertResponse: SecurityAlertResponse = { securityAlertId: 'test-id-mock', @@ -48,7 +48,7 @@ const mockExpectedState = { confirm: { currentConfirmation: currentConfirmationMock }, }; -describe('usePersonalSignAlerts', () => { +describe('useBlockaidAlert', () => { beforeAll(() => { process.env.ENABLE_CONFIRMATION_REDESIGN = 'true'; }); @@ -59,7 +59,7 @@ describe('usePersonalSignAlerts', () => { it('returns an empty array when there is no current confirmation', () => { const { result } = renderHookWithProvider( - () => usePersonalSignAlerts(), + () => useBlockaidAlert(), mockState, ); expect(result.current).toEqual([]); @@ -77,7 +77,7 @@ describe('usePersonalSignAlerts', () => { }, }; const { result } = renderHookWithProvider( - () => usePersonalSignAlerts(), + () => useBlockaidAlert(), alteredState, ); expect(result.current).toEqual([]); @@ -92,7 +92,7 @@ describe('usePersonalSignAlerts', () => { provider: SecurityProvider.Blockaid, reason: 'This is a deceptive request', }; - const { result } = renderHookWithProvider(() => usePersonalSignAlerts(), { + const { result } = renderHookWithProvider(() => useBlockaidAlert(), { ...mockExpectedState, metamask: { ...mockExpectedState.metamask, diff --git a/ui/pages/confirmations/hooks/alerts/usePersonalSignAlerts.ts b/ui/pages/confirmations/hooks/alerts/useBlockaidAlert.ts similarity index 80% rename from ui/pages/confirmations/hooks/alerts/usePersonalSignAlerts.ts rename to ui/pages/confirmations/hooks/alerts/useBlockaidAlert.ts index 3cc658703a8a..7eae58b553c7 100644 --- a/ui/pages/confirmations/hooks/alerts/usePersonalSignAlerts.ts +++ b/ui/pages/confirmations/hooks/alerts/useBlockaidAlert.ts @@ -1,12 +1,13 @@ import { useMemo } from 'react'; -import { ApprovalType } from '@metamask/controller-utils'; import { useSelector } from 'react-redux'; -import useCurrentConfirmation from '../useCurrentConfirmation'; + +import { BlockaidResultType } from '../../../../../shared/constants/security-provider'; import { Alert } from '../../../../ducks/confirm-alerts/confirm-alerts'; -import { SecurityAlertResponse } from '../../types/confirm'; import { useI18nContext } from '../../../../hooks/useI18nContext'; -import { BlockaidResultType } from '../../../../../shared/constants/security-provider'; -import { providerAlertNormalizer } from './utils'; +import { SecurityAlertResponse } from '../../types/confirm'; +import { isSignatureTransactionType } from '../../utils'; +import useCurrentConfirmation from '../useCurrentConfirmation'; +import { normalizeProviderAlert } from './utils'; type SignatureSecurityAlertResponsesState = { metamask: { @@ -14,7 +15,7 @@ type SignatureSecurityAlertResponsesState = { }; }; -const usePersonalSignAlerts = (): Alert[] => { +const useBlockaidAlerts = (): Alert[] => { const { currentConfirmation } = useCurrentConfirmation(); const t = useI18nContext(); const securityAlertResponse = @@ -28,7 +29,7 @@ const usePersonalSignAlerts = (): Alert[] => { ); const alerts = useMemo<Alert[]>(() => { - if (currentConfirmation?.type !== ApprovalType.PersonalSign) { + if (!isSignatureTransactionType(currentConfirmation)) { return []; } @@ -41,10 +42,10 @@ const usePersonalSignAlerts = (): Alert[] => { return []; } - return [providerAlertNormalizer(signatureSecurityAlertResponse, t)]; + return [normalizeProviderAlert(signatureSecurityAlertResponse, t)]; }, [currentConfirmation, signatureSecurityAlertResponse]); return alerts; }; -export default usePersonalSignAlerts; +export default useBlockaidAlerts; diff --git a/ui/pages/confirmations/hooks/alerts/utils.test.ts b/ui/pages/confirmations/hooks/alerts/utils.test.ts index 03e23b8e0a86..4499d5a8361a 100644 --- a/ui/pages/confirmations/hooks/alerts/utils.test.ts +++ b/ui/pages/confirmations/hooks/alerts/utils.test.ts @@ -1,7 +1,7 @@ import { SecurityAlertResponse } from '../../types/confirm'; import { BlockaidResultType } from '../../../../../shared/constants/security-provider'; import { Severity } from '../../../../helpers/constants/design-system'; -import { getProviderAlertSeverity, providerAlertNormalizer } from './utils'; +import { getProviderAlertSeverity, normalizeProviderAlert } from './utils'; describe('Utils', () => { describe('getProviderAlertSeverity', () => { @@ -16,7 +16,7 @@ describe('Utils', () => { }); }); - describe('providerAlertNormalizer', () => { + describe('normalizeProviderAlert', () => { const mockT = jest.fn((key) => key); const mockResponse: SecurityAlertResponse = { @@ -27,7 +27,7 @@ describe('Utils', () => { }; it('normalizes a security alert response correctly', () => { - const normalizedAlert = providerAlertNormalizer(mockResponse, mockT); + const normalizedAlert = normalizeProviderAlert(mockResponse, mockT); expect(normalizedAlert.key).toBe('test-id'); expect(normalizedAlert.reason).toBe('blockaidTitleDeceptive'); expect(normalizedAlert.severity).toBe(Severity.Danger); diff --git a/ui/pages/confirmations/hooks/alerts/utils.ts b/ui/pages/confirmations/hooks/alerts/utils.ts index 1bf655a553b5..6c88008a2a7c 100644 --- a/ui/pages/confirmations/hooks/alerts/utils.ts +++ b/ui/pages/confirmations/hooks/alerts/utils.ts @@ -40,7 +40,7 @@ export function getProviderAlertSeverity( * @param t - The translation function. * @returns The normalized Alert object. */ -export function providerAlertNormalizer( +export function normalizeProviderAlert( securityAlertResponse: SecurityAlertResponse, t: ReturnType<typeof useI18nContext>, ): Alert { diff --git a/ui/pages/confirmations/hooks/useConfirmationAlerts.test.ts b/ui/pages/confirmations/hooks/useConfirmationAlerts.test.ts index 9314db1c9c22..6ab4c240eca9 100644 --- a/ui/pages/confirmations/hooks/useConfirmationAlerts.test.ts +++ b/ui/pages/confirmations/hooks/useConfirmationAlerts.test.ts @@ -1,17 +1,17 @@ import { renderHook } from '@testing-library/react-hooks'; -import usePersonalSignAlerts from './alerts/usePersonalSignAlerts'; +import useBlockaidAlert from './alerts/useBlockaidAlert'; import useConfirmationAlerts from './useConfirmationAlerts'; -jest.mock('./alerts/usePersonalSignAlerts', () => jest.fn()); +jest.mock('./alerts/useBlockaidAlert', () => jest.fn()); describe('useConfirmationAlerts', () => { - describe('usePersonalSignAlerts', () => { + describe('useBlockaidAlert', () => { it('returns an array of alerts', () => { const personalSignAlerts = [ { key: '1', message: 'Alert 1' }, { key: '2', message: 'Alert 2' }, ]; - (usePersonalSignAlerts as jest.Mock).mockReturnValue(personalSignAlerts); + (useBlockaidAlert as jest.Mock).mockReturnValue(personalSignAlerts); const { result } = renderHook(() => useConfirmationAlerts()); @@ -19,7 +19,7 @@ describe('useConfirmationAlerts', () => { }); it('returns an empty array when there are no alerts', () => { - (usePersonalSignAlerts as jest.Mock).mockReturnValue([]); + (useBlockaidAlert as jest.Mock).mockReturnValue([]); const { result } = renderHook(() => useConfirmationAlerts()); diff --git a/ui/pages/confirmations/hooks/useConfirmationAlerts.ts b/ui/pages/confirmations/hooks/useConfirmationAlerts.ts index fcbc7eefef77..471c00c12d41 100644 --- a/ui/pages/confirmations/hooks/useConfirmationAlerts.ts +++ b/ui/pages/confirmations/hooks/useConfirmationAlerts.ts @@ -1,10 +1,10 @@ import { useMemo } from 'react'; -import usePersonalSignAlerts from './alerts/usePersonalSignAlerts'; +import useBlockaidAlerts from './alerts/useBlockaidAlert'; const useConfirmationAlerts = () => { - const personalSignAlerts = usePersonalSignAlerts(); + const blockaidAlerts = useBlockaidAlerts(); - return useMemo(() => [...personalSignAlerts], [personalSignAlerts]); + return useMemo(() => [...blockaidAlerts], [blockaidAlerts]); }; export default useConfirmationAlerts; diff --git a/ui/pages/confirmations/hooks/useSignatureSecurityAlertResponse.ts b/ui/pages/confirmations/hooks/useSignatureSecurityAlertResponse.ts deleted file mode 100644 index 03692a76d14c..000000000000 --- a/ui/pages/confirmations/hooks/useSignatureSecurityAlertResponse.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { useSelector } from 'react-redux'; -import { SecurityAlertResponse } from '../types/confirm'; - -type SignatureSecurityAlertResponsesState = { - metamask: { - signatureSecurityAlertResponses: Record<string, SecurityAlertResponse>; - }; -}; - -/** - * @param securityAlertId - * @deprecated This file should be deprecated when we introduce the alerts system logic - * @see {@link https://github.com/MetaMask/MetaMask-planning/issues/2412} - */ -function useSignatureSecurityAlertResponse(securityAlertId?: string) { - const signatureSecurityAlertResponses = useSelector( - (state: SignatureSecurityAlertResponsesState) => - state.metamask.signatureSecurityAlertResponses, - ); - - return securityAlertId - ? signatureSecurityAlertResponses?.[securityAlertId] - : null; -} - -export default useSignatureSecurityAlertResponse; diff --git a/ui/pages/confirmations/utils/confirm.test.ts b/ui/pages/confirmations/utils/confirm.test.ts index 235a82d4e0ad..5b9ba56b9e83 100644 --- a/ui/pages/confirmations/utils/confirm.test.ts +++ b/ui/pages/confirmations/utils/confirm.test.ts @@ -1,7 +1,11 @@ import { ApprovalRequest } from '@metamask/approval-controller'; import { ApprovalType } from '@metamask/controller-utils'; +import { TransactionType } from '@metamask/transaction-controller'; -import { isSignatureApprovalRequest } from './confirm'; +import { + isSignatureApprovalRequest, + isSignatureTransactionType, +} from './confirm'; describe('confirm util', () => { describe('isSignatureApprovalRequest', () => { @@ -22,4 +26,19 @@ describe('confirm util', () => { expect(result).toStrictEqual(false); }); }); + + describe('isSignatureTransactionType', () => { + it('returns true for signature transaction requests', () => { + const result = isSignatureTransactionType({ + type: TransactionType.personalSign, + }); + expect(result).toStrictEqual(true); + }); + it('returns false for request not of type signature', () => { + const result = isSignatureTransactionType({ + type: TransactionType.contractInteraction, + }); + expect(result).toStrictEqual(false); + }); + }); }); diff --git a/ui/pages/confirmations/utils/confirm.ts b/ui/pages/confirmations/utils/confirm.ts index 88f62493a757..bb5c0f192f39 100644 --- a/ui/pages/confirmations/utils/confirm.ts +++ b/ui/pages/confirmations/utils/confirm.ts @@ -27,6 +27,15 @@ export const isSignatureApprovalRequest = ( request: ApprovalRequest<Record<string, Json>>, ) => SIGNATURE_APPROVAL_TYPES.includes(request.type as ApprovalType); +const SIGNATURE_TRANSACTION_TYPES = [ + TransactionType.personalSign, + TransactionType.signTypedData, +]; + +export const isSignatureTransactionType = (request?: Record<string, unknown>) => + request && + SIGNATURE_TRANSACTION_TYPES.includes(request.type as TransactionType); + export const parseTypedDataMessage = (dataToParse: string) => { const { message, domain = {}, primaryType, types } = JSON.parse(dataToParse); const sanitizedMessage = sanitizeMessage(message, primaryType, types);