-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add notifications actions selectors - 4/7 (#10338)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This PR implements Actions, Selections, and utils for the upcoming Notifications feature. No UI change is presented on this PR. ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] 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.
- Loading branch information
1 parent
3cdd6de
commit 2f69e5f
Showing
13 changed files
with
726 additions
and
1,202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export enum notificationsErrors { | ||
PERFORM_SIGN_IN = 'Error while trying to sign in', | ||
PERFORM_SIGN_OUT = 'Error while trying to sign out', | ||
ENABLE_PROFILE_SYNCING = 'Error while trying to enable profile syncing', | ||
DISABLE_PROFILE_SYNCING = 'Error while trying to disable profile syncing', | ||
ENABLE_PUSH_NOTIFICATIONS = 'Error while trying to enable push notifications', | ||
DISABLE_PUSH_NOTIFICATIONS = 'Error while trying to disable push notifications', | ||
CHECK_ACCOUNTS_PRESENCE = 'Error while trying to check accounts presence', | ||
DELETE_ON_CHAIN_TRIGGERS_BY_ACCOUNT = 'Error while trying to delete on chain triggers by account', | ||
UPDATE_ON_CHAIN_TRIGGERS_BY_ACCOUNT = 'Error while trying to update on chain triggers by account', | ||
SET_FEATURE_ANNOUNCEMENTS_ENABLED = 'Error while trying to set feature announcements enabled', | ||
SET_SNAP_NOTIFICATIONS_ENABLED = 'Error while trying to set snap notifications enabled', | ||
SET_METAMASK_NOTIFICATIONS_FEATURE_SEEN = 'Error while trying to set metamask notifications feature seen', | ||
FETCH_AND_UPDATE_METAMASK_NOTIFICATIONS = 'Error while trying to fetch and update metamask notifications', | ||
MARK_METAMASK_NOTIFICATIONS_AS_READ = 'Error while trying to mark metamask notifications as read', | ||
DELETE_NOTIFICATION_STATUS = 'Error while trying to delete notification', | ||
SET_PARTICIPATE_IN_META_METRICS = 'Error while trying to set participate in meta metrics', | ||
UPDATE_TRIGGER_PUSH_NOTIFICATIONS = 'Error while trying to update trigger push notifications', | ||
ENABLE_NOTIFICATIONS_SERVICES = 'Error while trying to enable notifications services', | ||
DISABLE_NOTIFICATIONS_SERVICES = 'Error while trying to disable notifications services', | ||
} | ||
|
||
export default notificationsErrors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import { getErrorMessage } from '@metamask/utils'; | ||
|
||
import { notificationsErrors } from '../constants'; | ||
import Engine from '../../../core/Engine'; | ||
import { Notification } from '../../../util/notifications'; | ||
|
||
const { | ||
AuthenticationController, | ||
UserStorageController, | ||
NotificationServicesController, | ||
} = Engine.context; | ||
|
||
type MarkAsReadNotificationsParam = Pick< | ||
Notification, | ||
'id' | 'type' | 'isRead' | ||
>[]; | ||
|
||
export const signIn = async () => { | ||
try { | ||
const accessToken = await AuthenticationController.performSignIn(); | ||
if (!accessToken) { | ||
return getErrorMessage(notificationsErrors.PERFORM_SIGN_IN); | ||
} | ||
|
||
const profile = await AuthenticationController.getSessionProfile(); | ||
if (!profile) { | ||
return getErrorMessage(notificationsErrors.PERFORM_SIGN_IN); | ||
} | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const signOut = async () => { | ||
try { | ||
await AuthenticationController.performSignOut(); | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const enableProfileSyncing = async () => { | ||
try { | ||
await UserStorageController.enableProfileSyncing(); | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const disableProfileSyncing = async () => { | ||
try { | ||
await NotificationServicesController.disableNotificationServices(); | ||
await UserStorageController.disableProfileSyncing(); | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const enableNotificationServices = async () => { | ||
try { | ||
await NotificationServicesController.enableMetamaskNotifications(); | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const disableNotificationServices = async () => { | ||
try { | ||
await NotificationServicesController.disableNotificationServices(); | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const checkAccountsPresence = async (accounts: string[]) => { | ||
try { | ||
const { presence } = | ||
await NotificationServicesController.checkAccountsPresence(accounts); | ||
if (!presence) { | ||
return getErrorMessage(notificationsErrors.CHECK_ACCOUNTS_PRESENCE); | ||
} | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const deleteOnChainTriggersByAccount = async (accounts: string[]) => { | ||
try { | ||
const { userStorage } = | ||
await NotificationServicesController.deleteOnChainTriggersByAccount( | ||
accounts, | ||
); | ||
if (!userStorage) { | ||
return getErrorMessage( | ||
notificationsErrors.DELETE_ON_CHAIN_TRIGGERS_BY_ACCOUNT, | ||
); | ||
} | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const updateOnChainTriggersByAccount = async (accounts: string[]) => { | ||
try { | ||
const { userStorage } = | ||
await NotificationServicesController.updateOnChainTriggersByAccount( | ||
accounts, | ||
); | ||
if (!userStorage) { | ||
return getErrorMessage( | ||
notificationsErrors.UPDATE_ON_CHAIN_TRIGGERS_BY_ACCOUNT, | ||
); | ||
} | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const setFeatureAnnouncementsEnabled = async ( | ||
featureAnnouncementsEnabled: boolean, | ||
) => { | ||
try { | ||
await NotificationServicesController.setFeatureAnnouncementsEnabled( | ||
featureAnnouncementsEnabled, | ||
); | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const fetchAndUpdateMetamaskNotifications = async () => { | ||
try { | ||
const metamaskNotifications = | ||
await NotificationServicesController.fetchAndUpdateMetamaskNotifications(); | ||
if (!metamaskNotifications) { | ||
return getErrorMessage( | ||
notificationsErrors.FETCH_AND_UPDATE_METAMASK_NOTIFICATIONS, | ||
); | ||
} | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const markMetamaskNotificationsAsRead = async ( | ||
notifications: MarkAsReadNotificationsParam, | ||
) => { | ||
try { | ||
await NotificationServicesController.markMetamaskNotificationsAsRead( | ||
notifications, | ||
); | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.