add txStatus service

This commit is contained in:
Matias Alejo Garcia 2014-12-09 15:13:17 -03:00
commit a70e7e61a4
6 changed files with 130 additions and 56 deletions

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope, $timeout, $filter, $modal, rateService, notification, identityService) {
angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope, $timeout, $filter, $modal, rateService, notification, txStatus, identityService) {
$scope.initHome = function() {
var w = $rootScope.wallet;
@ -44,23 +44,7 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi
}
});
// TODO duplicated on controller send. move to a service.
$scope.notifyStatus = function(status) {
if (status == copay.Wallet.TX_BROADCASTED)
notification.success('Success', 'Transaction broadcasted!');
else if (status == copay.Wallet.TX_PROPOSAL_SENT)
notification.info('Success', 'Transaction proposal created');
else if (status == copay.Wallet.TX_SIGNED)
notification.success('Success', 'Transaction proposal was signed');
else if (status == copay.Wallet.TX_SIGNED_AND_BROADCASTED)
notification.success('Success', 'Transaction signed and broadcasted!');
else
notification.error('Error', 'Unknown error occured');
};
$scope.$on("$destroy", function() {
$scope.$on("$destroy", function() {
var w = $rootScope.wallet;
if (w) {
removeWatch();
@ -113,7 +97,8 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi
$scope.error = $scope.success = null;
w.signAndSend(ntxid, function(err, id, status) {
$scope.loading = false;
$scope.notifyStatus(status);
if (!txStatus.notify(status))
$scope.error = status;
_updateTxs();
});
};
@ -121,14 +106,14 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi
$scope.reject = function(ntxid) {
var w = $rootScope.wallet;
w.reject(ntxid);
notification.warning('Transaction rejected', 'You rejected the transaction successfully');
txStatus.notify('txRejected');
_updateTxs();
};
$scope.openTxModal = function(btx) {
$scope.openTxModal = function(tx) {
var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.btx = btx;
$scope.tx = tx;
$scope.getShortNetworkName = function() {
var w = $rootScope.wallet;
@ -141,7 +126,7 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi
};
$modal.open({
templateUrl: 'views/modals/tx-details.html',
templateUrl: 'views/modals/txp-details.html',
windowClass: 'tiny',
controller: ModalInstanceCtrl,
});

View file

@ -3,7 +3,7 @@ var bitcore = require('bitcore');
var preconditions = require('preconditions').singleton();
angular.module('copayApp.controllers').controller('SendController',
function($scope, $rootScope, $window, $timeout, $modal, $filter, notification, isMobile, rateService) {
function($scope, $rootScope, $window, $timeout, $modal, $filter, notification, isMobile, rateService, txStatus) {
var satToUnit, unitToSat, w;
@ -250,7 +250,6 @@ angular.module('copayApp.controllers').controller('SendController',
qrcode.callback = function(data) {
_scanStop();
$scope.$apply(function() {
$scope.sendForm.address.$setViewValue(data);
$scope.sendForm.address.$render();
@ -389,7 +388,10 @@ angular.module('copayApp.controllers').controller('SendController',
form.address.$setViewValue('');
form.address.$render();
}
$scope.notifyStatus(status);
if (!txStatus.notify(status))
$scope.error = status;
$timeout(function() {
$rootScope.$digest();
}, 1);
@ -414,23 +416,8 @@ angular.module('copayApp.controllers').controller('SendController',
});
};
$scope.openTxStatusModal = function(statusStr) {
var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.statusStr = statusStr;
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
};
$modal.open({
templateUrl: 'views/modals/tx-status.html',
windowClass: 'tiny',
controller: ModalInstanceCtrl,
});
};
$scope.setFromPayPro = function(uri) {
console.log('[send.js.391:uri:]', uri); //TODO
$scope.fetchingURL = uri;
$scope.loading = true;
@ -478,9 +465,6 @@ angular.module('copayApp.controllers').controller('SendController',
};
$scope.onAddressChange = function(value) {
var addr;
console.log('[send.js.391:value:]', value); //TODO
$scope.error = $scope.success = null;
if (!value) return '';
@ -489,6 +473,7 @@ angular.module('copayApp.controllers').controller('SendController',
} else if (/^https?:\/\//.test(value)) {
return $scope.setFromPayPro(value);
}
return value;
};
@ -558,8 +543,7 @@ angular.module('copayApp.controllers').controller('SendController',
});
modalInstance.result.then(function(addr) {
$scope._address = addr;
$scope.setForm(addr);
});
};
});

39
js/services/txStatus.js Normal file
View file

@ -0,0 +1,39 @@
'use strict';
angular.module('copayApp.services').factory('txStatus', function($modal) {
var root = {};
root.notify = function(status) {
var msg;
if (status == copay.Wallet.TX_BROADCASTED)
msg = 'Transaction broadcasted!';
else if (status == copay.Wallet.TX_PROPOSAL_SENT)
msg = 'Transaction proposal created';
else if (status == copay.Wallet.TX_SIGNED)
msg = 'Transaction proposal was signed';
else if (status == copay.Wallet.TX_SIGNED_AND_BROADCASTED)
msg = 'Transaction signed and broadcasted!';
else if (status == 'txRejected')
msg = 'Transaction was rejected!';
if (msg)
root.openModal(msg);
return msg ? true : false;
};
root.openModal = function(statusStr) {
var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.statusStr = statusStr;
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
};
$modal.open({
templateUrl: 'views/modals/tx-status.html',
windowClass: 'tiny',
controller: ModalInstanceCtrl,
});
};
return root;
});