Wallet/src/js/services/txStatus.js

41 lines
1 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
angular.module('copayApp.services').factory('txStatus', function(lodash, profileService, $timeout, platformInfo) {
2015-03-06 12:00:10 -03:00
var root = {};
2016-05-31 16:52:38 -03:00
var isCordova = platformInfo.isCordova;
2015-03-06 12:00:10 -03:00
root.notify = function(txp) {
2015-03-06 12:00:10 -03:00
var fc = profileService.focusedClient;
var status = txp.status;
var type;
2015-07-16 11:43:26 -03:00
var INMEDIATE_SECS = 10;
2015-04-27 02:07:26 -03:00
2015-03-06 12:00:10 -03:00
if (status == 'broadcasted') {
type = 'broadcasted';
2015-04-27 02:07:26 -03:00
} else {
var n = txp.actions.length;
2015-03-06 12:00:10 -03:00
var action = lodash.find(txp.actions, {
copayerId: fc.credentials.copayerId
});
if (!action) {
type = 'created';
2015-03-06 12:00:10 -03:00
} else if (action.type == 'accept') {
2015-07-16 11:43:26 -03:00
// created and accepted at the same time?
if (n == 1 && action.createdOn - txp.createdOn < INMEDIATE_SECS) {
2015-07-16 11:43:26 -03:00
type = 'created';
} else {
type = 'accepted';
}
2015-03-06 12:00:10 -03:00
} else if (action.type == 'reject') {
type = 'rejected';
} else {
throw new Error('Unknown type:' + type);
2015-03-06 12:00:10 -03:00
}
}
return type;
2015-03-06 12:00:10 -03:00
};
return root;
});