Skip to content

Commit

Permalink
Maryia/checking network status before initializing Pushwoosh
Browse files Browse the repository at this point in the history
  • Loading branch information
maryia-deriv-archive committed Feb 21, 2022
1 parent 9db26b5 commit 6233819
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions packages/core/src/Stores/pushwoosh-store.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -19,6 +19,19 @@ export default class PushwooshStore extends BaseStore {
*/
@action.bound
init = () => {
let reaction_id;
if (!this.root_store.common.is_network_online) {
// register a reaction that has to be executed only once
// when is_network_online is true for the first time after false:
reaction_id = when(
() => this.root_store.common.is_network_online,
() => {
this.init();
}
);
return;
}
reaction_id?.cancel();
if (!this.is_applicable && this.has_initialized) return;

this.push_woosh.push([
Expand All @@ -44,9 +57,7 @@ export default class PushwooshStore extends BaseStore {
}
});
// eslint-disable-next-line no-empty
} catch (e) {
/* no actual handling is expected */
}
} catch {}

this.sendTags(api);
},
Expand All @@ -69,8 +80,9 @@ export default class PushwooshStore extends BaseStore {
}
return null;
})
.catch(() => {
/* no actual handling is expected */
.catch(e => {
// eslint-disable-next-line no-console
console.error(e);
return null;
});
};
Expand Down

0 comments on commit 6233819

Please sign in to comment.