diff --git a/app/components/Nav/Main/MainNavigator.js b/app/components/Nav/Main/MainNavigator.js index d979dd1ce8b..2597a478fbf 100644 --- a/app/components/Nav/Main/MainNavigator.js +++ b/app/components/Nav/Main/MainNavigator.js @@ -14,13 +14,11 @@ import SecuritySettings from '../../Views/Settings/SecuritySettings'; import ExperimentalSettings from '../../Views/Settings/ExperimentalSettings'; import NetworksSettings from '../../Views/Settings/NetworksSettings'; import NotificationsSettings from '../../Views/Settings/NotificationsSettings'; -import NotificationsDetails from '../../Views/Notifications/Details'; import OptIn from '../../Views/Notifications/OptIn'; import AppInformation from '../../Views/Settings/AppInformation'; import Contacts from '../../Views/Settings/Contacts'; import Wallet from '../../Views/Wallet'; import Asset from '../../Views/Asset'; -import NotificationsView from '../../Views/Notifications'; import AssetDetails from '../../Views/AssetDetails'; import AddAsset from '../../Views/AddAsset'; import Collectible from '../../Views/Collectible'; @@ -600,22 +598,11 @@ const PaymentRequestView = () => ( /* eslint-disable react/prop-types */ const NotificationsModeView = (props) => ( - - - - - - -`; diff --git a/app/components/UI/Notification/List/index.test.tsx b/app/components/UI/Notification/List/index.test.tsx deleted file mode 100644 index 76dbc482957..00000000000 --- a/app/components/UI/Notification/List/index.test.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import React from 'react'; -import NotificationsList from './'; -import renderWithProvider from '../../../../util/test/renderWithProvider'; -import MOCK_NOTIFICATIONS from '../__mocks__/mock_notifications'; -import { - FeatureAnnouncementRawNotification, - HalRawNotification, -} from '../../../../util/notifications'; -const navigationMock = { - navigate: jest.fn(), -}; -describe('NotificationsList', () => { - it('should render correctly', () => { - const { toJSON } = renderWithProvider( - , - ); - expect(toJSON()).toMatchSnapshot(); - }); -}); diff --git a/app/components/UI/Notification/List/index.tsx b/app/components/UI/Notification/List/index.tsx deleted file mode 100644 index dd5676ad02c..00000000000 --- a/app/components/UI/Notification/List/index.tsx +++ /dev/null @@ -1,175 +0,0 @@ -import React, { useCallback, useMemo } from 'react'; -import { ActivityIndicator, FlatList, View } from 'react-native'; -import ScrollableTabView, { - DefaultTabBar, -} from 'react-native-scrollable-tab-view'; -import { strings } from '../../../../../locales/i18n'; -import { MetaMetricsEvents } from '../../../../core/Analytics'; - -import { useTheme } from '../../../../util/theme'; -import { createStyles } from './styles'; -import { useMetrics } from '../../../hooks/useMetrics'; -import Empty from '../Empty'; -import { NotificationRow } from '../Row'; -import { - FeatureAnnouncementRawNotification, - HalRawNotification, - Notification, - getRowDetails, -} from '../../../../util/notifications'; -import { NotificationsViewSelectorsIDs } from '../../../../../e2e/selectors/NotificationsView.selectors'; - -interface NotificationsList { - // TODO: Replace "any" with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - navigation: any; - allNotifications: Notification[]; - walletNotifications: HalRawNotification[]; - annoucementsNotifications: FeatureAnnouncementRawNotification[]; - loading: boolean; -} - -const Notifications = ({ - navigation, - allNotifications, - walletNotifications, - annoucementsNotifications, - loading, -}: NotificationsList) => { - const theme = useTheme(); - const { colors } = theme; - const styles = createStyles(theme); - const { trackEvent } = useMetrics(); - - const onPress = useCallback( - (item) => { - //TODO: details will be implemented on a separete PR - navigation.navigate('NotificationsDetails', { notification: item }); - }, - [navigation], - ); - - const renderTabBar = useCallback( - (props) => ( - - - - ), - [styles, colors], - ); - - const onChangeTab = useCallback( - (obj) => { - switch (obj.ref.props.tabLabel) { - case strings('notifications.all'): - trackEvent(MetaMetricsEvents.ALL_NOTIFICATIONS); - break; - case strings('notifications.wallet'): - trackEvent(MetaMetricsEvents.WALLET_NOTIFICATIONS); - break; - case strings('notifications.web3'): - trackEvent(MetaMetricsEvents.ANNOUCEMENTS_NOTIFICATIONS); - break; - default: - break; - } - }, - [trackEvent], - ); - - const combinedLists = useMemo( - () => [allNotifications, walletNotifications, annoucementsNotifications], - [allNotifications, walletNotifications, annoucementsNotifications], - ); - - const renderNotificationRow = useCallback( - (notification) => { - const hasActions = - !!notification.data?.link || !!notification.data?.action; - const { title, description, badgeIcon, createdAt, imageUrl, value } = - getRowDetails(notification)?.row || {}; - return ( - onPress(notification)} - styles={styles} - > - - - {hasActions && ( - - )} - - ); - }, - [onPress, styles], - ); - - const renderList = useCallback( - (list, idx) => ( - index.toString()} - key={combinedLists.indexOf(list)} - data={list} - ListEmptyComponent={ - - } - contentContainerStyle={styles.list} - renderItem={({ item }) => renderNotificationRow(item)} - initialNumToRender={10} - maxToRenderPerBatch={2} - onEndReachedThreshold={0.5} - /> - ), - [combinedLists, renderNotificationRow, styles.list], - ); - - return ( - - {loading ? ( - - - - ) : ( - - {combinedLists.map((list, idx) => renderList(list, idx))} - - )} - - ); -}; - -export default Notifications; diff --git a/app/components/UI/Notification/List/styles.ts b/app/components/UI/Notification/List/styles.ts deleted file mode 100644 index 672c5acedad..00000000000 --- a/app/components/UI/Notification/List/styles.ts +++ /dev/null @@ -1,141 +0,0 @@ -/* eslint-disable import/prefer-default-export */ -import { StyleSheet, TextStyle } from 'react-native'; -import type { Theme } from '@metamask/design-tokens'; - -export const createStyles = ({ colors, typography }: Theme) => - StyleSheet.create({ - container: { - flex: 1, - backgroundColor: colors.background.default, - }, - wrapper: { - flex: 1, - paddingHorizontal: 16, - paddingVertical: 10, - justifyContent: 'center', - borderRadius: 10, - }, - loaderContainer: { - position: 'absolute', - zIndex: 999, - width: '100%', - height: '100%', - }, - base: { - paddingHorizontal: 16, - }, - tabUnderlineStyle: { - height: 2, - backgroundColor: colors.primary.default, - }, - tabStyle: { - paddingBottom: 0, - paddingVertical: 8, - }, - tabBar: { - borderColor: colors.background.default, - }, - textStyle: { - ...(typography.sBodyMD as TextStyle), - fontWeight: '500', - }, - loader: { - backgroundColor: colors.background.default, - flex: 1, - justifyContent: 'center', - alignItems: 'center', - }, - TabWrapper: { - backgroundColor: colors.background.default, - flex: 1, - }, - list: { flexGrow: 1 }, - fox: { - width: 20, - height: 20, - }, - badgeWrapper: { - alignItems: 'center', - justifyContent: 'center', - alignSelf: 'flex-start', - position: 'absolute', - top: '10%', - }, - assetLogo: { - width: 32, - height: 32, - borderRadius: 16, - overflow: 'hidden', - borderWidth: 0.5, - borderColor: colors.background.alternative, - }, - assetPlaceholder: { - backgroundColor: colors.background.alternative, - width: 32, - height: 32, - borderRadius: 16, - borderWidth: 0.5, - borderColor: colors.background.alternative, - }, - nftLogo: { - width: 32, - height: 32, - borderRadius: 8, - overflow: 'hidden', - borderWidth: 0.5, - borderColor: colors.background.alternative, - }, - nftPlaceholder: { - backgroundColor: colors.background.alternative, - width: 32, - height: 32, - borderRadius: 8, - borderWidth: 0.5, - borderColor: colors.background.alternative, - }, - rowContainer: { flex: 1, marginLeft: 42, alignItem: 'center' }, - rowInsider: { - flex: 1, - flexDirection: 'row', - justifyContent: 'space-between', - }, - ethLogo: { - width: 32, - height: 32, - borderRadius: 16, - }, - foxWrapper: { - width: 32, - height: 32, - borderRadius: 16, - backgroundColor: colors.background.alternative, - alignItems: 'center', - justifyContent: 'center', - alignSelf: 'flex-start', - position: 'absolute', - top: '25%', - }, - textBox: { - flexShrink: 1, - maxWidth: '85%', - }, - button: { - marginTop: 16, - width: '100%', - alignSelf: 'center', - }, - trashIconContainer: { - position: 'absolute', - paddingHorizontal: 24, - flex: 1, - flexDirection: 'row', - backgroundColor: colors.background.hover, - justifyContent: 'flex-end', - alignItems: 'center', - overflow: 'hidden', - height: '100%', - right: 0, - left: 0, - zIndex: -1, - }, - }); diff --git a/app/components/UI/Notification/Row/Actions.test.tsx b/app/components/UI/Notification/Row/Actions.test.tsx deleted file mode 100644 index 596523d7cdd..00000000000 --- a/app/components/UI/Notification/Row/Actions.test.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import React from 'react'; -import { Linking } from 'react-native'; -import { fireEvent } from '@testing-library/react-native'; - -import renderWithProvider from '../../../../util/test/renderWithProvider'; - -import NotificationActions from './Actions'; -import { ACTIONS, PREFIXES } from '../../../../constants/deeplinks'; -import { NOTIFICATION_TEST_ID_TYPES } from './constants'; - -Linking.openURL = jest.fn(() => Promise.resolve('opened https://metamask.io!')); - -describe('NotificationActions', () => { - const styles = { - button: {}, - }; - const action = { - actionText: 'Send now!', - actionUrl: PREFIXES[ACTIONS.SEND], - isExternal: false, - }; - const link = { - linkText: 'Learn more', - linkUrl: 'https://metamask.io', - isExternal: true, - }; - - it('matches snapshot', () => { - const { toJSON } = renderWithProvider( - , - ); - expect(toJSON()).toMatchSnapshot(); - }); - - it('matches snapshot with LINK only', () => { - const { toJSON } = renderWithProvider( - , - ); - expect(toJSON()).toMatchSnapshot(); - }); - - it('renders link title', () => { - const { getByText } = renderWithProvider( - , - ); - - expect(getByText('Learn more')).toBeTruthy(); - }); - - it('calls Linking.openURL when link CTA is clicked', async () => { - const { getByTestId } = renderWithProvider( - , - ); - - fireEvent.press( - getByTestId(NOTIFICATION_TEST_ID_TYPES.NOTIFICATION_ACTION_BUTTON), - ); - expect(Linking.openURL).toHaveBeenCalledTimes(1); - }); -}); diff --git a/app/components/UI/Notification/Row/Actions.tsx b/app/components/UI/Notification/Row/Actions.tsx deleted file mode 100644 index fa286dcdb5f..00000000000 --- a/app/components/UI/Notification/Row/Actions.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import React from 'react'; -import { Linking } from 'react-native'; -import Button, { - ButtonVariants, -} from '../../../../component-library/components/Buttons/Button'; -import { IconName } from '../../../../component-library/components/Icons/Icon'; -import { NOTIFICATION_TEST_ID_TYPES } from './constants'; - -interface NotificationActionsProps { - link?: { - linkText: string; - linkUrl: string; - isExternal: boolean; - }; - action?: { - actionText: string; - actionUrl: string; - isExternal: boolean; - }; - // TODO: Replace "any" with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - styles: any; -} - -function NotificationActions({ - action, - link, - styles, -}: NotificationActionsProps) { - function handleCTAPress() { - if (link?.linkUrl) { - return Linking.openURL(link.linkUrl); - } - } - - return ( -