From a70e7e61a48fd39e2d2302a062bff0ff2575cfa1 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 9 Dec 2014 15:13:17 -0300 Subject: [PATCH] add txStatus service --- TODO | 5 +-- js/controllers/homeWallet.js | 31 ++++------------ js/controllers/send.js | 30 ++++----------- js/services/txStatus.js | 39 +++++++++++++++++++ views/modals/tx-details.html | 11 +++--- views/modals/txp-details.html | 70 +++++++++++++++++++++++++++++++++++ 6 files changed, 130 insertions(+), 56 deletions(-) create mode 100644 js/services/txStatus.js create mode 100644 views/modals/txp-details.html diff --git a/TODO b/TODO index 809f8701e..6ee9401cb 100644 --- a/TODO +++ b/TODO @@ -1,4 +1 @@ -- join. on walletComplete! -- paypro fetch-> return TIMEOUT -- yellow lock on paypro -- attack: change paypro ->no! in is cached +- addressbock diff --git a/js/controllers/homeWallet.js b/js/controllers/homeWallet.js index ee67815a5..091e5f731 100644 --- a/js/controllers/homeWallet.js +++ b/js/controllers/homeWallet.js @@ -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, }); diff --git a/js/controllers/send.js b/js/controllers/send.js index 9250b3421..74a2e91bb 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -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); }); }; - }); diff --git a/js/services/txStatus.js b/js/services/txStatus.js new file mode 100644 index 000000000..a5a539345 --- /dev/null +++ b/js/services/txStatus.js @@ -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; +}); diff --git a/views/modals/tx-details.html b/views/modals/tx-details.html index 2bfbba6df..ac52b1099 100644 --- a/views/modals/tx-details.html +++ b/views/modals/tx-details.html @@ -31,11 +31,11 @@

Transaction Details

-
ID: {{btx.txid}}
-
- +
ID: {{btx.txid}}
+
+ - [] + []
@@ -83,12 +83,11 @@
- diff --git a/views/modals/txp-details.html b/views/modals/txp-details.html new file mode 100644 index 000000000..1ada9656d --- /dev/null +++ b/views/modals/txp-details.html @@ -0,0 +1,70 @@ + +× + +

Transaction Proposal Details

+ +
+
+ {{out.value}} {{$root.wallet.settings.unitName}} + + {{out.alternativeAmount}} {{out.alternativeIsoCode}} + +
+
+ +
+
+
+ {{tx.merchant.domain}} + {{tx.merchant.domain}} + +
+ +
+ +
{{tx.comment}}
+ +
+
+ + + [] +
+ +
+ + To: + + {{tx.merchant.domain}} + {{tx.merchant.domain}} + + + + {{tx.labelTo || tx.addressTo}} + + +
+ +
+ {{tx.merchant.pr.pd.memo}} +
+ +
+ Copayers Signatures +
    +
  • + + + + + + + + + {{c.cId === $root.wallet.getMyCopayerId() ? 'Me' : $root.wallet.publicKeyRing.nicknameForCopayer(c.cId)}} +
  • +
+
+
+ +