Skip to content

Commit

Permalink
Merge branch 'develop' into NOTIFY-709-hotfix-basic-functionality-swi…
Browse files Browse the repository at this point in the history
…tch-breaks-e2e-tests
  • Loading branch information
danjm authored May 30, 2024
2 parents 8849db9 + e4bf8b3 commit 279852c
Show file tree
Hide file tree
Showing 37 changed files with 208 additions and 263 deletions.
3 changes: 0 additions & 3 deletions app/_locales/de/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/el/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/es/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/fr/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/hi/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/id/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/ja/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/ko/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/pt/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/ru/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/tl/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/tr/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/vi/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions app/_locales/zh_CN/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('AlertModal', () => {
},
});

useAlertsSpy.mockReturnValue({
(useAlertsSpy as jest.Mock).mockReturnValue({
setAlertConfirmed: setAlertConfirmedMock,
alerts: [alertsMock[1]],
generalAlerts: [],
Expand Down
25 changes: 16 additions & 9 deletions ui/components/app/alert-system/alert-modal/alert-modal.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -133,6 +135,11 @@ function AlertHeader({
);
}

function BlockaidAlertDetails() {
const t = useI18nContext();
return <Text textAlign={TextAlign.Center}>{t('blockaidAlertInfo')}</Text>;
}

function AlertDetails({
selectedAlert,
customDetails,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -311,10 +314,14 @@ export function AlertModal({
/>
<AlertHeader selectedAlert={selectedAlert} customTitle={customTitle} />
<ModalBody>
<AlertDetails
selectedAlert={selectedAlert}
customDetails={customDetails}
/>
{selectedAlert?.provider === SecurityProvider.Blockaid ? (
<BlockaidAlertDetails />
) : (
<AlertDetails
selectedAlert={selectedAlert}
customDetails={customDetails}
/>
)}
{customAcknowledgeCheckbox ?? (
<AcknowledgeCheckboxBase
selectedAlert={selectedAlert}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,37 +93,41 @@ describe('ConfirmAlertModal', () => {
expect(onSubmitMock).toHaveBeenCalledTimes(1);
});

it('calls open multiple alert modal when review alerts link is clicked', () => {
const { getByTestId } = renderWithProvider(
<ConfirmAlertModal {...defaultProps} />,
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(
// <ConfirmAlertModal {...defaultProps} />,
// 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(
<ConfirmAlertModal {...defaultProps} />,
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(
// <ConfirmAlertModal {...defaultProps} />,
// mockStoreAcknowledgeAlerts,
// );
// fireEvent.click(getByTestId('confirm-alert-modal-review-all-alerts'));
// fireEvent.click(getByTestId('alert-modal-button'));

// expect(getByText(DATA_ALERT_MESSAGE_MOCK)).toBeInTheDocument();
// });
// });
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { useCallback, useState } from 'react';

import { SecurityProvider } from '../../../../../shared/constants/security-provider';
import {
Box,
Button,
Expand All @@ -13,7 +15,6 @@ import {
} from '../../../component-library';
import {
AlignItems,
Severity,
TextAlign,
TextVariant,
} from '../../../../helpers/constants/design-system';
Expand All @@ -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. */
Expand Down Expand Up @@ -56,7 +56,7 @@ function ConfirmButtons({
variant={ButtonVariant.Secondary}
data-testid="confirm-alert-modal-cancel-button"
>
{t('cancel')}
{t('reject')}
</Button>
<Button
variant={ButtonVariant.Primary}
Expand Down Expand Up @@ -119,21 +119,14 @@ export function ConfirmAlertModal({
ownerId,
}: ConfirmAlertModalProps) {
const t = useI18nContext();
const { isAlertConfirmed, fieldAlerts } = useAlerts(ownerId);
const { alerts, unconfirmedDangerAlerts } = useAlerts(ownerId);

const unconfirmedDangerAlerts = fieldAlerts.filter(
(alert: Alert) =>
!isAlertConfirmed(alert.key) && alert.severity === Severity.Danger,
);
const selectedAlert = fieldAlerts.find(
(alert: Alert) => alert.key === alertKey,
);
const hasUnconfirmedDangerAlerts = unconfirmedDangerAlerts.length > 0;
const selectedAlert = alerts.find((alert) => alert.key === alertKey);

const [confirmCheckbox, setConfirmCheckbox] = useState<boolean>(false);
// if there are multiple alerts, show the multiple alert modal
const [multipleAlertModalVisible, setMultipleAlertModalVisible] =
useState<boolean>(hasUnconfirmedDangerAlerts);
useState<boolean>(unconfirmedDangerAlerts.length > 1);

const handleCloseMultipleAlertModal = useCallback(() => {
setMultipleAlertModalVisible(false);
Expand Down Expand Up @@ -170,14 +163,22 @@ export function ConfirmAlertModal({
onClose={onClose}
customTitle={t('confirmAlertModalTitle')}
customDetails={
<ConfirmDetails onAlertLinkClick={handleOpenMultipleAlertModal} />
selectedAlert?.provider === SecurityProvider.Blockaid ? (
SecurityProvider.Blockaid
) : (
<ConfirmDetails onAlertLinkClick={handleOpenMultipleAlertModal} />
)
}
customAcknowledgeCheckbox={
<AcknowledgeCheckboxBase
selectedAlert={selectedAlert}
isConfirmed={confirmCheckbox}
onCheckboxClick={handleConfirmCheckbox}
label={t('confirmAlertModalAcknowledge')}
label={
selectedAlert?.provider === SecurityProvider.Blockaid
? t('confirmAlertModalAcknowledgeBlockaid')
: t('confirmAlertModalAcknowledge')
}
/>
}
customAcknowledgeButton={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function MultipleAlertModal({
onFinalAcknowledgeClick,
ownerId,
}: MultipleAlertModalProps) {
const { isAlertConfirmed, fieldAlerts: alerts } = useAlerts(ownerId);
const { isAlertConfirmed, alerts } = useAlerts(ownerId);

const [selectedIndex, setSelectedIndex] = useState(
alerts.findIndex((alert: Alert) => alert.key === alertKey),
Expand Down
Loading

0 comments on commit 279852c

Please sign in to comment.