diff --git a/src/computed/notification.js b/src/computed/notification.js index 2a5f85043..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, { @@ -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); @@ -22,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 a359eca06..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', () => { @@ -23,10 +24,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', @@ -34,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'); - }); }); });