Merge pull request #4038 from JDonadio/fix/payment-expired-02

Stop counter when cancel is pressed
This commit is contained in:
Matias Alejo Garcia 2016-04-04 14:27:03 -03:00
commit 346f78c34c
2 changed files with 27 additions and 13 deletions

View File

@ -504,7 +504,7 @@
<a fast-click callback-fn="home.resetForm(sendForm)" class="button expand outline dark-gray round" translate>Cancel</a> <a fast-click callback-fn="home.resetForm(sendForm)" class="button expand outline dark-gray round" translate>Cancel</a>
</div> </div>
<div class="columns" ng-class="{'small-6 medium-6 large-6':(home._paypro || home.lockAddress || home.lockAmount)}"> <div class="columns" ng-class="{'small-6 medium-6 large-6':(home._paypro || home.lockAddress || home.lockAmount)}">
<button class="button black round expand" ng-disabled="sendForm.$invalid || home.blockUx || index.isOffline" <button class="button black round expand" ng-disabled="sendForm.$invalid || home.blockUx || index.isOffline || home.paymentExpired"
ng-style="{'background-color':index.backgroundColor}" fast-click callback-fn="home.submitForm()" translate> ng-style="{'background-color':index.backgroundColor}" fast-click callback-fn="home.submitForm()" translate>
Send Send
</button> </button>

View File

@ -23,6 +23,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
ret.addresses = []; ret.addresses = [];
ret.isMobile = isMobile.any(); ret.isMobile = isMobile.any();
ret.isWindowsPhoneApp = isMobile.Windows() && isCordova; ret.isWindowsPhoneApp = isMobile.Windows() && isCordova;
ret.countDown = null;
var vanillaScope = ret; var vanillaScope = ret;
var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) { var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) {
@ -304,6 +305,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
// only determined by the tx.message // only determined by the tx.message
this.openTxpModal = function(tx, copayers, isGlidera) { this.openTxpModal = function(tx, copayers, isGlidera) {
$rootScope.modalOpened = true; $rootScope.modalOpened = true;
var self = this;
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
var currentSpendUnconfirmed = configWallet.spendUnconfirmed; var currentSpendUnconfirmed = configWallet.spendUnconfirmed;
var ModalInstanceCtrl = function($scope, $modalInstance) { var ModalInstanceCtrl = function($scope, $modalInstance) {
@ -346,18 +348,23 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
function paymentTimeControl(expirationTime) { function paymentTimeControl(expirationTime) {
$scope.paymentExpired = false; $scope.paymentExpired = false;
var countDown;
setExpirationTime(); setExpirationTime();
countDown = $interval(function() {
self.countDown = $interval(function() {
setExpirationTime(); setExpirationTime();
}, 1000); }, 1000);
function setExpirationTime() { function setExpirationTime() {
if (moment().isAfter(expirationTime * 1000)) { var now = Math.floor(Date.now() / 1000);
if (now > expirationTime) {
$scope.paymentExpired = true; $scope.paymentExpired = true;
if (countDown) $interval.cancel(countDown); if (self.countDown) $interval.cancel(self.countDown);
return;
} }
$scope.expires = moment(expirationTime * 1000).fromNow(); var totalSecs = expirationTime - now;
var m = Math.floor(totalSecs / 60);
var s = totalSecs % 60;
$scope.expires = ('0' + m).slice(-2) + ":" + ('0' + s).slice(-2);
}; };
}; };
@ -994,6 +1001,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.resetForm = function() { this.resetForm = function() {
this.resetError(); this.resetError();
if (this.countDown) $interval.cancel(this.countDown);
this._paypro = null; this._paypro = null;
this.lockedCurrentFeePerKb = null; this.lockedCurrentFeePerKb = null;
@ -1114,25 +1122,31 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
function _paymentTimeControl(expirationTime) { function _paymentTimeControl(expirationTime) {
self.paymentExpired = false; self.paymentExpired = false;
var countDown;
setExpirationTime(); setExpirationTime();
countDown = $interval(function() {
self.countDown = $interval(function() {
setExpirationTime(); setExpirationTime();
}, 1000); }, 1000);
function setExpirationTime() { function setExpirationTime() {
if (moment().isAfter(expirationTime * 1000)) { var now = Math.floor(Date.now() / 1000);
setExpiredPaymentValues(); if (now > expirationTime) {
if (countDown) $interval.cancel(countDown); setExpiredValues();
return;
} }
self.remainingTimeStr = moment(expirationTime * 1000).fromNow();
var totalSecs = expirationTime - now;
var m = Math.floor(totalSecs / 60);
var s = totalSecs % 60;
self.remainingTimeStr = ('0' + m).slice(-2) + ":" + ('0' + s).slice(-2);
}; };
function setExpiredPaymentValues() { function setExpiredValues() {
self.paymentExpired = true; self.paymentExpired = true;
self.remainingTimeStr = null; self.remainingTimeStr = null;
self._paypro = null; self._paypro = null;
self.error = gettext('Cannot sign: The payment request has expired'); self.error = gettext('Cannot sign: The payment request has expired');
if (self.countDown) $interval.cancel(self.countDown);
}; };
}; };