Removes debit card limit. Back to amount view if create invoice failed

This commit is contained in:
Gustavo Maximiliano Cortez 2017-04-20 13:27:15 -03:00
commit 32fc5e6b9b
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF

View file

@ -9,16 +9,18 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
$scope.isCordova = platformInfo.isCordova; $scope.isCordova = platformInfo.isCordova;
var showErrorAndBack = function(err) { var showErrorAndBack = function(title, msg) {
title = title || 'Error';
$scope.sendStatus = ''; $scope.sendStatus = '';
$log.error(err); $log.error(msg);
err = err.errors ? err.errors[0].message : err; msg = msg.errors ? msg.errors[0].message : msg;
popupService.showAlert('Error', err, function() { popupService.showAlert(title, msg, function() {
$ionicHistory.goBack(); $ionicHistory.goBack();
}); });
}; };
var showError = function(title, msg) { var showError = function(title, msg) {
title = title || 'Error';
$scope.sendStatus = ''; $scope.sendStatus = '';
$log.error(msg); $log.error(msg);
msg = msg.errors ? msg.errors[0].message : msg; msg = msg.errors ? msg.errors[0].message : msg;
@ -50,28 +52,12 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
} }
}; };
var checkDailyLimit = function() {
if (currency == 'USD' && amount > 10000) {
showErrorAndBack('Top up is limited to USD 10,000 per day');
return;
}
bitpayCardService.getRates('USD', function(err, data) {
if (err) $log.error(err);
$scope.rate = data.rate;
if (currency == 'BTC' && (amount * data.rate) > 10000) {
showErrorAndBack('Top up is limited to USD 10,000 per day');
return;
}
});
};
$scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.$on("$ionicView.beforeEnter", function(event, data) {
cardId = data.stateParams.id; cardId = data.stateParams.id;
sendMax = data.stateParams.useSendMax; sendMax = data.stateParams.useSendMax;
if (!cardId) { if (!cardId) {
showErrorAndBack('No card selected'); showErrorAndBack(null, 'No card selected');
return; return;
} }
@ -92,14 +78,19 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
}); });
if (lodash.isEmpty($scope.wallets)) { if (lodash.isEmpty($scope.wallets)) {
showErrorAndBack('Insufficient funds'); showErrorAndBack(null, 'Insufficient funds');
return; return;
} }
$scope.onWalletSelect($scope.wallets[0]); // Default first wallet $scope.onWalletSelect($scope.wallets[0]); // Default first wallet
bitpayCardService.getRates('USD', function(err, data) {
if (err) $log.error(err);
$scope.rate = data.rate;
});
bitpayCardService.get({ cardId: cardId, noRefresh: true }, function(err, card) { bitpayCardService.get({ cardId: cardId, noRefresh: true }, function(err, card) {
if (err) { if (err) {
showErrorAndBack(err); showErrorAndBack(null, err);
return; return;
} }
$scope.cardInfo = card[0]; $scope.cardInfo = card[0];
@ -127,7 +118,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
bitpayCardService.topUp(cardId, dataSrc, function(err, invoiceId) { bitpayCardService.topUp(cardId, dataSrc, function(err, invoiceId) {
if (err) { if (err) {
ongoingProcess.set('topup', false, statusChangeHandler); ongoingProcess.set('topup', false, statusChangeHandler);
showError('Could not create the invoice', err); showErrorAndBack('Could not create the invoice', err);
return; return;
} }
@ -206,7 +197,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
sendMaxService.getInfo($scope.wallet, function(err, values) { sendMaxService.getInfo($scope.wallet, function(err, values) {
ongoingProcess.set('retrievingInputs', false); ongoingProcess.set('retrievingInputs', false);
if (err) { if (err) {
showErrorAndBack(err); showErrorAndBack(null, err);
return; return;
} }
var config = configService.getSync().wallet.settings; var config = configService.getSync().wallet.settings;
@ -218,14 +209,11 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
amount = parsedAmount.amount; amount = parsedAmount.amount;
currency = parsedAmount.currency; currency = parsedAmount.currency;
checkDailyLimit();
$scope.amountUnitStr = parsedAmount.amountUnitStr; $scope.amountUnitStr = parsedAmount.amountUnitStr;
$timeout(function() { $timeout(function() {
$scope.$digest(); $scope.$digest();
}, 100); }, 100);
}); });
} else {
checkDailyLimit();
} }
}; };