From 48a2be626dec5d267dba8e5e92c9f736018f31f4 Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 25 Aug 2016 10:19:39 -0300 Subject: [PATCH] refactor --- public/views/confirm.html | 10 ++--- public/views/includes/note.html | 6 +-- src/js/controllers/confirm.js | 70 +++++++++++++++---------------- src/js/controllers/tab-receive.js | 2 +- src/js/directives/directives.js | 4 +- src/sass/main.scss | 4 -- 6 files changed, 43 insertions(+), 53 deletions(-) diff --git a/public/views/confirm.html b/public/views/confirm.html index fcbe282fa..115c8824d 100644 --- a/public/views/confirm.html +++ b/public/views/confirm.html @@ -55,11 +55,9 @@ -
- -
+ diff --git a/public/views/includes/note.html b/public/views/includes/note.html index e52beba85..451ac6baf 100644 --- a/public/views/includes/note.html +++ b/public/views/includes/note.html @@ -1,11 +1,11 @@
- +
- +
- +
diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index 6572247bc..ae183bc93 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -28,12 +28,14 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.commentPopupClose = function() { commentPopup.close(); }; - $scope.commentPopupSave = function() { - $log.debug('Saving description: ' + $scope.data.comment); - $scope.description = $scope.data.comment; + $scope.commentPopupSave = function(description) { + $log.debug('Saving description: ' + description); + $scope.description = description; $scope.txp = null; + ongoingProcess.set('creatingTx', true); createTx($scope.wallet, function(err, txp) { + ongoingProcess.set('creatingTx', false); if (err) return; cachedTxp[$scope.wallet.id] = txp; apply(txp); @@ -97,7 +99,6 @@ angular.module('copayApp.controllers').controller('confirmController', function( $log.error('Bad params at amount') throw ('bad params'); } - $scope.isCordova = platformInfo.isCordova; var config = configService.getSync().wallet; @@ -123,34 +124,32 @@ angular.module('copayApp.controllers').controller('confirmController', function( var filteredWallets = []; var index = 0; - filterWallet(); + ongoingProcess.set('scanning', true); - function filterWallet() { - if (index == wallets.length) { - if (!lodash.isEmpty(filteredWallets)) { - $log.debug('Wallet changed: ' + filteredWallets[0].name); - $scope.wallets = lodash.clone(filteredWallets); - setWallet(wallets[0], true); - $scope.notAvailable = false; - } else { - $scope.notAvailable = true; - $log.warn('No wallet available to make the payment'); - } - - $timeout(function() { - $scope.$apply(); - }, 10); - return; - } - - walletService.getStatus(wallets[index], {}, function(err, status) { + lodash.each(wallets, function(w) { + walletService.getStatus(w, {}, function(err, status) { if (err) $log.error(err); - if (!status.availableBalanceSat) $log.debug('No balance available in: ' + wallets[index].name); - if (status.availableBalanceSat > amount) filteredWallets.push(wallets[index]); - index++; - filterWallet(); + if (!status.availableBalanceSat) $log.debug('No balance available in: ' + w.name); + if (status.availableBalanceSat > amount) filteredWallets.push(w); + + if (++index == wallets.length) { + ongoingProcess.set('scanning', false); + + if (!lodash.isEmpty(filteredWallets)) { + $scope.wallets = lodash.clone(filteredWallets); + $scope.notAvailable = false; + } else { + $scope.notAvailable = true; + $log.warn('No wallet available to make the payment'); + } + + $timeout(function() { + $scope.$apply(); + }, 10); + return; + } }); - }; + }); txFormatService.formatAlternativeStr(amount, function(v) { $scope.alternativeAmountStr = v; @@ -158,7 +157,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( }; $scope.$on('Wallet/Changed', function(event, wallet) { - if (!wallet) { + if (lodash.isEmpty(wallet)) { $log.debug('No wallet provided'); return; } @@ -172,6 +171,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.fee = $scope.txp = null; $timeout(function() { + $ionicScrollDelegate.resize(); $scope.$apply(); }, 10); @@ -180,17 +180,13 @@ angular.module('copayApp.controllers').controller('confirmController', function( stop = null; } - function apply(txp) { - $scope.fee = txFormatService.formatAmountStr(txp.fee); - $scope.txp = txp; - $scope.$apply(); - }; - if (cachedTxp[wallet.id]) { apply(cachedTxp[wallet.id]); } else { + ongoingProcess.set('creatingTx', true); stop = $timeout(function() { - createTx(wallet, $scope.toAddress, $scope.toAmount, $scope.comment || null, function(err, txp) { + createTx(wallet, function(err, txp) { + ongoingProcess.set('creatingTx', false); if (err) return; cachedTxp[wallet.id] = txp; apply(txp); diff --git a/src/js/controllers/tab-receive.js b/src/js/controllers/tab-receive.js index 342080515..c7e2b319b 100644 --- a/src/js/controllers/tab-receive.js +++ b/src/js/controllers/tab-receive.js @@ -13,7 +13,7 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi } $scope.$on('Wallet/Changed', function(event, wallet) { - if (!wallet) { + if (lodash.isEmpty(wallet)) { $log.debug('No wallet provided'); return; } diff --git a/src/js/directives/directives.js b/src/js/directives/directives.js index e9a1e5ee1..88458c146 100644 --- a/src/js/directives/directives.js +++ b/src/js/directives/directives.js @@ -153,11 +153,11 @@ angular.module('copayApp.directives') link: function(scope, element, attrs) { scope.$on("$ionicSlides.sliderInitialized", function(event, data) { scope.slider = data.slider; - scope.$emit('Wallet/Changed', scope.wallets[0]); + scope.$emit('Wallet/Changed', scope.wallets ? scope.wallets[0] : null); }); scope.$on("$ionicSlides.slideChangeEnd", function(event, data) { - scope.$emit('Wallet/Changed', scope.wallets[data.slider.activeIndex]); + scope.$emit('Wallet/Changed', scope.wallets ? scope.wallets[data.slider.activeIndex] : null); }); } } diff --git a/src/sass/main.scss b/src/sass/main.scss index 6c41c6f57..c52303e5b 100644 --- a/src/sass/main.scss +++ b/src/sass/main.scss @@ -880,10 +880,6 @@ input[type=file] { .wallets { height: 105px; } - -.no-pager .swiper-pagination { - display: none; -} /* * Calculator */