From 1402eea43ecf342c2ad249d6c22329958d27542e Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 4 Feb 2016 10:33:41 -0300 Subject: [PATCH 01/11] display payment expiry time --- public/views/walletHome.html | 3 ++- src/js/controllers/walletHome.js | 33 ++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/public/views/walletHome.html b/public/views/walletHome.html index d33459be6..a34277eb0 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -367,6 +367,7 @@ class="p10" translate> Send All +
@@ -475,7 +476,7 @@ Cancel
- diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 5bbb9ae88..3eef20738 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, isMobile, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, bwsError, confirmDialog, txFormatService, animationService, addressbookService, go, feeService, txService) { +angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $interval, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, isMobile, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, bwsError, confirmDialog, txFormatService, animationService, addressbookService, go, feeService, txSignService) { var self = this; window.ignoreMobilePause = false; @@ -27,6 +27,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi this.showScanner = false; this.addr = {}; this.lockedCurrentFeePerKb = null; + self.paymentExpired = true; var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) { self.setForm(data); @@ -37,6 +38,10 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi self.resetForm(); self.error = gettext('Could not recognize a valid Bitcoin QR Code'); } + + $timeout(function () { + $rootScope.$appply(); + }, 10); }); var disablePaymentUriListener = $rootScope.$on('paymentUri', function(event, uri) { @@ -618,7 +623,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi }); }; - // Send + // Send this.canShowAlternative = function() { return $scope.showAlternative; @@ -673,7 +678,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi if (isCordova && !this.isWindowsPhoneApp) { this.hideMenuBar(what); } - + var self = this; if (isCordova && !this.isWindowsPhoneApp && what == 'address') { getClipboard(function(value) { @@ -877,7 +882,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi }); }, 100); - }; + }; this.acceptTx = function(txp) { var self = this; @@ -975,7 +980,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi $timeout(function() { $rootScope.$digest(); }, 1); - }; + }; this.openPPModal = function(paypro) { $rootScope.modalOpened = true; @@ -1059,11 +1064,27 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi self._paypro = paypro; self.setForm(paypro.toAddress, (paypro.amount * satToUnit).toFixed(self.unitDecimals), paypro.memo); + _countDownPaymentTime(paypro.expires); return cb(); }); }, 1); }; + function _countDownPaymentTime(time){ + self.paymentExpired = false; + // self.timeToExpire = time; + self.timeToExpire = (Math.floor(Date.now()/1000) + 10); + var countDown = $interval(function(){ + self.timeToExpire--; + if(self.timeToExpire <= Math.floor(Date.now() / 1000)){ + self.paymentExpired = true; + self.timeToExpire = null; + self.error = gettext('Cannot send the payment: time to sign expired'); + $interval.cancel(countDown); + } + }, 1000); + }; + this.setFromUri = function(uri) { var self = this; @@ -1135,7 +1156,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi } }; - // History + // History function strip(number) { return (parseFloat(number.toPrecision(12))); From bccadd8708537abb672552fd0de8667e477b9200 Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 4 Feb 2016 12:59:13 -0300 Subject: [PATCH 02/11] fix refreshing values when scanned twice --- src/js/controllers/walletHome.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 3eef20738..f0da81f2c 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -38,10 +38,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi self.resetForm(); self.error = gettext('Could not recognize a valid Bitcoin QR Code'); } - - $timeout(function () { - $rootScope.$appply(); - }, 10); }); var disablePaymentUriListener = $rootScope.$on('paymentUri', function(event, uri) { @@ -952,6 +948,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi this.resetForm = function() { this.resetError(); + self.paymentExpired = true; this._paypro = null; this.lockedCurrentFeePerKb = null; @@ -1079,6 +1076,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi if(self.timeToExpire <= Math.floor(Date.now() / 1000)){ self.paymentExpired = true; self.timeToExpire = null; + self._paypro = null; self.error = gettext('Cannot send the payment: time to sign expired'); $interval.cancel(countDown); } From a962e3a913c6f14f16e5cd31e21931b0e9a0303a Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 4 Feb 2016 13:25:35 -0300 Subject: [PATCH 03/11] disable send button if time is expired --- public/views/walletHome.html | 2 +- src/js/controllers/walletHome.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/public/views/walletHome.html b/public/views/walletHome.html index a34277eb0..65275597c 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -476,7 +476,7 @@ Cancel
- diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index f0da81f2c..176a21621 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -28,6 +28,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi this.addr = {}; this.lockedCurrentFeePerKb = null; self.paymentExpired = true; + self.usePaypro = false; var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) { self.setForm(data); @@ -949,6 +950,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi this.resetForm = function() { this.resetError(); self.paymentExpired = true; + self.usePaypro = false; this._paypro = null; this.lockedCurrentFeePerKb = null; @@ -1068,9 +1070,10 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi }; function _countDownPaymentTime(time){ + self.usePaypro = true; self.paymentExpired = false; - // self.timeToExpire = time; - self.timeToExpire = (Math.floor(Date.now()/1000) + 10); + self.timeToExpire = time; + // self.timeToExpire = (Math.floor(Date.now()/1000) + 10); var countDown = $interval(function(){ self.timeToExpire--; if(self.timeToExpire <= Math.floor(Date.now() / 1000)){ From bcbb0e68d183421e1cbfb259ccc093371e346031 Mon Sep 17 00:00:00 2001 From: Javier Date: Fri, 5 Feb 2016 17:36:25 -0300 Subject: [PATCH 04/11] expiry time in proposal details --- public/views/modals/txp-details.html | 10 +++++----- src/js/controllers/walletHome.js | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/public/views/modals/txp-details.html b/public/views/modals/txp-details.html index 2b8160b00..a72a5ce7f 100644 --- a/public/views/modals/txp-details.html +++ b/public/views/modals/txp-details.html @@ -11,7 +11,7 @@ - - +
@@ -54,7 +54,7 @@
@@ -143,7 +143,7 @@
  • Expires - +
  • @@ -170,7 +170,7 @@ {{ac.copayerName}} ({{'Me'|translate}})
  • -
    +
    diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 176a21621..103eb180c 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -285,6 +285,9 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi var fc = profileService.focusedClient; var currentSpendUnconfirmed = configWallet.spendUnconfirmed; var ModalInstanceCtrl = function($scope, $modalInstance) { + $scope.paymentExpired = false; + $scope.usePaypro = false; + checkPaypro(); $scope.error = null; $scope.copayers = copayers $scope.copayerId = fc.credentials.copayerId; @@ -306,6 +309,21 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi $scope.getShortNetworkName = function() { return fc.credentials.networkName.substring(0, 4); }; + + function checkPaypro() { + if(tx.payProUrl && !isChromeApp){ + fc.fetchPayPro({ + payProUrl: tx.payProUrl, + }, function(err, paypro) { + if (err) return $log.debug(err); + tx.paypro = paypro; + $scope.usePaypro = true; + $scope.paymentExpired = tx.paypro.expires <= Math.floor(Date.now() / 1000); + $scope.$apply(); + }); + } + }; + lodash.each(['TxProposalRejectedBy', 'TxProposalAcceptedBy', 'transactionProposalRemoved', 'TxProposalRemoved', 'NewOutgoingTx', 'UpdateTx'], function(eventName) { $rootScope.$on(eventName, function() { fc.getTx($scope.tx.id, function(err, tx) { @@ -324,9 +342,12 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi var action = lodash.find(tx.actions, { copayerId: fc.credentials.copayerId }); + $scope.tx = txFormatService.processTx(tx); + if (!action && tx.status == 'pending') $scope.tx.pendingForUs = true; + $scope.updateCopayerList(); $scope.$apply(); }); @@ -1073,7 +1094,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi self.usePaypro = true; self.paymentExpired = false; self.timeToExpire = time; - // self.timeToExpire = (Math.floor(Date.now()/1000) + 10); var countDown = $interval(function(){ self.timeToExpire--; if(self.timeToExpire <= Math.floor(Date.now() / 1000)){ From af28406446ce2fff6f302226a3c0f20e5deeea9c Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 10 Feb 2016 12:48:43 -0300 Subject: [PATCH 05/11] replace self -> this --- src/js/controllers/walletHome.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 103eb180c..a894cbc7b 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -27,8 +27,8 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi this.showScanner = false; this.addr = {}; this.lockedCurrentFeePerKb = null; - self.paymentExpired = true; - self.usePaypro = false; + this.paymentExpired = true; + this.usePaypro = false; var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) { self.setForm(data); @@ -970,8 +970,8 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi this.resetForm = function() { this.resetError(); - self.paymentExpired = true; - self.usePaypro = false; + this.paymentExpired = true; + this.usePaypro = false; this._paypro = null; this.lockedCurrentFeePerKb = null; From df9cc658f0a44384fce6757b3a3d28c1a8c11fc4 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 10 Feb 2016 12:59:31 -0300 Subject: [PATCH 06/11] fix translate string --- public/views/walletHome.html | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/public/views/walletHome.html b/public/views/walletHome.html index 65275597c..228b84887 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -361,13 +361,14 @@

    - Send All - +
    + Payment expires + +

    From ed7d55d8ceacc16bc085895b674b391695e561ec Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 10 Feb 2016 13:04:00 -0300 Subject: [PATCH 07/11] fix return on checkPayPro function --- src/js/controllers/walletHome.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index a894cbc7b..d94facbbc 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -315,7 +315,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi fc.fetchPayPro({ payProUrl: tx.payProUrl, }, function(err, paypro) { - if (err) return $log.debug(err); + if (err) return; tx.paypro = paypro; $scope.usePaypro = true; $scope.paymentExpired = tx.paypro.expires <= Math.floor(Date.now() / 1000); From c67d6ff80d54e9aaf93c75460d88684184c0c390 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 10 Feb 2016 15:32:29 -0300 Subject: [PATCH 08/11] fix wording on error text --- src/js/controllers/walletHome.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index d94facbbc..18c2f93ab 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -1090,19 +1090,19 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi }, 1); }; - function _countDownPaymentTime(time){ + function _countDownPaymentTime(time) { self.usePaypro = true; self.paymentExpired = false; self.timeToExpire = time; - var countDown = $interval(function(){ - self.timeToExpire--; - if(self.timeToExpire <= Math.floor(Date.now() / 1000)){ + var countDown = $interval(function() { + if (self.timeToExpire <= Math.floor(Date.now() / 1000)) { self.paymentExpired = true; self.timeToExpire = null; self._paypro = null; - self.error = gettext('Cannot send the payment: time to sign expired'); + self.error = gettext('Cannot sign: The payment request has expired'); $interval.cancel(countDown); } + self.timeToExpire--; }, 1000); }; From 966adbd322da8c2d2069fd4dd4a1790aca5263af Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 10 Feb 2016 16:29:40 -0300 Subject: [PATCH 09/11] display expired time in red text --- public/views/modals/txp-details.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/public/views/modals/txp-details.html b/public/views/modals/txp-details.html index a72a5ce7f..319165808 100644 --- a/public/views/modals/txp-details.html +++ b/public/views/modals/txp-details.html @@ -140,7 +140,13 @@ -
  • +
  • + Expired + + + +
  • +
  • Expires From 256f7218d72861762c1b1be92ea08d8e4ad14176 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 10 Feb 2016 18:26:30 -0300 Subject: [PATCH 10/11] refactor time to expire control --- src/js/controllers/walletHome.js | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 18c2f93ab..bd3d8ea06 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $interval, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, isMobile, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, bwsError, confirmDialog, txFormatService, animationService, addressbookService, go, feeService, txSignService) { +angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $interval, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, isMobile, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, bwsError, confirmDialog, txFormatService, animationService, addressbookService, go, feeService) { var self = this; window.ignoreMobilePause = false; @@ -1084,26 +1084,37 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi self._paypro = paypro; self.setForm(paypro.toAddress, (paypro.amount * satToUnit).toFixed(self.unitDecimals), paypro.memo); - _countDownPaymentTime(paypro.expires); + _paymentTimeControl(paypro.expires); return cb(); }); }, 1); }; - function _countDownPaymentTime(time) { + function _paymentTimeControl(timeToExpire) { self.usePaypro = true; + var now = Math.floor(Date.now() / 1000); + + if (timeToExpire <= now) { + setExpiredPaymentValues(); + return; + } + self.paymentExpired = false; - self.timeToExpire = time; + self.timeToExpire = timeToExpire; var countDown = $interval(function() { - if (self.timeToExpire <= Math.floor(Date.now() / 1000)) { - self.paymentExpired = true; - self.timeToExpire = null; - self._paypro = null; - self.error = gettext('Cannot sign: The payment request has expired'); + if (self.timeToExpire <= now) { + setExpiredPaymentValues(); $interval.cancel(countDown); } - self.timeToExpire--; + self.timeToExpire --; }, 1000); + + function setExpiredPaymentValues() { + self.paymentExpired = true; + self.timeToExpire = null; + self._paypro = null; + self.error = gettext('Cannot sign: The payment request has expired'); + }; }; this.setFromUri = function(uri) { From 8d591ab7abe79d71d228cb733a20982869066dac Mon Sep 17 00:00:00 2001 From: Javier Date: Fri, 19 Feb 2016 13:29:41 -0300 Subject: [PATCH 11/11] refactor --- public/views/modals/txp-details.html | 2 +- public/views/walletHome.html | 6 +++--- src/js/controllers/walletHome.js | 32 +++++++++++++++++----------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/public/views/modals/txp-details.html b/public/views/modals/txp-details.html index 319165808..595f4b563 100644 --- a/public/views/modals/txp-details.html +++ b/public/views/modals/txp-details.html @@ -149,7 +149,7 @@
  • Expires - +
  • diff --git a/public/views/walletHome.html b/public/views/walletHome.html index 228b84887..57c69b762 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -175,7 +175,7 @@
    Updating transaction history. Please stand by.
  • -
    +

    @@ -365,7 +365,7 @@ ng-click="home.sendAll()" translate> Send All -
    +
    Payment expires
    @@ -477,7 +477,7 @@ Cancel
    - diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index bd3d8ea06..744aeda6e 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $interval, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, isMobile, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, bwsError, confirmDialog, txFormatService, animationService, addressbookService, go, feeService) { +angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $interval, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, isMobile, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, bwsError, confirmDialog, txFormatService, animationService, addressbookService, go, feeService, txService) { var self = this; window.ignoreMobilePause = false; @@ -27,8 +27,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi this.showScanner = false; this.addr = {}; this.lockedCurrentFeePerKb = null; - this.paymentExpired = true; - this.usePaypro = false; + this.paymentExpired = false; var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) { self.setForm(data); @@ -285,8 +284,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi var fc = profileService.focusedClient; var currentSpendUnconfirmed = configWallet.spendUnconfirmed; var ModalInstanceCtrl = function($scope, $modalInstance) { - $scope.paymentExpired = false; - $scope.usePaypro = false; + $scope.paymentExpired = null; checkPaypro(); $scope.error = null; $scope.copayers = copayers @@ -295,6 +293,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi $scope.loading = null; $scope.color = fc.backgroundColor; $scope.isShared = fc.credentials.n > 1; + var now = Math.floor(Date.now() / 1000); // ToDo: use tx.customData instead of tx.message if (tx.message === 'Glidera transaction' && isGlidera) { @@ -311,19 +310,31 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi }; function checkPaypro() { - if(tx.payProUrl && !isChromeApp){ + if (tx.payProUrl && !isChromeApp) { fc.fetchPayPro({ payProUrl: tx.payProUrl, }, function(err, paypro) { if (err) return; tx.paypro = paypro; - $scope.usePaypro = true; - $scope.paymentExpired = tx.paypro.expires <= Math.floor(Date.now() / 1000); + $scope.paymentExpired = tx.paypro.expires <= now; + if (!$scope.paymentExpired) + paymentTimeControl(tx.paypro.expires); $scope.$apply(); }); } }; + function paymentTimeControl(timeToExpire) { + $scope.expires = timeToExpire; + var countDown = $interval(function() { + if ($scope.expires <= now) { + $scope.paymentExpired = true; + $interval.cancel(countDown); + } + $scope.expires --; + }, 1000); + }; + lodash.each(['TxProposalRejectedBy', 'TxProposalAcceptedBy', 'transactionProposalRemoved', 'TxProposalRemoved', 'NewOutgoingTx', 'UpdateTx'], function(eventName) { $rootScope.$on(eventName, function() { fc.getTx($scope.tx.id, function(err, tx) { @@ -970,8 +981,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi this.resetForm = function() { this.resetError(); - this.paymentExpired = true; - this.usePaypro = false; + this.paymentExpired = false; this._paypro = null; this.lockedCurrentFeePerKb = null; @@ -1091,7 +1101,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi }; function _paymentTimeControl(timeToExpire) { - self.usePaypro = true; var now = Math.floor(Date.now() / 1000); if (timeToExpire <= now) { @@ -1099,7 +1108,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi return; } - self.paymentExpired = false; self.timeToExpire = timeToExpire; var countDown = $interval(function() { if (self.timeToExpire <= now) {