Fix reset values

This commit is contained in:
Gustavo Maximiliano Cortez 2017-07-11 10:36:00 -03:00
parent 79a78d9937
commit abd09fb559
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
1 changed files with 12 additions and 4 deletions

View File

@ -11,6 +11,11 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
var message; var message;
var configWallet = configService.getSync().wallet; var configWallet = configService.getSync().wallet;
var _resetValues = function() {
$scope.totalAmountStr = $scope.amount = $scope.invoiceFee = $scope.networkFee = $scope.totalAmount = $scope.wallet = null;
createdTx = message = null;
};
var showErrorAndBack = function(title, msg) { var showErrorAndBack = function(title, msg) {
title = title || gettextCatalog.getString('Error'); title = title || gettextCatalog.getString('Error');
$scope.sendStatus = ''; $scope.sendStatus = '';
@ -193,6 +198,8 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
return; return;
} }
// Sometimes API does not return this element;
invoice['buyerPaidBtcMinerFee'] = invoice.buyerPaidBtcMinerFee || 0;
var invoiceFeeSat = (invoice.buyerPaidBtcMinerFee * 100000000).toFixed(); var invoiceFeeSat = (invoice.buyerPaidBtcMinerFee * 100000000).toFixed();
message = gettextCatalog.getString("Top up {{amountStr}} to debit card ({{cardLastNumber}})", { message = gettextCatalog.getString("Top up {{amountStr}} to debit card ({{cardLastNumber}})", {
@ -203,6 +210,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
createTx(wallet, invoice, message, function(err, ctxp) { createTx(wallet, invoice, message, function(err, ctxp) {
ongoingProcess.set('loadingTxInfo', false); ongoingProcess.set('loadingTxInfo', false);
if (err) { if (err) {
_resetValues();
showError(err.title, err.message); showError(err.title, err.message);
return; return;
} }
@ -284,8 +292,8 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
ongoingProcess.set('topup', true, statusChangeHandler); ongoingProcess.set('topup', true, statusChangeHandler);
publishAndSign($scope.wallet, createdTx, function() {}, function(err, txSent) { publishAndSign($scope.wallet, createdTx, function() {}, function(err, txSent) {
if (err) { if (err) {
ongoingProcess.set('topup', false); _resetValues();
$scope.sendStatus = ''; ongoingProcess.set('topup', false, statusChangeHandler);
showError(gettextCatalog.getString('Could not send transaction'), err); showError(gettextCatalog.getString('Could not send transaction'), err);
return; return;
} }
@ -295,7 +303,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
}; };
$scope.showWalletSelector = function() { $scope.showWalletSelector = function() {
$scope.walletSelectorTitle = 'From'; $scope.walletSelectorTitle = gettextCatalog.getString('From');
$scope.showWallets = true; $scope.showWallets = true;
}; };
@ -305,7 +313,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
calculateAmount(wallet, function(err, a, c) { calculateAmount(wallet, function(err, a, c) {
ongoingProcess.set('retrievingInputs', false); ongoingProcess.set('retrievingInputs', false);
if (err) { if (err) {
createdTx = message = $scope.totalAmountStr = $scope.amountUnitStr = $scope.wallet = null; _resetValues();
showError(err.title, err.message, function() { showError(err.title, err.message, function() {
$scope.showWalletSelector(); $scope.showWalletSelector();
}); });