better send tab without internet

This commit is contained in:
Matias Alejo Garcia 2017-01-16 16:58:42 -03:00
parent f063c06751
commit aa05165710
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
3 changed files with 31 additions and 20 deletions

View File

@ -79,12 +79,14 @@ angular.module('copayApp.controllers').controller('confirmController', function(
var filteredWallets = []; var filteredWallets = [];
var index = 0; var index = 0;
var enoughFunds = false; var enoughFunds = false;
var walletsUpdated = 0;
lodash.each($scope.wallets, function(w) { lodash.each($scope.wallets, function(w) {
walletService.getStatus(w, {}, function(err, status) { walletService.getStatus(w, {}, function(err, status) {
if (err || !status) { if (err || !status) {
$log.error(err); $log.error(err);
} else { } else {
walletsUpdated++;
w.status = status; w.status = status;
if (!status.availableBalanceSat) $log.debug('No balance available in: ' + w.name); if (!status.availableBalanceSat) $log.debug('No balance available in: ' + w.name);
if (status.availableBalanceSat > toAmount) { if (status.availableBalanceSat > toAmount) {
@ -94,6 +96,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
} }
if (++index == $scope.wallets.length) { if (++index == $scope.wallets.length) {
if (!lodash.isEmpty(filteredWallets)) { if (!lodash.isEmpty(filteredWallets)) {
$scope.wallets = lodash.clone(filteredWallets); $scope.wallets = lodash.clone(filteredWallets);
if ($scope.useSendMax) { if ($scope.useSendMax) {
@ -105,9 +108,23 @@ angular.module('copayApp.controllers').controller('confirmController', function(
} }
} else initConfirm(); } else initConfirm();
} else { } else {
if (!enoughFunds) $scope.insufficientFunds = true;
displayValues(); // Were we able to update any wallet?
$log.warn('No wallet available to make the payment'); if (walletsUpdated) {
if (!enoughFunds) $scope.insufficientFunds = true;
displayValues();
$log.warn('No wallet available to make the payment');
} else {
popupService.showAlert(gettextCatalog.getString('Could not update wallets'), bwcError.msg(err), function() {
$ionicHistory.nextViewOptions({
disableAnimate: true,
historyRoot: true
});
$ionicHistory.clearHistory();
$state.go('tabs.send');
});
}
} }
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();

View File

@ -94,8 +94,8 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
$timeout(function() { $timeout(function() {
item.getAddress(function(err, addr) { item.getAddress(function(err, addr) {
if (err || !addr) { if (err || !addr) {
$log.error(err); //Error is already formated
return; return popupService.showAlert(err);
} }
$log.debug('Got toAddress:' + addr + ' | ' + item.name); $log.debug('Got toAddress:' + addr + ' | ' + item.name);
return $state.transitionTo('tabs.send.amount', { return $state.transitionTo('tabs.send.amount', {
@ -109,6 +109,10 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
}); });
}; };
// THIS is ONLY to show the 'buy bitcoins' message
// does not has any other function.
var updateHasFunds = function() { var updateHasFunds = function() {
if ($rootScope.everHasFunds) { if ($rootScope.everHasFunds) {
@ -128,20 +132,18 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
}); });
} }
$scope.checkingBalanceError = false;
$scope.checkingBalance = true; $scope.checkingBalance = true;
var index = 0, var index = 0;
errorShown = 0;
lodash.each(wallets, function(w) { lodash.each(wallets, function(w) {
walletService.getStatus(w, {}, function(err, status) { walletService.getStatus(w, {}, function(err, status) {
++index; ++index;
if (err && !status) { if (err && !status) {
$log.error(err); $log.error(err);
if (!errorShown++) popupService.showAlert(bwcError.msg(err, gettextCatalog.getString('Could not update wallet'))); // error updating the wallet. Probably a network error, do not show
$scope.checkingBalanceError = true; // the 'buy bitcoins' message.
return;
$scope.hasFunds = true;
} else if (status.availableBalanceSat > 0) { } else if (status.availableBalanceSat > 0) {
$scope.hasFunds = true; $scope.hasFunds = true;
$rootScope.everHasFunds = true; $rootScope.everHasFunds = true;

View File

@ -2,14 +2,6 @@
<ion-nav-bar class="bar-royal"> <ion-nav-bar class="bar-royal">
<ion-nav-title>{{'Send' | translate}}</ion-nav-title> <ion-nav-title>{{'Send' | translate}}</ion-nav-title>
</ion-nav-bar> </ion-nav-bar>
<ion-content ng-show="checkingBalanceError">
<div class="list card">
<div class="item item-icon-left">
<i class="ion-alert-circled icon"></i>
<span translate>Could not update wallets</span>
</div>
</div>
</ion-content >
<ion-content ng-show="!checkingBalance"> <ion-content ng-show="!checkingBalance">
<div ng-if="hasFunds == false" class="zero-state"> <div ng-if="hasFunds == false" class="zero-state">
<div> <div>