Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 38100c6

Browse files
Merge pull request #458 from lightninglabs/list-single-syncing-ntfn
List only 1 'syncing to chain' ntfn
2 parents 762a801 + 4d9438f commit 38100c6

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

src/computed/notification.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computed, extendObservable } from 'mobx';
2-
import { toCaps } from '../helper';
2+
import { toCaps, formatNumber } from '../helper';
33

44
const ComputedNotification = store => {
55
extendObservable(store, {
@@ -13,7 +13,13 @@ const ComputedNotification = store => {
1313
}),
1414
computedNotifications: computed(() => {
1515
const { notifications } = store;
16-
const all = notifications ? notifications.slice() : [];
16+
const all = [];
17+
notifications.forEach(n => {
18+
if (n.waiting && all.find(a => a.waiting)) {
19+
return;
20+
}
21+
all.push(n);
22+
});
1723
all.sort((a, b) => b.date.getTime() - a.date.getTime());
1824
all.forEach(n => {
1925
n.typeLabel = toCaps(n.type);
@@ -22,6 +28,9 @@ const ComputedNotification = store => {
2228
});
2329
return all;
2430
}),
31+
notificationCountLabel: computed(() =>
32+
formatNumber(store.computedNotifications.length)
33+
),
2534
});
2635
};
2736

src/computed/setting.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ const ComputedSetting = store => {
66
extendObservable(store, {
77
selectedUnitLabel: computed(() => getUnitLabel(store.settings.unit)),
88
selectedFiatLabel: computed(() => FIATS[store.settings.fiat].display),
9-
notificationCountLabel: computed(() =>
10-
formatNumber(store.notifications.length)
11-
),
129
satUnitLabel: computed(() => getUnitLabel('sat')),
1310
bitUnitLabel: computed(() => getUnitLabel('bit')),
1411
btcUnitLabel: computed(() => getUnitLabel('btc')),

test/unit/computed/notification.spec.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('Computed Notification Unit Tests', () => {
1414
expect(store.lastNotification, 'to equal', null);
1515
expect(store.displayNotification, 'to equal', false);
1616
expect(store.computedNotifications, 'to equal', []);
17+
expect(store.notificationCountLabel, 'to equal', '0');
1718
});
1819

1920
it('should set notification attributes', () => {
@@ -23,17 +24,38 @@ describe('Computed Notification Unit Tests', () => {
2324
date: new Date(1528703821406),
2425
display: true,
2526
});
27+
store.notifications.push({
28+
type: 'info',
29+
message: 'Syncing to chain',
30+
date: new Date(1528703821407),
31+
display: true,
32+
waiting: true,
33+
});
34+
store.notifications.push({
35+
type: 'info',
36+
message: 'Syncing to chain',
37+
date: new Date(1528703821408),
38+
display: true,
39+
waiting: true,
40+
});
2641
ComputedNotification(store);
27-
expect(store.lastNotification.type, 'to equal', 'error');
42+
expect(store.lastNotification.type, 'to equal', 'info');
2843
expect(store.displayNotification, 'to equal', true);
2944
expect(store.computedNotifications, 'to satisfy', [
45+
{
46+
typeLabel: 'Info',
47+
message: 'Syncing to chain',
48+
dateLabel: new Date(1528703821407).toLocaleDateString(),
49+
dateTimeLabel: new Date(1528703821407).toLocaleString(),
50+
},
3051
{
3152
typeLabel: 'Error',
3253
message: 'Oops something went wrong',
3354
dateLabel: new Date(1528703821406).toLocaleDateString(),
3455
dateTimeLabel: new Date(1528703821406).toLocaleString(),
3556
},
3657
]);
58+
expect(store.notificationCountLabel, 'to equal', '2');
3759
});
3860
});
3961
});

test/unit/computed/setting.spec.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ describe('Computed Settings Unit Tests', () => {
1313
ComputedSetting(store);
1414
expect(store.selectedUnitLabel, 'to equal', 'Bitcoin');
1515
expect(store.selectedFiatLabel, 'to equal', 'US Dollar');
16-
expect(store.notificationCountLabel, 'to equal', '0');
1716
expect(store.satUnitLabel, 'to be ok');
1817
expect(store.bitUnitLabel, 'to be ok');
1918
expect(store.btcUnitLabel, 'to be ok');
@@ -31,11 +30,5 @@ describe('Computed Settings Unit Tests', () => {
3130
/Satoshi {3}\(0[,.]00000001 BTC\)/
3231
);
3332
});
34-
35-
it('should display notification count as a string', () => {
36-
store.notifications.push({ type: 'error' });
37-
ComputedSetting(store);
38-
expect(store.notificationCountLabel, 'to equal', '1');
39-
});
4033
});
4134
});

0 commit comments

Comments
 (0)