From 0bbfe11ec8e0a2fe89e81ff551a8832a6222ea7e Mon Sep 17 00:00:00 2001 From: maryia-deriv Date: Mon, 21 Feb 2022 17:48:02 +0300 Subject: [PATCH 1/2] Maryia/Checking network status before initializing Pushwoosh --- packages/core/src/Stores/pushwoosh-store.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/core/src/Stores/pushwoosh-store.js b/packages/core/src/Stores/pushwoosh-store.js index 340ab7c76357..b686cff64001 100644 --- a/packages/core/src/Stores/pushwoosh-store.js +++ b/packages/core/src/Stores/pushwoosh-store.js @@ -1,4 +1,4 @@ -import { action } from 'mobx'; +import { action, when } from 'mobx'; import { Pushwoosh } from 'web-push-notifications'; import { getAppId, urlForCurrentDomain } from '@deriv/shared'; import { getLanguage } from '@deriv/translations'; @@ -19,6 +19,18 @@ export default class PushwooshStore extends BaseStore { */ @action.bound init = () => { + let reaction_id; + if (!this.root_store.common.is_network_online) { + reaction_id = when( + () => this.root_store.common.is_network_online, + () => { + this.init(); + } + ); + return; + } + // canceling the reaction once is_network_online becomes true for the first time: + reaction_id?.cancel(); if (!this.is_applicable && this.has_initialized) return; this.push_woosh.push([ From 2b431eb8ff7c310237fe7c1a0f7b7793d72f5645 Mon Sep 17 00:00:00 2001 From: maryia-deriv Date: Tue, 22 Feb 2022 10:13:19 +0300 Subject: [PATCH 2/2] Maryia/refactoring --- packages/core/src/Stores/pushwoosh-store.js | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/packages/core/src/Stores/pushwoosh-store.js b/packages/core/src/Stores/pushwoosh-store.js index b686cff64001..0bba30203721 100644 --- a/packages/core/src/Stores/pushwoosh-store.js +++ b/packages/core/src/Stores/pushwoosh-store.js @@ -18,20 +18,9 @@ export default class PushwooshStore extends BaseStore { * Pushes initialize event to pushwoosh */ @action.bound - init = () => { - let reaction_id; - if (!this.root_store.common.is_network_online) { - reaction_id = when( - () => this.root_store.common.is_network_online, - () => { - this.init(); - } - ); - return; - } - // canceling the reaction once is_network_online becomes true for the first time: - reaction_id?.cancel(); + init = async () => { if (!this.is_applicable && this.has_initialized) return; + await when(() => this.root_store.common.is_network_online); this.push_woosh.push([ 'init',