'use strict';

angular.module('copayApp.services').factory('txStatus', function($modal, lodash, profileService, $timeout, gettext) {
  var root = {};

  root.notify = function(txp, cb) {
    var fc = profileService.focusedClient;
    var status = txp.status;
    var type;

    if (status == 'broadcasted') {
      type = 'broadcasted';
    } else {

      var n = txp.actions.length;
      var action = lodash.find(txp.actions, {
        copayerId: fc.credentials.copayerId
      });

      if (!action || (action.type == 'accept' && n == 1)) {
        type = 'created';
      } else if (action.type == 'accept') {
        type = 'accepted';
      } else if (action.type == 'reject') {
        type = 'rejected';
      } else {
        throw new Error('Unknown type:' + type);
      }
    }

    root.openModal(type, cb);
  };

  root.openModal = function(type, cb) {
    var ModalInstanceCtrl = function($scope, $modalInstance) {
      $scope.type = type;
      $scope.cancel = function() {
        $modalInstance.dismiss('cancel');
      };
      if (cb) $timeout(cb, 100);
    };
    var modalInstance = $modal.open({
      templateUrl: 'views/modals/tx-status.html',
      windowClass: 'full popup-tx-status closeModalAnimation',
      controller: ModalInstanceCtrl,
    });

    modalInstance.result.finally(function() {
      var m = angular.element(document.getElementsByClassName('reveal-modal'));
      m.addClass('animated fadeOutUp');
    });
  };

  return root;
});

@@ -265,16 +265,45 @@
 ar type;
+%0A    var INMEDIATE_SECS = 10;
 %0A%0A    if
@@ -529,48 +529,10 @@
 tion
- %7C%7C (action.type == 'accept' && n == 1)
 )
+ 
  %7B%0A 
@@ -596,24 +596,198 @@
 'accept') %7B%0A
+        // created and accepted at the same time?%0A        if ( n == 1 && action.createdOn - txp.createdOn %3C INMEDIATE_SECS ) %7B%0A          type = 'created';%0A        %7D else %7B%0A  
         type
@@ -797,24 +797,34 @@
 'accepted';%0A
+        %7D%0A
       %7D else

fix notification