Skip to content
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: ensure push notifications are able to be subscribed to when the wallet is locked #4653

Merged
merged 10 commits into from
Sep 6, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,27 @@
return;
}

this.#pushListenerUnsubscribe ??= await listenToPushNotifications({
env: this.#env,
listenToPushReceived: async (n) => {
this.messagingSystem.publish(
'NotificationServicesPushController:onNewNotifications',
n,
);
await this.#config.onPushNotificationReceived(n);
},
listenToPushClicked: (e, n) => {
if (n) {
this.messagingSystem.publish(
'NotificationServicesPushController:pushNotificationClicked',
n,
);
}

this.#config.onPushNotificationClicked(e, n);
},
});
Prithpal-Sooriya marked this conversation as resolved.
Show resolved Hide resolved

const bearerToken = await this.#getAndAssertBearerToken();

try {
Expand All @@ -229,27 +250,6 @@
return;
}

this.#pushListenerUnsubscribe ??= await listenToPushNotifications({
env: this.#env,
listenToPushReceived: async (n) => {
this.messagingSystem.publish(
'NotificationServicesPushController:onNewNotifications',
n,
);
await this.#config.onPushNotificationReceived(n);
},
listenToPushClicked: (e, n) => {
if (n) {
this.messagingSystem.publish(
'NotificationServicesPushController:pushNotificationClicked',
n,
);
}

this.#config.onPushNotificationClicked(e, n);
},
});

// Update state
this.update((state) => {
state.fcmToken = regToken;
Expand Down Expand Up @@ -287,9 +287,8 @@
regToken: this.state.fcmToken,
});
} catch (error) {
const errorMessage = `Failed to disable push notifications: ${
error as string
}`;
const errorMessage = `Failed to disable push notifications: ${error as string

Check failure on line 290 in packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Insert `⏎········`
}`;

Check failure on line 291 in packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Delete `··`
log.error(errorMessage);
throw new Error(errorMessage);
}
Expand Down Expand Up @@ -342,9 +341,8 @@
});
}
} catch (error) {
const errorMessage = `Failed to update triggers for push notifications: ${
error as string
}`;
const errorMessage = `Failed to update triggers for push notifications: ${error as string

Check failure on line 344 in packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Insert `⏎········`
}`;

Check failure on line 345 in packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Delete `··`
log.error(errorMessage);
throw new Error(errorMessage);
}
Expand Down
Loading