Skip to content

Commit

Permalink
feat: add notifications controllers v2 - 3/7 (MetaMask#10332)
Browse files Browse the repository at this point in the history
<!--
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**

PR Chunk 3.

This adds the profile syncing and notifications controllers. This is not
yet tied to the UI, this just updates the Engine.ts to include these.


## **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
Jonathansoufer authored Jul 18, 2024
1 parent 97e3617 commit 0abb822
Show file tree
Hide file tree
Showing 11 changed files with 929 additions and 50 deletions.
5 changes: 5 additions & 0 deletions .android.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export MM_FOX_CODE="EXAMPLE_FOX_CODE"
export MM_BRANCH_KEY_TEST=
export MM_BRANCH_KEY_LIVE=
export METAMASK_BUILD_TYPE=
# Firebase
export FCM_CONFIG_API_KEY=
export FCM_CONFIG_AUTH_DOMAIN=
Expand All @@ -9,3 +10,7 @@ export FCM_CONFIG_STORAGE_BUCKET=
export FCM_CONFIG_MESSAGING_SENDER_ID=
export FCM_CONFIG_APP_ID=
export GOOGLE_SERVICES_B64=
#Notifications Feature Announcements
export FEATURES_ANNOUNCEMENTS_ACCESS_TOKEN=
export FEATURES_ANNOUNCEMENTS_SPACE_ID=

3 changes: 3 additions & 0 deletions .ios.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ FCM_CONFIG_STORAGE_BUCKET=
FCM_CONFIG_MESSAGING_SENDER_ID=
FCM_CONFIG_APP_ID=
GOOGLE_SERVICES_B64=
#Notifications Feature Announcements
FEATURES_ANNOUNCEMENTS_ACCESS_TOKEN=
FEATURES_ANNOUNCEMENTS_SPACE_ID=
3 changes: 3 additions & 0 deletions .js.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ export FCM_CONFIG_STORAGE_BUCKET=""
export FCM_CONFIG_MESSAGING_SENDER_ID=""
export FCM_CONFIG_APP_ID=""
export GOOGLE_SERVICES_B64=""
#Notifications Feature Announcements
export FEATURES_ANNOUNCEMENTS_ACCESS_TOKEN=
export FEATURES_ANNOUNCEMENTS_SPACE_ID=
3 changes: 3 additions & 0 deletions app/core/Engine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ describe('Engine', () => {
expect(engine.context).toHaveProperty('LoggingController');
expect(engine.context).toHaveProperty('TransactionController');
expect(engine.context).toHaveProperty('SmartTransactionsController');
expect(engine.context).toHaveProperty('AuthenticationController');
expect(engine.context).toHaveProperty('UserStorageController');
expect(engine.context).toHaveProperty('NotificationServicesController');
});

it('calling Engine.init twice returns the same instance', () => {
Expand Down
98 changes: 97 additions & 1 deletion app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ import {
DetectSnapLocationOptions,
} from './Snaps';
import { getRpcMethodMiddleware } from './RPCMethods/RPCMethodMiddleware';

import {
AuthenticationController,
UserStorageController,
} from '@metamask/profile-sync-controller';
import { NotificationServicesController } from '@metamask/notification-services-controller';
///: END:ONLY_INCLUDE_IF
import {
getCaveatSpecifications,
Expand Down Expand Up @@ -230,6 +236,10 @@ interface TestOrigin {
}

type PhishingControllerActions = MaybeUpdateState | TestOrigin;
type AuthenticationControllerActions = AuthenticationController.AllowedActions;
type UserStorageControllerActions = UserStorageController.AllowedActions;
type NotificationsServicesControllerActions =
NotificationServicesController.AllowedActions;

type SnapsGlobalActions =
| SnapControllerActions
Expand All @@ -255,6 +265,9 @@ type GlobalActions =
| LoggingControllerActions
///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps)
| SnapsGlobalActions
| AuthenticationControllerActions
| UserStorageControllerActions
| NotificationsServicesControllerActions
///: END:ONLY_INCLUDE_IF
| KeyringControllerActions
| AccountsControllerActions
Expand Down Expand Up @@ -307,6 +320,9 @@ export interface EngineState {
SnapController: PersistedSnapControllerState;
SnapsRegistry: SnapsRegistryState;
SubjectMetadataController: SubjectMetadataControllerState;
AuthenticationController: AuthenticationController.AuthenticationControllerState;
UserStorageController: UserStorageController.UserStorageControllerState;
NotificationServicesController: NotificationServicesController.NotificationServicesControllerState;
///: END:ONLY_INCLUDE_IF
PermissionController: PermissionControllerState<Permissions>;
ApprovalController: ApprovalControllerState;
Expand Down Expand Up @@ -349,6 +365,9 @@ interface Controllers {
///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps)
SnapController: SnapController;
SubjectMetadataController: SubjectMetadataController;
AuthenticationController: AuthenticationController.Controller;
UserStorageController: UserStorageController.Controller;
NotificationServicesController: NotificationServicesController.Controller;
///: END:ONLY_INCLUDE_IF
SwapsController: SwapsController;
}
Expand Down Expand Up @@ -914,7 +933,6 @@ class Engine {

const requireAllowlist = process.env.METAMASK_BUILD_TYPE === 'main';
const disableSnapInstallation = process.env.METAMASK_BUILD_TYPE === 'main';

const allowLocalSnaps = process.env.METAMASK_BUILD_TYPE === 'flask';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore TODO: Resolve/patch mismatch between base-controller versions.
Expand Down Expand Up @@ -1017,6 +1035,75 @@ class Engine {
store.getState().settings.basicFunctionalityEnabled === false,
}),
});

const authenticationController = new AuthenticationController.Controller({
state: initialState.AuthenticationController,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore TODO: Resolve/patch mismatch between messenger types
messenger: this.controllerMessenger.getRestricted({
name: 'AuthenticationController',
allowedActions: [
'SnapController:handleRequest',
'UserStorageController:disableProfileSyncing',
],
allowedEvents: [],
}),
// TODO: Fix this by (await MetaMetrics.getInstance().getMetaMetricsId()) before go live
metametrics: {
agent: 'mobile',
getMetaMetricsId: async () => Promise.resolve(''),
},
});

const userStorageController = new UserStorageController.Controller({
getMetaMetricsState: () => MetaMetrics.getInstance().isEnabled(),
state: initialState.UserStorageController,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore TODO: Resolve/patch mismatch between messenger types
messenger: this.controllerMessenger.getRestricted({
name: 'UserStorageController',
allowedActions: [
'SnapController:handleRequest',
'AuthenticationController:getBearerToken',
'AuthenticationController:getSessionProfile',
'AuthenticationController:isSignedIn',
'AuthenticationController:performSignOut',
'AuthenticationController:performSignIn',
'NotificationServicesController:disableNotificationServices',
'NotificationServicesController:selectIsNotificationServicesEnabled',
],
allowedEvents: [],
}),
});

const notificationServicesController =
new NotificationServicesController.Controller({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore TODO: Resolve/patch mismatch between messenger types
messenger: this.controllerMessenger.getRestricted({
name: 'NotificationServicesController',
allowedActions: [
'KeyringController:getAccounts',
'AuthenticationController:getBearerToken',
'AuthenticationController:isSignedIn',
'UserStorageController:enableProfileSyncing',
'UserStorageController:getStorageKey',
'UserStorageController:performGetStorage',
'UserStorageController:performSetStorage',
],
allowedEvents: ['KeyringController:stateChange'],
}),
state: initialState.NotificationServicesController,
env: {
isPushIntegrated: false,
featureAnnouncements: {
platform: 'mobile',
accessToken: process.env
.FEATURES_ANNOUNCEMENTS_ACCESS_TOKEN as string,
spaceId: process.env.FEATURES_ANNOUNCEMENTS_SPACE_ID as string,
},
},
});
///: END:ONLY_INCLUDE_IF

this.transactionController = new TransactionController({
Expand Down Expand Up @@ -1302,6 +1389,9 @@ class Engine {
///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps)
snapController,
subjectMetadataController,
authenticationController,
userStorageController,
notificationServicesController,
///: END:ONLY_INCLUDE_IF
accountsController,
new PPOMController({
Expand Down Expand Up @@ -1820,6 +1910,9 @@ export default {
///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps)
SnapController,
SubjectMetadataController,
AuthenticationController,
UserStorageController,
NotificationServicesController,
///: END:ONLY_INCLUDE_IF
PermissionController,
ApprovalController,
Expand Down Expand Up @@ -1861,6 +1954,9 @@ export default {
///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps)
SnapController,
SubjectMetadataController,
AuthenticationController,
UserStorageController,
NotificationServicesController,
///: END:ONLY_INCLUDE_IF
PermissionController,
ApprovalController,
Expand Down
19 changes: 19 additions & 0 deletions app/util/sentry/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,25 @@ export const sentryStateMask = {
TransactionController: {
[AllProperties]: false,
},
AuthenticationController: {
[AllProperties]: false,
},
NotificationServicesController: {
isCheckingAccountsPresence: false,
isFeatureAnnouncementsEnabled: false,
isFetchingMetamaskNotifications: false,
isMetamaskNotificationsFeatureSeen: false,
isNotificationServicesEnabled: false,
isUpdatingMetamaskNotifications: false,
isUpdatingMetamaskNotificationsAccount: [],
metamaskNotificationsList: [],
metamaskNotificationsReadList: [],
subscriptionAccountsSeen: [],
},
UserStorageController: {
isProfileSyncingEnabled: true,
isProfileSyncingUpdateLoading: false,
},
},
},
experimentalSettings: true,
Expand Down
27 changes: 24 additions & 3 deletions app/util/test/initial-background-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"storageMetadata": [],
"versionInfo": []
},

"CurrencyRateController": {
"currentCurrency": "usd",
"currencyRates": {
Expand All @@ -65,7 +64,10 @@
"ticker": "ETH"
},
"networksMetadata": {
"mainnet": { "EIPS": {}, "status": "unknown" }
"mainnet": {
"EIPS": {},
"status": "unknown"
}
},
"selectedNetworkClientId": "mainnet"
},
Expand Down Expand Up @@ -237,5 +239,24 @@
"unapprovedMsgCount": 0,
"unapprovedPersonalMsgCount": 0,
"unapprovedTypedMessagesCount": 0
},
"AuthenticationController": {
"isSignedIn": false
},
"NotificationServicesController": {
"isCheckingAccountsPresence": false,
"isFeatureAnnouncementsEnabled": false,
"isFetchingMetamaskNotifications": false,
"isMetamaskNotificationsFeatureSeen": false,
"isNotificationServicesEnabled": false,
"isUpdatingMetamaskNotifications": false,
"isUpdatingMetamaskNotificationsAccount": [],
"metamaskNotificationsList": [],
"metamaskNotificationsReadList": [],
"subscriptionAccountsSeen": []
},
"UserStorageController": {
"isProfileSyncingEnabled": true,
"isProfileSyncingUpdateLoading": false
}
}
}
8 changes: 8 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ module.exports = {
test: './node_modules/marked',
plugins: [['@babel/plugin-transform-private-methods', { loose: true }]],
},
{
test: './node_modules/@metamask/profile-sync-controller',
plugins: [['@babel/plugin-transform-private-methods', { loose: true }]],
},
{
test: './node_modules/@metamask/notification-services-controller',
plugins: [['@babel/plugin-transform-private-methods', { loose: true }]],
},
],
env: {
production: {
Expand Down
4 changes: 3 additions & 1 deletion firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"react-native": {
"analytics_auto_collection_enabled": false,
"messaging_auto_init_enabled": false,
"messaging_ios_auto_register_for_remote_messages": true
"messaging_ios_auto_register_for_remote_messages": true,
"android_task_executor_maximum_pool_size": 10,
"android_task_executor_keep_alive_seconds": 3
}
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@
"@metamask/logging-controller": "^3.0.0",
"@metamask/message-signing-snap": "^0.3.3",
"@metamask/network-controller": "^18.1.0",
"@metamask/notification-services-controller": "^0.1.1",
"@metamask/permission-controller": "^9.0.0",
"@metamask/phishing-controller": "^9.0.0",
"@metamask/post-message-stream": "^8.0.0",
"@metamask/ppom-validator": "0.32.0",
"@metamask/preferences-controller": "^11.0.0",
"@metamask/profile-sync-controller": "^0.1.3",
"@metamask/react-native-actionsheet": "2.4.2",
"@metamask/react-native-button": "^3.0.0",
"@metamask/react-native-payments": "^2.0.0",
Expand Down Expand Up @@ -575,8 +577,9 @@
"ts-node>@swc/core": false,
"@metamask/sdk-communication-layer>bufferutil": false,
"@metamask/sdk-communication-layer>utf-8-validate": false,
"detox>ws>bufferutil": false
"detox>ws>bufferutil": false,
"@metamask/notification-services-controller>firebase>@firebase/firestore>@grpc/proto-loader>protobufjs": false
}
},
"packageManager": "[email protected]"
}
}
Loading

0 comments on commit 0abb822

Please sign in to comment.