File tree 2 files changed +20
-7
lines changed
2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change
1
+ import browser from "webextension-polyfill"
1
2
import { FiatCurrency } from "../../assets"
2
3
import { AddressOnNetwork , NameOnNetwork } from "../../accounts"
3
4
import { ServiceLifecycleEvents , ServiceCreatorFunction } from "../types"
@@ -281,11 +282,21 @@ export default class PreferenceService extends BaseService<Events> {
281
282
return ( await this . db . getPreferences ( ) ) . shouldShowNotifications
282
283
}
283
284
285
+ /**
286
+ * This guards against invalid state by checking if permissions have
287
+ * been granted by the browser
288
+ */
284
289
async setShouldShowNotifications ( shouldShowNotifications : boolean ) {
285
- await this . db . setShouldShowNotifications ( shouldShowNotifications )
286
- this . emitter . emit ( "setNotificationsPermission" , shouldShowNotifications )
290
+ const hasBrowserPermissions = await browser . permissions . contains ( {
291
+ permissions : [ "notifications" ] ,
292
+ } )
293
+
294
+ const updatedValue = hasBrowserPermissions && shouldShowNotifications
295
+
296
+ await this . db . setShouldShowNotifications ( updatedValue )
297
+ this . emitter . emit ( "setNotificationsPermission" , updatedValue )
287
298
288
- return shouldShowNotifications
299
+ return updatedValue
289
300
}
290
301
291
302
async getAccountSignerSettings ( ) : Promise < AccountSignerSettings [ ] > {
Original file line number Diff line number Diff line change @@ -1709,10 +1709,12 @@ export default class ReduxService extends BaseService<never> {
1709
1709
uiSliceEmitter . on (
1710
1710
"shouldShowNotifications" ,
1711
1711
async ( shouldShowNotifications : boolean ) => {
1712
- await this . preferenceService . setShouldShowNotifications (
1713
- shouldShowNotifications ,
1714
- )
1715
- this . store . dispatch ( toggleNotifications ( shouldShowNotifications ) )
1712
+ const notificationsEnabled =
1713
+ await this . preferenceService . setShouldShowNotifications (
1714
+ shouldShowNotifications ,
1715
+ )
1716
+
1717
+ this . store . dispatch ( toggleNotifications ( notificationsEnabled ) )
1716
1718
} ,
1717
1719
)
1718
1720
You can’t perform that action at this time.
0 commit comments