Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions app/actions/notification/helpers/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
fetchAccountNotificationSettings,
disableAccounts,
enableAccounts,
resetNotifications,
toggleFeatureAnnouncements,
fetchNotifications,
markNotificationsAsRead,
enablePushNotifications,
disablePushNotifications,
hasNotificationPreferences,
type setContentPreviewToken as setContentPreviewTokenFn,
type getContentPreviewToken as getContentPreviewTokenFn,
type subscribeToContentPreviewToken as subscribeToContentPreviewTokenFn,
Expand Down Expand Up @@ -38,15 +38,55 @@ jest.mock('../../../core/Engine', () => ({
disablePushNotifications: jest.fn(),
},
},
controllerMessenger: {
call: jest.fn(),
},
}));

beforeEach(() => {
jest.clearAllMocks();
});

describe('helpers - enableNotificationServices()', () => {
it('invoke notification services method', async () => {
await enableNotifications();
expect(
Engine.context.NotificationServicesController.enableMetamaskNotifications,
).toHaveBeenCalled();
});

it('passes marketing consent to notification services method', async () => {
const options = { hasMarketingConsent: true };

await enableNotifications(options);

expect(
Engine.context.NotificationServicesController.enableMetamaskNotifications,
).toHaveBeenCalledWith(options);
});
});

describe('helpers - hasNotificationPreferences()', () => {
it('returns true when AUS preferences exist', async () => {
jest.mocked(Engine.controllerMessenger.call).mockResolvedValue({
walletActivity: {
inAppNotificationsEnabled: true,
pushNotificationsEnabled: true,
accounts: [],
},
});

await expect(hasNotificationPreferences()).resolves.toBe(true);
expect(Engine.controllerMessenger.call).toHaveBeenCalledWith(
'AuthenticatedUserStorageService:getNotificationPreferences',
);
});

it('returns false when AUS preferences are missing', async () => {
jest.mocked(Engine.controllerMessenger.call).mockResolvedValue(null);

await expect(hasNotificationPreferences()).resolves.toBe(false);
});
});

describe('helpers - disableNotificationServices()', () => {
Expand Down Expand Up @@ -88,15 +128,6 @@ describe('helpers - enableAccounts()', () => {
});
});

describe('helpers - createOnChainTriggersByAccount()', () => {
it('invoke notification services method', async () => {
await resetNotifications();
expect(
Engine.context.NotificationServicesController.createOnChainTriggers,
).toHaveBeenCalled();
});
});

describe('helpers - setFeatureAnnouncementsEnabled()', () => {
it('invoke notification services method', async () => {
await toggleFeatureAnnouncements(true);
Expand Down
37 changes: 22 additions & 15 deletions app/actions/notification/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import EventEmitter2 from 'eventemitter2';
import type { MarkAsReadNotificationsParam } from '@metamask/notification-services-controller/notification-services';
import type {
MarkAsReadNotificationsParam,
NotificationServicesControllerEnableNotificationsOptions,
} from '@metamask/notification-services-controller/notification-services';
import Engine from '../../../core/Engine';
import { isNotificationsFeatureEnabled } from '../../../util/notifications';

Expand Down Expand Up @@ -38,9 +41,25 @@ export const assertIsFeatureEnabled = () => {
* - This is used during onboarding and for the notifications settings toggle
* - Enables wallet notifications, feature announcements, and push notifications
*/
export const enableNotifications = async () => {
export const enableNotifications = async (
options?: NotificationServicesControllerEnableNotificationsOptions,
) => {
assertIsFeatureEnabled();
await Engine.context.NotificationServicesController.enableMetamaskNotifications();
await Engine.context.NotificationServicesController.enableMetamaskNotifications(
options,
);
};

/**
* Checks whether the authenticated user storage already has notification preferences.
* A missing AUS row is returned as `null` by the service.
*/
export const hasNotificationPreferences = async () => {
assertIsFeatureEnabled();
const preferences = await Engine.controllerMessenger.call(
'AuthenticatedUserStorageService:getNotificationPreferences',
);
return preferences != null;
};

/**
Expand Down Expand Up @@ -147,15 +166,3 @@ export const markNotificationsAsRead = async (
notifications,
);
};

/**
* Developer options/User toggle to reset notifications
* (in case their UserStorage or notifications become corrupt)
* @throws if there is an error resetting notifications
*/
export const resetNotifications = async () => {
assertIsFeatureEnabled();
await Engine.context.NotificationServicesController.createOnChainTriggers({
resetNotifications: true,
});
};
34 changes: 21 additions & 13 deletions app/components/Nav/Main/MainNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import NetworksManagementView from '../../Views/NetworksManagement/NetworksManag
import NetworkDetailsView from '../../Views/NetworksManagement/NetworkDetailsView';
import ExperimentalSettings from '../../Views/Settings/ExperimentalSettings';
import NotificationsSettings from '../../Views/Settings/NotificationsSettings';
import NotificationSettingsSection from '../../Views/Settings/NotificationsSettings/NotificationSettingsSection';
import RegionSelector from '../../UI/Ramp/Views/Settings/RegionSelector/RegionSelector';
import NotificationsView from '../../Views/Notifications';
import NotificationsDetails from '../../Views/Notifications/Details';
Expand Down Expand Up @@ -127,7 +128,6 @@ import {
TopTradersView,
TraderProfileView,
TraderPositionView,
NotificationPreferencesView,
} from '../../Views/SocialLeaderboard';
import { selectSocialLeaderboardEnabled } from '../../../selectors/featureFlagController/socialLeaderboard';
import PerpsPositionTransactionView from '../../UI/Perps/Views/PerpsTransactionsView/PerpsPositionTransactionView';
Expand Down Expand Up @@ -441,7 +441,12 @@ const NotificationsOptInStack = () => (
<Stack.Screen
name={Routes.SETTINGS.NOTIFICATIONS}
component={NotificationsSettings}
options={NotificationsSettings.navigationOptions}
options={{ headerShown: false }}
/>
<Stack.Screen
name={Routes.SETTINGS.NOTIFICATION_SETTINGS_SECTION}
component={NotificationSettingsSection}
options={{ headerShown: false }}
/>
</Stack.Navigator>
);
Expand Down Expand Up @@ -607,7 +612,12 @@ const SettingsFlow = () => {
<Stack.Screen
name={Routes.SETTINGS.NOTIFICATIONS}
component={NotificationsSettings}
options={NotificationsSettings.navigationOptions}
options={{ headerShown: false }}
/>
<Stack.Screen
name={Routes.SETTINGS.NOTIFICATION_SETTINGS_SECTION}
component={NotificationSettingsSection}
options={{ headerShown: false }}
/>
<Stack.Screen
name={Routes.SETTINGS.BACKUP_AND_SYNC}
Expand Down Expand Up @@ -946,16 +956,21 @@ const OfflineModeView = () => (

/* eslint-disable react/prop-types */
const NotificationsModeView = (props) => (
<Stack.Navigator>
<Stack.Navigator screenOptions={{ headerShown: true }}>
<Stack.Screen
name={Routes.NOTIFICATIONS.VIEW}
component={NotificationsView}
options={NotificationsView.navigationOptions}
options={{ headerShown: false }}
/>
<Stack.Screen
name={Routes.SETTINGS.NOTIFICATIONS}
component={NotificationsSettings}
options={NotificationsSettings.navigationOptions}
options={{ headerShown: false }}
/>
<Stack.Screen
name={Routes.SETTINGS.NOTIFICATION_SETTINGS_SECTION}
component={NotificationSettingsSection}
options={{ headerShown: false }}
/>
<Stack.Screen
name={Routes.NOTIFICATIONS.OPT_IN}
Expand Down Expand Up @@ -1357,13 +1372,6 @@ const MainNavigator = () => {
options={{ headerShown: false, ...slideFromRightAnimation }}
/>
)}
{isSocialLeaderboardEnabled && (
<Stack.Screen
name={Routes.SOCIAL_LEADERBOARD.NOTIFICATION_PREFERENCES}
component={NotificationPreferencesView}
options={{ headerShown: false, ...slideFromRightAnimation }}
/>
)}
<>
<Stack.Screen
name={Routes.EXPLORE_SEARCH}
Expand Down
112 changes: 0 additions & 112 deletions app/components/UI/SettingsNotification/index.js

This file was deleted.

30 changes: 0 additions & 30 deletions app/components/UI/SettingsNotification/index.test.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const NotificationMenuViewSelectorsText = {
export const NotificationMenuViewSelectorsIDs = {
TITLE: 'notification-menu-view-title',
COG_WHEEL: 'notification-menu-view-cog-wheel',
CLOSE_BUTTON: 'notification-menu-view-close-button',
ITEM: (id: string) => `notification-menu-view-item-${id}`,
ITEM_LIST_SCROLLVIEW: 'notification-menu-scroll-view',
};
Loading
Loading