-
-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: notification services controller mobile fixes #4441
Changes from all commits
ba4f7cf
39b2bf0
f230326
509f795
caf274f
ab5de02
4ca7284
fe8f87f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,3 @@ export * from './mock-notification-trigger'; | |
export * from './mock-notification-user-storage'; | ||
export * from './mock-raw-notifications'; | ||
export * from './mockResponses'; | ||
export * from './mockServices'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import type { Compute } from '../types/type-utils'; | ||
|
||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
export enum TRIGGER_TYPES { | ||
FEATURES_ANNOUNCEMENT = 'features_announcement', | ||
|
@@ -42,15 +44,22 @@ export enum TRIGGER_TYPES_GROUPS { | |
DEFI = 'defi', | ||
} | ||
|
||
export const NOTIFICATION_CHAINS = { | ||
export const NOTIFICATION_CHAINS_ID = { | ||
ETHEREUM: '1', | ||
OPTIMISM: '10', | ||
BSC: '56', | ||
POLYGON: '137', | ||
ARBITRUM: '42161', | ||
AVALANCHE: '43114', | ||
LINEA: '59144', | ||
}; | ||
} as const; | ||
|
||
type ToPrimitiveKeys<TObj> = Compute<{ | ||
[K in keyof TObj]: TObj[K] extends string ? string : TObj[K]; | ||
}>; | ||
export const NOTIFICATION_CHAINS: ToPrimitiveKeys< | ||
typeof NOTIFICATION_CHAINS_ID | ||
> = NOTIFICATION_CHAINS_ID; | ||
Comment on lines
+47
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is some fancy types/constants so they can be reused for the
|
||
|
||
export const CHAIN_SYMBOLS = { | ||
[NOTIFICATION_CHAINS.ETHEREUM]: 'ETH', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { NOTIFICATION_CHAINS_ID } from '../constants/notification-schema'; | ||
|
||
export const NOTIFICATION_NETWORK_CURRENCY_NAME = { | ||
[NOTIFICATION_CHAINS_ID.ETHEREUM]: 'Ethereum', | ||
[NOTIFICATION_CHAINS_ID.ARBITRUM]: 'Arbitrum', | ||
[NOTIFICATION_CHAINS_ID.AVALANCHE]: 'Avalanche', | ||
[NOTIFICATION_CHAINS_ID.BSC]: 'Binance', | ||
[NOTIFICATION_CHAINS_ID.LINEA]: 'Linea', | ||
[NOTIFICATION_CHAINS_ID.OPTIMISM]: 'Optimism', | ||
[NOTIFICATION_CHAINS_ID.POLYGON]: 'Polygon', | ||
} as const; | ||
|
||
export const NOTIFICATION_NETWORK_CURRENCY_SYMBOL = { | ||
[NOTIFICATION_CHAINS_ID.ETHEREUM]: 'ETH', | ||
[NOTIFICATION_CHAINS_ID.ARBITRUM]: 'ETH', | ||
[NOTIFICATION_CHAINS_ID.AVALANCHE]: 'AVAX', | ||
[NOTIFICATION_CHAINS_ID.BSC]: 'BNB', | ||
[NOTIFICATION_CHAINS_ID.LINEA]: 'ETH', | ||
[NOTIFICATION_CHAINS_ID.OPTIMISM]: 'ETH', | ||
[NOTIFICATION_CHAINS_ID.POLYGON]: 'MATIC', | ||
}; | ||
|
||
export { NOTIFICATION_CHAINS_ID } from '../constants/notification-schema'; | ||
Comment on lines
+1
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mobile does not have consistent token name/exports to extension. To keep things in sync, we will use these shared constants in this package. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './constants'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,9 @@ export type NotificationServicesPushControllerMessenger = | |
AllowedEvents['type'] | ||
>; | ||
|
||
export const defaultState: NotificationServicesPushControllerState = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mobile ask - we are now exporting default exports (this ensures that our redux initial state has "something"). |
||
fcmToken: '', | ||
}; | ||
const metadata = { | ||
fcmToken: { | ||
persist: true, | ||
|
@@ -141,9 +144,7 @@ export default class NotificationServicesPushController extends BaseController< | |
messenger, | ||
metadata, | ||
name: controllerName, | ||
state: { | ||
fcmToken: state?.fcmToken || '', | ||
}, | ||
state: { ...defaultState, ...state }, | ||
}); | ||
|
||
this.#env = env; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './mockResponse'; | ||
export * from './mockServices'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import type { Types } from '../../../NotificationServicesController'; | |
import { Processors } from '../../../NotificationServicesController'; | ||
import type { PushNotificationEnv } from '../../types/firebase'; | ||
|
||
const sw = self as unknown as ServiceWorkerGlobalScope; | ||
declare const self: ServiceWorkerGlobalScope; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. self does not exist on mobile and breaks. So instead removing the In the future (once we support multiple exports and tree shaking) we can tidy this up. |
||
|
||
const createFirebaseApp = async ( | ||
env: PushNotificationEnv, | ||
|
@@ -52,7 +52,7 @@ export async function createRegToken( | |
try { | ||
const messaging = await getFirebaseMessaging(env); | ||
const token = await getToken(messaging, { | ||
serviceWorkerRegistration: sw.registration, | ||
serviceWorkerRegistration: self.registration, | ||
vapidKey: env.vapidKey, | ||
}); | ||
return token; | ||
|
@@ -135,8 +135,8 @@ export function listenToPushNotificationsClicked( | |
handler(event, data); | ||
}; | ||
|
||
sw.addEventListener('notificationclick', clickHandler); | ||
self.addEventListener('notificationclick', clickHandler); | ||
const unsubscribe = () => | ||
sw.removeEventListener('notificationclick', clickHandler); | ||
self.removeEventListener('notificationclick', clickHandler); | ||
return unsubscribe; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"extends": "../../tsconfig.packages.build.json", | ||
"extends": "../../tsconfig.packages.json", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Misc, noticed we are not using the correct tsconfig for this file compared to other packages. No major issues though. |
||
"compilerOptions": { | ||
"baseUrl": "./" | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './mockResponses'; | ||
export * from './mockServices'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from './mockResponses'; | ||
export * from './mockServices'; | ||
export * from './mockStorage'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import type { Env, Platform } from '../env'; | ||
|
||
export const enum AuthType { | ||
export enum AuthType { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Infura SDK ask. Projects that use |
||
/* sign in using a private key derived from your secret recovery phrase (SRP). | ||
Uses message signing snap to perform this operation */ | ||
SRP = 'SRP', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temp for mobile. We will remove this in a later release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Push Notification controllers isn't integrated and won't be on Mobile since MM app relies on Firebase SDK directly. Maybe we should remove the comment and use this flag as a feature that it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK fair, as this is 0.x.x packages, there most likely will be more changes coming down the pipeline. I shall update any documentation and comments in a future version.