From ae7851ac9306bdef07bc0e70c4c147d7eb3c613d Mon Sep 17 00:00:00 2001 From: Viktor Voronin Date: Fri, 22 Nov 2019 17:29:20 +0300 Subject: [PATCH 1/9] DEXW-2441: add shutdown notification templates and config --- mocks/waves-client-config/master/config.json | 7 +++- src/modules/utils/modals/ModalManager.js | 36 +++++++++++++++++++ .../modals/shutdownFirst/shutdownFirst.html | 8 +++++ .../modals/shutdownFirst/shutdownFirst.js | 20 +++++++++++ .../modals/shutdownFirst/shutdownFirst.less | 0 .../modals/shutdownLast/shutdownLast.html | 8 +++++ .../utils/modals/shutdownLast/shutdownLast.js | 21 +++++++++++ .../modals/shutdownLast/shutdownLast.less | 0 .../modals/shutdownSecond/shutdownSecond.html | 8 +++++ .../modals/shutdownSecond/shutdownSecond.js | 20 +++++++++++ .../modals/shutdownSecond/shutdownSecond.less | 0 11 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/modules/utils/modals/shutdownFirst/shutdownFirst.html create mode 100644 src/modules/utils/modals/shutdownFirst/shutdownFirst.js create mode 100644 src/modules/utils/modals/shutdownFirst/shutdownFirst.less create mode 100644 src/modules/utils/modals/shutdownLast/shutdownLast.html create mode 100644 src/modules/utils/modals/shutdownLast/shutdownLast.js create mode 100644 src/modules/utils/modals/shutdownLast/shutdownLast.less create mode 100644 src/modules/utils/modals/shutdownSecond/shutdownSecond.html create mode 100644 src/modules/utils/modals/shutdownSecond/shutdownSecond.js create mode 100644 src/modules/utils/modals/shutdownSecond/shutdownSecond.less diff --git a/mocks/waves-client-config/master/config.json b/mocks/waves-client-config/master/config.json index a3e753fbda..c54eb84d0f 100644 --- a/mocks/waves-client-config/master/config.json +++ b/mocks/waves-client-config/master/config.json @@ -80,5 +80,10 @@ "GATEWAYS_SOON": [ "5dJj4Hn9t2Ve3tRpNGirUHy4yBK6qdJRAJYV21yPPuGz" ], - "DEXW_LOCKED": false + "DEXW_LOCKED": false, + "SHUTDOWN_NOTIFICATION_TIMERS": [ + { "start": "2019-11-01T15:00:00+0300", "end": "2019-11-01T15:01:00+0300", "action": "showShutdownFirstModal" }, + { "start": "2019-11-02T08:00:00+0300", "end": "2019-11-02T08:01:00+0300", "action": "showShutdownSecondModal" }, + { "start": "2019-11-02T10:00:00+0300", "action": "showShutdownLastModal" } + ] } diff --git a/src/modules/utils/modals/ModalManager.js b/src/modules/utils/modals/ModalManager.js index ed0afd2c52..c9429ac33a 100644 --- a/src/modules/utils/modals/ModalManager.js +++ b/src/modules/utils/modals/ModalManager.js @@ -54,6 +54,7 @@ state.signals.changeRouterStateStart.on(this.closeModals, this); user.logoutSignal.on(this.closeModals, this); + window._mm = this; } /** @@ -755,6 +756,41 @@ return this._getModal(tsUtils.merge({}, DEFAULT_OPTIONS, options, { contentUrl, controller })); } + showShutdownFirstModal() { + localStorage.setItem('shutdownFirstShown', true); + return this._getModal({ + id: 'shutdownFirstModal', + templateUrl: 'modules/utils/modals/shutdownFirst/shutdownFirst.html', + controller: 'ShutdownFirstCtrl', + clickOutsideToClose: false, + escapeToClose: false + }); + } + + showShutdownSecondModal() { + localStorage.setItem('shutdownSecondShown', true); + return this._getModal({ + id: 'shutdownSecondModal', + templateUrl: 'modules/utils/modals/shutdownSecond/shutdownSecond.html', + controller: 'ShutdownSecondCtrl', + clickOutsideToClose: false, + escapeToClose: false, + hasBackdrop: false + }); + } + + showShutdownLastModal() { + return this._getModal({ + id: 'shutdownLastModal', + templateUrl: 'modules/utils/modals/shutdownLast/shutdownLast.html', + controller: 'ShutdownLastCtrl', + clickOutsideToClose: false, + escapeToClose: false, + hasBackdrop: true + }); + } + + /** * @param {IModalOptions} options * @return {$q.resolve} diff --git a/src/modules/utils/modals/shutdownFirst/shutdownFirst.html b/src/modules/utils/modals/shutdownFirst/shutdownFirst.html new file mode 100644 index 0000000000..9030d3a40d --- /dev/null +++ b/src/modules/utils/modals/shutdownFirst/shutdownFirst.html @@ -0,0 +1,8 @@ + + + + modal day before + + + + diff --git a/src/modules/utils/modals/shutdownFirst/shutdownFirst.js b/src/modules/utils/modals/shutdownFirst/shutdownFirst.js new file mode 100644 index 0000000000..a2daf15d1b --- /dev/null +++ b/src/modules/utils/modals/shutdownFirst/shutdownFirst.js @@ -0,0 +1,20 @@ +(function () { + 'use strict'; + + const controller = function (Base, $mdDialog) { + + class ShutdownFirstCtrl extends Base { + + confirm() { + $mdDialog.hide(); + } + + } + + return new ShutdownFirstCtrl(); + }; + + controller.$inject = ['Base', '$mdDialog']; + + angular.module('app.utils').controller('ShutdownFirstCtrl', controller); +})(); diff --git a/src/modules/utils/modals/shutdownFirst/shutdownFirst.less b/src/modules/utils/modals/shutdownFirst/shutdownFirst.less new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/modules/utils/modals/shutdownLast/shutdownLast.html b/src/modules/utils/modals/shutdownLast/shutdownLast.html new file mode 100644 index 0000000000..b1eacff07f --- /dev/null +++ b/src/modules/utils/modals/shutdownLast/shutdownLast.html @@ -0,0 +1,8 @@ + + + + modal hour x + + + + diff --git a/src/modules/utils/modals/shutdownLast/shutdownLast.js b/src/modules/utils/modals/shutdownLast/shutdownLast.js new file mode 100644 index 0000000000..36568739e5 --- /dev/null +++ b/src/modules/utils/modals/shutdownLast/shutdownLast.js @@ -0,0 +1,21 @@ +(function () { + 'use strict'; + + const controller = function (Base, $mdDialog) { + + class ShutdownLastCtrl extends Base { + + confirm() { + window.history.go(0); + $mdDialog.hide(); + } + + } + + return new ShutdownLastCtrl(); + }; + + controller.$inject = ['Base', '$mdDialog']; + + angular.module('app.utils').controller('ShutdownLastCtrl', controller); +})(); diff --git a/src/modules/utils/modals/shutdownLast/shutdownLast.less b/src/modules/utils/modals/shutdownLast/shutdownLast.less new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/modules/utils/modals/shutdownSecond/shutdownSecond.html b/src/modules/utils/modals/shutdownSecond/shutdownSecond.html new file mode 100644 index 0000000000..97bc738c0f --- /dev/null +++ b/src/modules/utils/modals/shutdownSecond/shutdownSecond.html @@ -0,0 +1,8 @@ + + + + modal hour before + + + + diff --git a/src/modules/utils/modals/shutdownSecond/shutdownSecond.js b/src/modules/utils/modals/shutdownSecond/shutdownSecond.js new file mode 100644 index 0000000000..9a6b281eca --- /dev/null +++ b/src/modules/utils/modals/shutdownSecond/shutdownSecond.js @@ -0,0 +1,20 @@ +(function () { + 'use strict'; + + const controller = function (Base, $mdDialog) { + + class ShutdownSecondCtrl extends Base { + + confirm() { + $mdDialog.hide(); + } + + } + + return new ShutdownSecondCtrl(); + }; + + controller.$inject = ['Base', '$mdDialog']; + + angular.module('app.utils').controller('ShutdownSecondCtrl', controller); +})(); diff --git a/src/modules/utils/modals/shutdownSecond/shutdownSecond.less b/src/modules/utils/modals/shutdownSecond/shutdownSecond.less new file mode 100644 index 0000000000..e69de29bb2 From a180f1610d6048fd0562395d168cbfe92968b076 Mon Sep 17 00:00:00 2001 From: Viktor Voronin Date: Fri, 22 Nov 2019 17:33:10 +0300 Subject: [PATCH 2/9] fixup! Merge pull request #1795 from wavesplatform/dexw-2445-release-1.4.16 --- src/modules/utils/modals/ModalManager.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/modules/utils/modals/ModalManager.js b/src/modules/utils/modals/ModalManager.js index c9429ac33a..6be3e2f819 100644 --- a/src/modules/utils/modals/ModalManager.js +++ b/src/modules/utils/modals/ModalManager.js @@ -774,8 +774,7 @@ templateUrl: 'modules/utils/modals/shutdownSecond/shutdownSecond.html', controller: 'ShutdownSecondCtrl', clickOutsideToClose: false, - escapeToClose: false, - hasBackdrop: false + escapeToClose: false }); } @@ -785,8 +784,7 @@ templateUrl: 'modules/utils/modals/shutdownLast/shutdownLast.html', controller: 'ShutdownLastCtrl', clickOutsideToClose: false, - escapeToClose: false, - hasBackdrop: true + escapeToClose: false }); } From 760172b140996a87301d7035880fe3c72b77db59 Mon Sep 17 00:00:00 2001 From: Max Axenov Date: Mon, 25 Nov 2019 10:51:48 +0300 Subject: [PATCH 3/9] DEXW-2439: shutdownService --- mocks/waves-client-config/master/config.json | 6 +-- src/modules/app/initialize/AppRun.js | 10 +++- src/modules/app/services/ShutdownService.js | 55 ++++++++++++++++++++ 3 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 src/modules/app/services/ShutdownService.js diff --git a/mocks/waves-client-config/master/config.json b/mocks/waves-client-config/master/config.json index c54eb84d0f..87665af0da 100644 --- a/mocks/waves-client-config/master/config.json +++ b/mocks/waves-client-config/master/config.json @@ -82,8 +82,8 @@ ], "DEXW_LOCKED": false, "SHUTDOWN_NOTIFICATION_TIMERS": [ - { "start": "2019-11-01T15:00:00+0300", "end": "2019-11-01T15:01:00+0300", "action": "showShutdownFirstModal" }, - { "start": "2019-11-02T08:00:00+0300", "end": "2019-11-02T08:01:00+0300", "action": "showShutdownSecondModal" }, - { "start": "2019-11-02T10:00:00+0300", "action": "showShutdownLastModal" } + { "start": "2019-12-01T15:00:00+03:00", "end": "2019-12-01T15:01:00+03:00", "action": "showShutdownFirstModal" }, + { "start": "2019-12-02T08:00:00+03:00", "end": "2019-12-02T08:01:00+03:00", "action": "showShutdownSecondModal" }, + { "start": "2019-12-02T10:00:00+03:00", "action": "showShutdownLastModal" } ] } diff --git a/src/modules/app/initialize/AppRun.js b/src/modules/app/initialize/AppRun.js index 1f703a61c9..e4725ee190 100644 --- a/src/modules/app/initialize/AppRun.js +++ b/src/modules/app/initialize/AppRun.js @@ -78,6 +78,7 @@ * @param {ModalRouter} ModalRouter * @param {ConfigService} configService * @param {INotification} userNotification + * @param {ShutdownService} shutdownService * @return {AppRun} */ // eslint-disable-next-line max-params @@ -97,7 +98,8 @@ multiAccount, ModalRouter, configService, - userNotification + userNotification, + shutdownService ) { const phone = WavesApp.device.phone(); @@ -248,6 +250,10 @@ return false; } + _setShutdownService() { + shutdownService.run(); + } + /** * @private */ @@ -399,6 +405,7 @@ }); balanceWatcher.change.once(this._onBalanceChange, this); + this._setShutdownService(); }); } @@ -809,6 +816,7 @@ 'ModalRouter', 'configService', 'userNotification', + 'shutdownService', 'whatsNew' ]; diff --git a/src/modules/app/services/ShutdownService.js b/src/modules/app/services/ShutdownService.js new file mode 100644 index 0000000000..9b0f26995e --- /dev/null +++ b/src/modules/app/services/ShutdownService.js @@ -0,0 +1,55 @@ +(function () { + 'use strict'; + + /** + * @param {Base} Base + * @param {IPollCreate} createPoll + * @param {ConfigService} configService + * @param {ModalManager} modalManager + * @return {ShutdownService} + */ + const factory = function (Base, createPoll, configService, modalManager) { + + class ShutdownService extends Base { + + /** + * @public + */ + run() { + createPoll(this, this._getDates, this._handleDates, 1000); + } + + _getDates() { + return configService.get('SHUTDOWN_NOTIFICATION_TIMERS'); + } + + _handleDates(timers) { + const now = Date.now(); + timers.forEach(timer => { + const start = new Date(timer.start).getTime(); + const end = timer.end ? new Date(timer.end).getTime() : Date.now(); + + if (now >= start && now <= end) { + if (!sessionStorage.getItem(timer.action)) { + sessionStorage.setItem(timer.action, 'true'); + modalManager[timer.action](); + } + + } + }); + } + + + } + + return new ShutdownService(); + }; + + factory.$inject = ['Base', 'createPoll', 'configService', 'modalManager']; + + angular.module('app').factory('shutdownService', factory); +})(); + +/** + * @name ShutdownService + */ From f0015d0098609b2732fb1b9d7b16b5fe264614a6 Mon Sep 17 00:00:00 2001 From: Max Axenov Date: Mon, 25 Nov 2019 10:53:57 +0300 Subject: [PATCH 4/9] DEXW-2439: added jsdock type --- src/modules/app/services/ShutdownService.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/modules/app/services/ShutdownService.js b/src/modules/app/services/ShutdownService.js index 9b0f26995e..0a59734fd6 100644 --- a/src/modules/app/services/ShutdownService.js +++ b/src/modules/app/services/ShutdownService.js @@ -19,10 +19,18 @@ createPoll(this, this._getDates, this._handleDates, 1000); } + /** + * @return {*} + * @private + */ _getDates() { return configService.get('SHUTDOWN_NOTIFICATION_TIMERS'); } + /** + * @param {[{ start: string, end: ?string, action: string }]} timers + * @private + */ _handleDates(timers) { const now = Date.now(); timers.forEach(timer => { From 59a7077c60a0e05e0d5955f74f2d055e240160bb Mon Sep 17 00:00:00 2001 From: Max Axenov Date: Mon, 25 Nov 2019 11:56:45 +0300 Subject: [PATCH 5/9] DEXW-2439: change polling to setTimeout --- src/modules/app/initialize/AppRun.js | 2 +- src/modules/app/services/ShutdownService.js | 13 ++++++++++++- src/modules/utils/modals/ModalManager.js | 1 - 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/modules/app/initialize/AppRun.js b/src/modules/app/initialize/AppRun.js index e4725ee190..460a1dcc74 100644 --- a/src/modules/app/initialize/AppRun.js +++ b/src/modules/app/initialize/AppRun.js @@ -160,6 +160,7 @@ this._initializeLogin(); this._initializeOutLinks(); this._openMigrationModal(); + this._setShutdownService(); if (WavesApp.isDesktop()) { window.listenMainProcessEvent((type, url) => { @@ -405,7 +406,6 @@ }); balanceWatcher.change.once(this._onBalanceChange, this); - this._setShutdownService(); }); } diff --git a/src/modules/app/services/ShutdownService.js b/src/modules/app/services/ShutdownService.js index 0a59734fd6..ef61727be7 100644 --- a/src/modules/app/services/ShutdownService.js +++ b/src/modules/app/services/ShutdownService.js @@ -16,7 +16,17 @@ * @public */ run() { - createPoll(this, this._getDates, this._handleDates, 1000); + let timerId; + const tick = () => { + this._handleDates(this._getDates()); + if (timerId) { + window.clearInterval(timerId); + } + timerId = setTimeout(() => tick(), 1000); + }; + + tick(); + } /** @@ -33,6 +43,7 @@ */ _handleDates(timers) { const now = Date.now(); + timers.forEach(timer => { const start = new Date(timer.start).getTime(); const end = timer.end ? new Date(timer.end).getTime() : Date.now(); diff --git a/src/modules/utils/modals/ModalManager.js b/src/modules/utils/modals/ModalManager.js index 6be3e2f819..3e7ac784c8 100644 --- a/src/modules/utils/modals/ModalManager.js +++ b/src/modules/utils/modals/ModalManager.js @@ -54,7 +54,6 @@ state.signals.changeRouterStateStart.on(this.closeModals, this); user.logoutSignal.on(this.closeModals, this); - window._mm = this; } /** From 732902757146efa014135afc8ca61d002df8e4d2 Mon Sep 17 00:00:00 2001 From: Max Axenov Date: Mon, 25 Nov 2019 12:04:27 +0300 Subject: [PATCH 6/9] DEXW-2439: fix naming --- src/modules/app/services/ShutdownService.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/modules/app/services/ShutdownService.js b/src/modules/app/services/ShutdownService.js index ef61727be7..63cdb0ddab 100644 --- a/src/modules/app/services/ShutdownService.js +++ b/src/modules/app/services/ShutdownService.js @@ -16,13 +16,13 @@ * @public */ run() { - let timerId; + let timeOutTimerId; const tick = () => { - this._handleDates(this._getDates()); - if (timerId) { - window.clearInterval(timerId); + this._handleTimers(this._getTimers()); + if (timeOutTimerId) { + window.clearInterval(timeOutTimerId); } - timerId = setTimeout(() => tick(), 1000); + timeOutTimerId = setTimeout(() => tick(), 1000); }; tick(); @@ -33,7 +33,7 @@ * @return {*} * @private */ - _getDates() { + _getTimers() { return configService.get('SHUTDOWN_NOTIFICATION_TIMERS'); } @@ -41,7 +41,7 @@ * @param {[{ start: string, end: ?string, action: string }]} timers * @private */ - _handleDates(timers) { + _handleTimers(timers) { const now = Date.now(); timers.forEach(timer => { From 702ed70a00f852d653c28f5d593690f749424ed5 Mon Sep 17 00:00:00 2001 From: Max Axenov Date: Mon, 25 Nov 2019 12:28:05 +0300 Subject: [PATCH 7/9] DEXW-2439: fix clearTimeout --- src/modules/app/services/ShutdownService.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/app/services/ShutdownService.js b/src/modules/app/services/ShutdownService.js index 63cdb0ddab..dbd22b2344 100644 --- a/src/modules/app/services/ShutdownService.js +++ b/src/modules/app/services/ShutdownService.js @@ -20,7 +20,7 @@ const tick = () => { this._handleTimers(this._getTimers()); if (timeOutTimerId) { - window.clearInterval(timeOutTimerId); + window.clearTimeout(timeOutTimerId); } timeOutTimerId = setTimeout(() => tick(), 1000); }; From d184a104ae72c1157d97f3933ab8df73e750b79e Mon Sep 17 00:00:00 2001 From: Max Axenov Date: Mon, 25 Nov 2019 12:43:23 +0300 Subject: [PATCH 8/9] DEXW-2439: refactor, fix empty config value --- src/modules/app/services/ShutdownService.js | 23 ++++++++------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/modules/app/services/ShutdownService.js b/src/modules/app/services/ShutdownService.js index dbd22b2344..f81b335446 100644 --- a/src/modules/app/services/ShutdownService.js +++ b/src/modules/app/services/ShutdownService.js @@ -12,21 +12,18 @@ class ShutdownService extends Base { + /** + * @private + */ + _timeOutTimerId; + /** * @public */ run() { - let timeOutTimerId; - const tick = () => { - this._handleTimers(this._getTimers()); - if (timeOutTimerId) { - window.clearTimeout(timeOutTimerId); - } - timeOutTimerId = setTimeout(() => tick(), 1000); - }; - - tick(); - + this._handleTimers(this._getTimers()); + window.clearTimeout(this._timeOutTimerId); + this._timeOutTimerId = setTimeout(() => this.run(), 1000); } /** @@ -34,7 +31,7 @@ * @private */ _getTimers() { - return configService.get('SHUTDOWN_NOTIFICATION_TIMERS'); + return configService.get('SHUTDOWN_NOTIFICATION_TIMERS') || []; } /** @@ -53,12 +50,10 @@ sessionStorage.setItem(timer.action, 'true'); modalManager[timer.action](); } - } }); } - } return new ShutdownService(); From 2c522c9bfbad7c9aaf96f3fadc4754c974c4aec9 Mon Sep 17 00:00:00 2001 From: Max Axenov Date: Mon, 25 Nov 2019 12:44:31 +0300 Subject: [PATCH 9/9] DEXW-2439: remove method --- src/modules/app/initialize/AppRun.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/modules/app/initialize/AppRun.js b/src/modules/app/initialize/AppRun.js index 460a1dcc74..2f62dc0641 100644 --- a/src/modules/app/initialize/AppRun.js +++ b/src/modules/app/initialize/AppRun.js @@ -160,7 +160,7 @@ this._initializeLogin(); this._initializeOutLinks(); this._openMigrationModal(); - this._setShutdownService(); + shutdownService.run(); if (WavesApp.isDesktop()) { window.listenMainProcessEvent((type, url) => { @@ -251,10 +251,6 @@ return false; } - _setShutdownService() { - shutdownService.run(); - } - /** * @private */