lock form inputs during fetch. add fetch timeout. see bitpay/bitcore#518. see #1508.

This commit is contained in:
Christopher Jeffrey 2014-09-30 11:36:24 -07:00
commit 313f7eaaae

View file

@ -522,11 +522,36 @@ angular.module('copayApp.controllers').controller('SendController',
return; return;
} }
var apply = function() {
if ($rootScope.$$phase !== '$apply' && $rootScope.$$phase !== '$digest') {
$rootScope.$apply();
}
};
notification.info('Fetching Payment', notification.info('Fetching Payment',
'Retrieving Payment Request from ' + uri.merchant); 'Retrieving Payment Request from ' + uri.merchant);
scope.loading = true;
apply();
var timeout = setTimeout(function() {
timeout = null;
scope.loading = false;
scope.sendForm.address.$setViewValue('');
scope.sendForm.address.$render();
scope.sendForm.address.$isValid = false;
notification.error('Error', 'Payment server timed out.');
apply();
}, 10 * 1000);
// Payment Protocol URI (BIP-72) // Payment Protocol URI (BIP-72)
scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) { scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) {
if (!timeout) return;
clearTimeout(timeout);
scope.loading = false;
apply();
var balance = $rootScope.availableBalance; var balance = $rootScope.availableBalance;
var available = +(balance * w.settings.unitToSatoshi).toFixed(0); var available = +(balance * w.settings.unitToSatoshi).toFixed(0);
@ -536,8 +561,6 @@ angular.module('copayApp.controllers').controller('SendController',
} }
if (err) { if (err) {
scope.sendForm.address.$isValid = false;
if (err.amount) { if (err.amount) {
scope.sendForm.amount.$setViewValue(+err.amount / w.settings.unitToSatoshi); scope.sendForm.amount.$setViewValue(+err.amount / w.settings.unitToSatoshi);
scope.sendForm.amount.$render(); scope.sendForm.amount.$render();
@ -551,18 +574,18 @@ angular.module('copayApp.controllers').controller('SendController',
scope.sendForm.amount.$setViewValue(''); scope.sendForm.amount.$setViewValue('');
scope.sendForm.amount.$render(); scope.sendForm.amount.$render();
unregister(); unregister();
if ($rootScope.$$phase !== '$apply' && $rootScope.$$phase !== '$digest') { apply();
$rootScope.$apply();
}
} }
}); });
} else {
scope.sendForm.address.$setViewValue('');
scope.sendForm.address.$render();
} }
scope.sendForm.address.$isValid = false;
notification.error('Error', err.message || 'Bad payment server.'); notification.error('Error', err.message || 'Bad payment server.');
if ($rootScope.$$phase !== '$apply' && $rootScope.$$phase !== '$digest') { apply();
$rootScope.$apply();
}
return; return;
} }
@ -590,9 +613,7 @@ angular.module('copayApp.controllers').controller('SendController',
$scope.clearMerchant(unregister); $scope.clearMerchant(unregister);
}); });
if ($rootScope.$$phase !== '$apply' && $rootScope.$$phase !== '$digest') { apply();
$rootScope.$apply();
}
notification.info('Payment Request', notification.info('Payment Request',
'Server is requesting ' + merchantData.unitTotal + 'Server is requesting ' + merchantData.unitTotal +