Wallet/src/js/services/txStatus.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
angular.module('copayApp.services').factory('txStatus', function($modal, lodash, profileService, $timeout, gettext) {
2015-03-06 12:00:10 -03:00
var root = {};
2015-04-27 02:07:26 -03:00
root.notify = function(txp, cb) {
2015-03-06 12:00:10 -03:00
var fc = profileService.focusedClient;
var status = txp.status;
var type;
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 || (action.type == 'accept' && n == 1)) {
type = 'created';
2015-03-06 12:00:10 -03:00
} else if (action.type == 'accept') {
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
}
}
root.openModal(type, cb);
2015-03-06 12:00:10 -03:00
};
root.openModal = function(type, cb) {
2015-03-06 12:00:10 -03:00
var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.type = type;
2015-03-06 12:00:10 -03:00
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
2015-04-27 02:07:26 -03:00
if (cb) $timeout(cb, 100);
2015-03-06 12:00:10 -03:00
};
2015-05-07 19:02:38 -03:00
var modalInstance = $modal.open({
2015-03-06 12:00:10 -03:00
templateUrl: 'views/modals/tx-status.html',
windowClass: 'full popup-tx-status closeModalAnimation',
2015-03-06 12:00:10 -03:00
controller: ModalInstanceCtrl,
});
2015-05-07 19:02:38 -03:00
modalInstance.result.finally(function() {
var m = angular.element(document.getElementsByClassName('reveal-modal'));
2015-05-07 19:15:38 -03:00
m.addClass('animated fadeOutUp');
2015-05-07 19:02:38 -03:00
});
2015-03-06 12:00:10 -03:00
};
return root;
});