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"
@@ -275,11 +276,21 @@ export default class PreferenceService extends BaseService<Events> {
275
276
return ( await this . db . getPreferences ( ) ) . shouldShowNotifications
276
277
}
277
278
279
+ /**
280
+ * This guards against invalid state by checking if permissions have
281
+ * been granted by the browser
282
+ */
278
283
async setShouldShowNotifications ( shouldShowNotifications : boolean ) {
279
- await this . db . setShouldShowNotifications ( shouldShowNotifications )
280
- this . emitter . emit ( "setNotificationsPermission" , shouldShowNotifications )
284
+ const hasBrowserPermissions = await browser . permissions . contains ( {
285
+ permissions : [ "notifications" ] ,
286
+ } )
287
+
288
+ const updatedValue = hasBrowserPermissions && shouldShowNotifications
289
+
290
+ await this . db . setShouldShowNotifications ( updatedValue )
291
+ this . emitter . emit ( "setNotificationsPermission" , updatedValue )
281
292
282
- return shouldShowNotifications
293
+ return updatedValue
283
294
}
284
295
285
296
async getAccountSignerSettings ( ) : Promise < AccountSignerSettings [ ] > {
Original file line number Diff line number Diff line change @@ -1699,10 +1699,12 @@ export default class ReduxService extends BaseService<never> {
1699
1699
uiSliceEmitter . on (
1700
1700
"shouldShowNotifications" ,
1701
1701
async ( shouldShowNotifications : boolean ) => {
1702
- await this . preferenceService . setShouldShowNotifications (
1703
- shouldShowNotifications ,
1704
- )
1705
- this . store . dispatch ( toggleNotifications ( shouldShowNotifications ) )
1702
+ const notificationsEnabled =
1703
+ await this . preferenceService . setShouldShowNotifications (
1704
+ shouldShowNotifications ,
1705
+ )
1706
+
1707
+ this . store . dispatch ( toggleNotifications ( notificationsEnabled ) )
1706
1708
} ,
1707
1709
)
1708
1710
You can’t perform that action at this time.
0 commit comments