Merge pull request #3860 from JDonadio/fix/payment-expired

Expiry time - paypro
This commit is contained in:
Matias Alejo Garcia 2016-02-19 17:36:28 -03:00
commit fe2c02ccc6
3 changed files with 87 additions and 18 deletions

View file

@ -11,7 +11,7 @@
</h1> </h1>
</section> </section>
</nav> </nav>
<div class="modal-content fix-modals-touch" <div class="modal-content fix-modals-touch"
ng-swipe-disable-mouse ng-swipe-disable-mouse
ng-swipe-right="cancel()" ng-swipe-right="cancel()"
ng-init="updateCopayerList()"> ng-init="updateCopayerList()">
@ -29,7 +29,7 @@
</span> </span>
</span> </span>
</div> </div>
<div class="oh"> <div class="oh">
<div class="box-notification" ng-show="error"> <div class="box-notification" ng-show="error">
<span class="text-warning size-14"> <span class="text-warning size-14">
@ -54,7 +54,7 @@
<div class="large-6 medium-6 small-6 columns text-right" ng-show="canSign"> <div class="large-6 medium-6 small-6 columns text-right" ng-show="canSign">
<button class="button primary round expand" ng-click="sign(tx)" <button class="button primary round expand" ng-click="sign(tx)"
ng-style="{'background-color':color}" ng-style="{'background-color':color}"
ng-disabled="loading"> ng-disabled="loading || (paymentExpired && usePaypro)">
<i class="fi-check"></i> <i class="fi-check"></i>
<span translate>Accept</span> <span translate>Accept</span>
</button> </button>
@ -140,10 +140,16 @@
<contact address="{{tx.toAddress}}" ng-hide="tx.merchant"></contact> <contact address="{{tx.toAddress}}" ng-hide="tx.merchant"></contact>
</span> </span>
</li> </li>
<li class="line-b p10"> <li class="line-b p10" ng-if="paymentExpired">
<span class="text-gray" translate>Expired</span>
<span class="right text-alert">
<time>{{tx.paypro.expires * 1000 | amTimeAgo }}</time>
</span>
</li>
<li class="line-b p10" ng-if="!paymentExpired">
<span class="text-gray" translate>Expires</span> <span class="text-gray" translate>Expires</span>
<span class="right"> <span class="right">
<time>{{tx.paypro.expirationDate | amTimeAgo }}</time> <time>{{expires * 1000 | amTimeAgo }}</time>
</span> </span>
</li> </li>
<li class="line-b p10"> <li class="line-b p10">
@ -170,7 +176,7 @@
{{ac.copayerName}} <span ng-if="ac.copayerId == copayerId">({{'Me'|translate}})</span> {{ac.copayerName}} <span ng-if="ac.copayerId == copayerId">({{'Me'|translate}})</span>
</li> </li>
</ul> </ul>
</div> </div>
<div class="columns text-center m20t" ng-if="tx.canBeRemoved || (tx.status == 'accepted' && !tx.broadcastedOn)"> <div class="columns text-center m20t" ng-if="tx.canBeRemoved || (tx.status == 'accepted' && !tx.broadcastedOn)">
<div class="text-gray size-12 m20b" ng-show="!tx.isGlidera && isShared" translate> <div class="text-gray size-12 m20b" ng-show="!tx.isGlidera && isShared" translate>

View file

@ -175,7 +175,7 @@
<div translate>Updating transaction history. Please stand by.</div> <div translate>Updating transaction history. Please stand by.</div>
</div> </div>
</div> </div>
</div> </div>
<div class="oh pr" ng-show="index.txHistory[0]"> <div class="oh pr" ng-show="index.txHistory[0]">
<h4 class="title m0"> <h4 class="title m0">
@ -361,12 +361,14 @@
<div class="pr p25b"> <div class="pr p25b">
<h4 class="title m0"> <h4 class="title m0">
<available-balance></available-balance> <available-balance></available-balance>
<a <a ng-show="!home.lockedCurrentFeePerKb && index.feeToSendMaxStr && index.availableBalanceSat > 0 && !home.blockUx && !home.lockAmount"
ng-show="!home.lockedCurrentFeePerKb && index.feeToSendMaxStr && index.availableBalanceSat > 0 && !home.blockUx && !home.lockAmount" ng-click="home.sendAll()"
ng-click="home.sendAll()"
class="p10"
translate> Send All translate> Send All
</a> </a>
<div ng-show="!home.paymentExpired && home._paypro">
<span translate>Payment expires</span>
<time> {{home.timeToExpire * 1000 | amTimeAgo}}</time>
</div>
</h4> </h4>
<div class="camera-icon" ng-show="index.isComplete"> <div class="camera-icon" ng-show="index.isComplete">
<qr-scanner on-scan="home.onQrCodeScanned(data)"></qr-scanner> <qr-scanner on-scan="home.onQrCodeScanned(data)"></qr-scanner>
@ -475,7 +477,7 @@
<a ng-click="home.resetForm(sendForm)" class="button expand outline dark-gray round" translate>Cancel</a> <a ng-click="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 type="submit" class="button black round expand" ng-disabled="sendForm.$invalid || home.blockUx || index.isOffline" <button type="submit" class="button black round expand" ng-disabled="sendForm.$invalid || home.blockUx || index.isOffline || (home.paymentExpired && home._paypro)"
ng-style="{'background-color':index.backgroundColor}" translate> ng-style="{'background-color':index.backgroundColor}" translate>
Send Send
</button> </button>

View file

@ -1,6 +1,6 @@
'use strict'; '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, txService) {
var self = this; var self = this;
window.ignoreMobilePause = false; window.ignoreMobilePause = false;
@ -27,6 +27,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.showScanner = false; this.showScanner = false;
this.addr = {}; this.addr = {};
this.lockedCurrentFeePerKb = null; this.lockedCurrentFeePerKb = null;
this.paymentExpired = false;
var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) { var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) {
self.setForm(data); self.setForm(data);
@ -283,6 +284,8 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
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) {
$scope.paymentExpired = null;
checkPaypro();
$scope.error = null; $scope.error = null;
$scope.copayers = copayers $scope.copayers = copayers
$scope.copayerId = fc.credentials.copayerId; $scope.copayerId = fc.credentials.copayerId;
@ -290,6 +293,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$scope.loading = null; $scope.loading = null;
$scope.color = fc.backgroundColor; $scope.color = fc.backgroundColor;
$scope.isShared = fc.credentials.n > 1; $scope.isShared = fc.credentials.n > 1;
var now = Math.floor(Date.now() / 1000);
// ToDo: use tx.customData instead of tx.message // ToDo: use tx.customData instead of tx.message
if (tx.message === 'Glidera transaction' && isGlidera) { if (tx.message === 'Glidera transaction' && isGlidera) {
@ -304,6 +308,33 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$scope.getShortNetworkName = function() { $scope.getShortNetworkName = function() {
return fc.credentials.networkName.substring(0, 4); return fc.credentials.networkName.substring(0, 4);
}; };
function checkPaypro() {
if (tx.payProUrl && !isChromeApp) {
fc.fetchPayPro({
payProUrl: tx.payProUrl,
}, function(err, paypro) {
if (err) return;
tx.paypro = paypro;
$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) { lodash.each(['TxProposalRejectedBy', 'TxProposalAcceptedBy', 'transactionProposalRemoved', 'TxProposalRemoved', 'NewOutgoingTx', 'UpdateTx'], function(eventName) {
$rootScope.$on(eventName, function() { $rootScope.$on(eventName, function() {
fc.getTx($scope.tx.id, function(err, tx) { fc.getTx($scope.tx.id, function(err, tx) {
@ -322,9 +353,12 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
var action = lodash.find(tx.actions, { var action = lodash.find(tx.actions, {
copayerId: fc.credentials.copayerId copayerId: fc.credentials.copayerId
}); });
$scope.tx = txFormatService.processTx(tx); $scope.tx = txFormatService.processTx(tx);
if (!action && tx.status == 'pending') if (!action && tx.status == 'pending')
$scope.tx.pendingForUs = true; $scope.tx.pendingForUs = true;
$scope.updateCopayerList(); $scope.updateCopayerList();
$scope.$apply(); $scope.$apply();
}); });
@ -618,7 +652,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}); });
}; };
// Send // Send
this.canShowAlternative = function() { this.canShowAlternative = function() {
return $scope.showAlternative; return $scope.showAlternative;
@ -673,7 +707,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
if (isCordova && !this.isWindowsPhoneApp) { if (isCordova && !this.isWindowsPhoneApp) {
this.hideMenuBar(what); this.hideMenuBar(what);
} }
var self = this; var self = this;
if (isCordova && !this.isWindowsPhoneApp && what == 'address') { if (isCordova && !this.isWindowsPhoneApp && what == 'address') {
getClipboard(function(value) { getClipboard(function(value) {
@ -877,7 +911,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}); });
}, 100); }, 100);
}; };
this.acceptTx = function(txp) { this.acceptTx = function(txp) {
var self = this; var self = this;
@ -947,6 +981,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.resetForm = function() { this.resetForm = function() {
this.resetError(); this.resetError();
this.paymentExpired = false;
this._paypro = null; this._paypro = null;
this.lockedCurrentFeePerKb = null; this.lockedCurrentFeePerKb = null;
@ -975,7 +1010,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$timeout(function() { $timeout(function() {
$rootScope.$digest(); $rootScope.$digest();
}, 1); }, 1);
}; };
this.openPPModal = function(paypro) { this.openPPModal = function(paypro) {
$rootScope.modalOpened = true; $rootScope.modalOpened = true;
@ -1059,11 +1094,37 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
self._paypro = paypro; self._paypro = paypro;
self.setForm(paypro.toAddress, (paypro.amount * satToUnit).toFixed(self.unitDecimals), paypro.memo); self.setForm(paypro.toAddress, (paypro.amount * satToUnit).toFixed(self.unitDecimals), paypro.memo);
_paymentTimeControl(paypro.expires);
return cb(); return cb();
}); });
}, 1); }, 1);
}; };
function _paymentTimeControl(timeToExpire) {
var now = Math.floor(Date.now() / 1000);
if (timeToExpire <= now) {
setExpiredPaymentValues();
return;
}
self.timeToExpire = timeToExpire;
var countDown = $interval(function() {
if (self.timeToExpire <= now) {
setExpiredPaymentValues();
$interval.cancel(countDown);
}
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) { this.setFromUri = function(uri) {
var self = this; var self = this;
@ -1135,7 +1196,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
} }
}; };
// History // History
function strip(number) { function strip(number) {
return (parseFloat(number.toPrecision(12))); return (parseFloat(number.toPrecision(12)));