copay/old/notificationsService.js

116 lines
3.1 KiB
JavaScript
Raw Normal View History

2015-03-06 07:00:10 -08:00
'use strict';
angular.module('copayApp.services')
.factory('notificationService', function profileServiceFactory($filter, notification, lodash, configService, gettext) {
2015-03-06 07:00:10 -08:00
var root = {};
var groupingTime = 5000;
2015-03-06 07:00:10 -08:00
var lastNotificationOnWallet = {};
root.getLast = function(walletId) {
var last = lastNotificationOnWallet[walletId];
if (!last) return null;
return Date.now() - last.ts < groupingTime ? last : null;
};
root.storeLast = function(notificationData, walletId) {
2015-05-29 08:39:17 -07:00
if (notificationData.type == 'NewAddress')
return;
2015-03-06 07:00:10 -08:00
lastNotificationOnWallet[walletId] = {
creatorId: notificationData.creatorId,
type: notificationData.type,
ts: Date.now(),
};
};
root.shouldSkip = function(notificationData, last) {
if (!last) return false;
// rules...
if (last.type === 'NewTxProposal' &&
notificationData.type === 'TxProposalAcceptedBy')
2015-03-06 07:00:10 -08:00
return true;
if (last.type === 'TxProposalFinallyAccepted' &&
notificationData.type === 'NewOutgoingTx')
2015-03-06 07:00:10 -08:00
return true;
if (last.type === 'TxProposalRejectedBy' &&
notificationData.type === 'TxProposalFinallyRejected')
2015-03-06 07:00:10 -08:00
return true;
return false;
};
root.newBWCNotification = function(notificationData, walletId, walletName) {
var last = root.getLast(walletId);
root.storeLast(notificationData, walletId);
if (root.shouldSkip(notificationData, last))
return;
var config = configService.getSync();
config.colorFor = config.colorFor || {};
var color = config.colorFor[walletId] || '#4A90E2';
2015-05-14 06:39:22 -07:00
var name = config.aliasFor[walletId] || walletName;
2015-03-06 07:00:10 -08:00
switch (notificationData.type) {
case 'NewTxProposal':
notification.new(gettext('New Payment Proposal'),
name, {
color: color
});
2015-03-06 07:00:10 -08:00
break;
case 'TxProposalAcceptedBy':
notification.success(gettext('Payment Proposal Signed by Copayer'),
name, {
color: color
});
2015-03-06 07:00:10 -08:00
break;
case 'TxProposalRejectedBy':
notification.error(gettext('Payment Proposal Rejected by Copayer'),
name, {
color: color
});
2015-03-06 07:00:10 -08:00
break;
case 'TxProposalFinallyRejected':
2015-05-18 20:49:07 -07:00
notification.error(gettext('Payment Proposal Rejected'),
name, {
color: color
});
2015-03-06 07:00:10 -08:00
break;
case 'NewOutgoingTx':
2015-05-29 08:39:17 -07:00
notification.sent(gettext('Payment Sent'),
name, {
color: color
});
2015-03-06 07:00:10 -08:00
break;
case 'NewIncomingTx':
notification.funds(gettext('Funds received'),
name, {
color: color
});
2015-03-06 07:00:10 -08:00
break;
case 'ScanFinished':
notification.success(gettext('Scan Finished'),
name, {
color: color
});
2015-03-06 07:00:10 -08:00
break;
case 'NewCopayer':
// No UX notification
break;
2016-01-13 07:08:13 -08:00
case 'BalanceUpdated':
// No UX notification
break;
2015-03-06 07:00:10 -08:00
}
};
return root;
});