Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/computed/notification.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { computed, extendObservable } from 'mobx';
import { toCaps } from '../helper';
import { toCaps, formatNumber } from '../helper';

const ComputedNotification = store => {
extendObservable(store, {
Expand All @@ -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);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This displays only the first waiting notification.

all.sort((a, b) => b.date.getTime() - a.date.getTime());
all.forEach(n => {
n.typeLabel = toCaps(n.type);
Expand All @@ -22,6 +28,9 @@ const ComputedNotification = store => {
});
return all;
}),
notificationCountLabel: computed(() =>
formatNumber(store.computedNotifications.length)
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also moved this here to be computed based on the computedNotifications list size.

});
};

Expand Down
3 changes: 0 additions & 3 deletions src/computed/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down
24 changes: 23 additions & 1 deletion test/unit/computed/notification.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -23,17 +24,38 @@ describe('Computed Notification Unit Tests', () => {
date: new Date(1528703821406),
display: true,
});
store.notifications.push({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went in to add this test, I see you've already added it 💯

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',
dateLabel: new Date(1528703821406).toLocaleDateString(),
dateTimeLabel: new Date(1528703821406).toLocaleString(),
},
]);
expect(store.notificationCountLabel, 'to equal', '2');
});
});
});
7 changes: 0 additions & 7 deletions test/unit/computed/setting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
});
});
});