2015-03-06 12:00:10 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-08-19 18:03:25 -03:00
|
|
|
angular.module('copayApp.services').factory('txStatus', function($stateParams, 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
|
|
|
|
2016-06-16 14:57:30 -03:00
|
|
|
root.notify = function(txp) {
|
2016-08-19 13:09:27 -03:00
|
|
|
var wallet = profileService.getWallet($stateParams.walletId);
|
2015-03-06 12:00:10 -03:00
|
|
|
var status = txp.status;
|
2015-05-18 16:21:36 -03:00
|
|
|
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') {
|
2015-05-18 16:21:36 -03:00
|
|
|
type = 'broadcasted';
|
2015-04-27 02:07:26 -03:00
|
|
|
} else {
|
2015-05-18 16:21:36 -03:00
|
|
|
|
|
|
|
|
var n = txp.actions.length;
|
2015-03-06 12:00:10 -03:00
|
|
|
var action = lodash.find(txp.actions, {
|
2016-08-19 13:09:27 -03:00
|
|
|
copayerId: wallet.credentials.copayerId
|
2015-03-06 12:00:10 -03:00
|
|
|
});
|
2015-05-18 16:21:36 -03:00
|
|
|
|
2016-06-16 14:57:30 -03:00
|
|
|
if (!action) {
|
2015-05-18 16:21:36 -03:00
|
|
|
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?
|
2016-06-16 14:57:30 -03:00
|
|
|
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') {
|
2015-05-18 16:21:36 -03:00
|
|
|
type = 'rejected';
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error('Unknown type:' + type);
|
2015-03-06 12:00:10 -03:00
|
|
|
}
|
|
|
|
|
}
|
2016-06-16 14:57:30 -03:00
|
|
|
return type;
|
2015-03-06 12:00:10 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return root;
|
|
|
|
|
});
|