From 036c37ba8044093bdd4614add386131ebbc18941 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Tue, 17 Jul 2018 16:29:00 -0700 Subject: [PATCH 1/4] List only 1 'syncing to chain' ntfn --- src/action/notification.js | 24 +++++++++++++++--------- test/unit/action/notification.spec.js | 9 +++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/action/notification.js b/src/action/notification.js index 0b128e16a..52991ad9b 100644 --- a/src/action/notification.js +++ b/src/action/notification.js @@ -9,15 +9,21 @@ class NotificationAction { display({ type, msg, wait, err, handler, handlerLbl }) { if (err) log.error(msg, err); - this._store.notifications.push({ - type: type || (err ? 'error' : 'info'), - message: msg, - waiting: wait, - date: new Date(), - handler: handler || (err ? () => this._nav.goCLI() : null), - handlerLbl: handlerLbl || (err ? 'Show error logs' : null), - display: true, - }); + const ntfnCount = this._store.notifications.length; + let prevNtfn = ntfnCount ? this._store.notifications[ntfnCount - 1] : null; + if (prevNtfn && prevNtfn.message === msg) { + prevNtfn.date = new Date(); + } else { + this._store.notifications.push({ + type: type || (err ? 'error' : 'info'), + message: msg, + waiting: wait, + date: new Date(), + handler: handler || (err ? () => this._nav.goCLI() : null), + handlerLbl: handlerLbl || (err ? 'Show error logs' : null), + display: true, + }); + } clearTimeout(this.tdisplay); this.tdisplay = setTimeout(() => this.close(), NOTIFICATION_DELAY); } diff --git a/test/unit/action/notification.spec.js b/test/unit/action/notification.spec.js index 4323d2cd3..0eb32c0cf 100644 --- a/test/unit/action/notification.spec.js +++ b/test/unit/action/notification.spec.js @@ -84,6 +84,15 @@ describe('Action Notification Unit Tests', () => { store.notifications[0].handler(); expect(nav.goCLI, 'was called once'); }); + + it('avoid redundant notifications but update date', async () => { + notification.display({ msg: 'hello' }); + const date = store.notifications[0].date; + await nap(10); + notification.display({ msg: 'hello' }); + expect(store.notifications.length, 'to equal', 1); + expect(store.notifications[0].date, 'not to equal', date); + }); }); describe('close()', () => { From 2558c6eee7faf7c925874cf435dd5da272451bcd Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Tue, 24 Jul 2018 10:02:51 +0200 Subject: [PATCH 2/4] Revert "List only 1 'syncing to chain' ntfn" This reverts commit fc0df24a83348c328ecf5799b7798b405a225dd5. --- src/action/notification.js | 24 +++++++++--------------- test/unit/action/notification.spec.js | 9 --------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/action/notification.js b/src/action/notification.js index 52991ad9b..0b128e16a 100644 --- a/src/action/notification.js +++ b/src/action/notification.js @@ -9,21 +9,15 @@ class NotificationAction { display({ type, msg, wait, err, handler, handlerLbl }) { if (err) log.error(msg, err); - const ntfnCount = this._store.notifications.length; - let prevNtfn = ntfnCount ? this._store.notifications[ntfnCount - 1] : null; - if (prevNtfn && prevNtfn.message === msg) { - prevNtfn.date = new Date(); - } else { - this._store.notifications.push({ - type: type || (err ? 'error' : 'info'), - message: msg, - waiting: wait, - date: new Date(), - handler: handler || (err ? () => this._nav.goCLI() : null), - handlerLbl: handlerLbl || (err ? 'Show error logs' : null), - display: true, - }); - } + this._store.notifications.push({ + type: type || (err ? 'error' : 'info'), + message: msg, + waiting: wait, + date: new Date(), + handler: handler || (err ? () => this._nav.goCLI() : null), + handlerLbl: handlerLbl || (err ? 'Show error logs' : null), + display: true, + }); clearTimeout(this.tdisplay); this.tdisplay = setTimeout(() => this.close(), NOTIFICATION_DELAY); } diff --git a/test/unit/action/notification.spec.js b/test/unit/action/notification.spec.js index 0eb32c0cf..4323d2cd3 100644 --- a/test/unit/action/notification.spec.js +++ b/test/unit/action/notification.spec.js @@ -84,15 +84,6 @@ describe('Action Notification Unit Tests', () => { store.notifications[0].handler(); expect(nav.goCLI, 'was called once'); }); - - it('avoid redundant notifications but update date', async () => { - notification.display({ msg: 'hello' }); - const date = store.notifications[0].date; - await nap(10); - notification.display({ msg: 'hello' }); - expect(store.notifications.length, 'to equal', 1); - expect(store.notifications[0].date, 'not to equal', date); - }); }); describe('close()', () => { From 386a562acff1ed93de68bca0805ab99716386205 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Tue, 24 Jul 2018 10:39:14 +0200 Subject: [PATCH 3/4] List waiting notification only once in notification list --- src/computed/notification.js | 8 +++++++- test/unit/computed/notification.spec.js | 22 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/computed/notification.js b/src/computed/notification.js index 2a5f85043..c99fb13f0 100644 --- a/src/computed/notification.js +++ b/src/computed/notification.js @@ -13,7 +13,13 @@ const ComputedNotification = store => { }), computedNotifications: computed(() => { const { notifications } = store; - const all = notifications ? notifications.slice() : []; + const all = []; + notifications.forEach(n => { + if (n.waiting && all.find(a => a.waiting)) { + return; + } + all.push(n); + }); all.sort((a, b) => b.date.getTime() - a.date.getTime()); all.forEach(n => { n.typeLabel = toCaps(n.type); diff --git a/test/unit/computed/notification.spec.js b/test/unit/computed/notification.spec.js index a359eca06..5a154c69b 100644 --- a/test/unit/computed/notification.spec.js +++ b/test/unit/computed/notification.spec.js @@ -23,10 +23,30 @@ describe('Computed Notification Unit Tests', () => { date: new Date(1528703821406), display: true, }); + store.notifications.push({ + type: 'info', + message: 'Syncing to chain', + date: new Date(1528703821407), + display: true, + waiting: true, + }); + store.notifications.push({ + type: 'info', + message: 'Syncing to chain', + date: new Date(1528703821408), + display: true, + waiting: true, + }); ComputedNotification(store); - expect(store.lastNotification.type, 'to equal', 'error'); + expect(store.lastNotification.type, 'to equal', 'info'); expect(store.displayNotification, 'to equal', true); expect(store.computedNotifications, 'to satisfy', [ + { + typeLabel: 'Info', + message: 'Syncing to chain', + dateLabel: new Date(1528703821407).toLocaleDateString(), + dateTimeLabel: new Date(1528703821407).toLocaleString(), + }, { typeLabel: 'Error', message: 'Oops something went wrong', From 4d9438ffc4890c4d0472d1aa6cb658995f31040a Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Tue, 24 Jul 2018 11:26:44 +0200 Subject: [PATCH 4/4] Display notification count bubble based on computed notifications --- src/computed/notification.js | 5 ++++- src/computed/setting.js | 3 --- test/unit/computed/notification.spec.js | 2 ++ test/unit/computed/setting.spec.js | 7 ------- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/computed/notification.js b/src/computed/notification.js index c99fb13f0..b96add011 100644 --- a/src/computed/notification.js +++ b/src/computed/notification.js @@ -1,5 +1,5 @@ import { computed, extendObservable } from 'mobx'; -import { toCaps } from '../helper'; +import { toCaps, formatNumber } from '../helper'; const ComputedNotification = store => { extendObservable(store, { @@ -28,6 +28,9 @@ const ComputedNotification = store => { }); return all; }), + notificationCountLabel: computed(() => + formatNumber(store.computedNotifications.length) + ), }); }; diff --git a/src/computed/setting.js b/src/computed/setting.js index 833f36137..3f2d12ff0 100644 --- a/src/computed/setting.js +++ b/src/computed/setting.js @@ -6,9 +6,6 @@ const ComputedSetting = store => { extendObservable(store, { selectedUnitLabel: computed(() => getUnitLabel(store.settings.unit)), selectedFiatLabel: computed(() => FIATS[store.settings.fiat].display), - notificationCountLabel: computed(() => - formatNumber(store.notifications.length) - ), satUnitLabel: computed(() => getUnitLabel('sat')), bitUnitLabel: computed(() => getUnitLabel('bit')), btcUnitLabel: computed(() => getUnitLabel('btc')), diff --git a/test/unit/computed/notification.spec.js b/test/unit/computed/notification.spec.js index 5a154c69b..951fb85f2 100644 --- a/test/unit/computed/notification.spec.js +++ b/test/unit/computed/notification.spec.js @@ -14,6 +14,7 @@ describe('Computed Notification Unit Tests', () => { expect(store.lastNotification, 'to equal', null); expect(store.displayNotification, 'to equal', false); expect(store.computedNotifications, 'to equal', []); + expect(store.notificationCountLabel, 'to equal', '0'); }); it('should set notification attributes', () => { @@ -54,6 +55,7 @@ describe('Computed Notification Unit Tests', () => { dateTimeLabel: new Date(1528703821406).toLocaleString(), }, ]); + expect(store.notificationCountLabel, 'to equal', '2'); }); }); }); diff --git a/test/unit/computed/setting.spec.js b/test/unit/computed/setting.spec.js index 5cc9f106b..dd5551c96 100644 --- a/test/unit/computed/setting.spec.js +++ b/test/unit/computed/setting.spec.js @@ -13,7 +13,6 @@ describe('Computed Settings Unit Tests', () => { ComputedSetting(store); expect(store.selectedUnitLabel, 'to equal', 'Bitcoin'); expect(store.selectedFiatLabel, 'to equal', 'US Dollar'); - expect(store.notificationCountLabel, 'to equal', '0'); expect(store.satUnitLabel, 'to be ok'); expect(store.bitUnitLabel, 'to be ok'); expect(store.btcUnitLabel, 'to be ok'); @@ -31,11 +30,5 @@ describe('Computed Settings Unit Tests', () => { /Satoshi {3}\(0[,.]00000001 BTC\)/ ); }); - - it('should display notification count as a string', () => { - store.notifications.push({ type: 'error' }); - ComputedSetting(store); - expect(store.notificationCountLabel, 'to equal', '1'); - }); }); });