diff --git a/public/views/confirm.html b/public/views/confirm.html index f52529809..835cb1d15 100644 --- a/public/views/confirm.html +++ b/public/views/confirm.html @@ -22,15 +22,9 @@
Fee: {{feeLevel}} -<<<<<<< eb8c739515d024200f5ea2bad72fffb21437375b - - {{fee || '...'}} - -======= {{fee || '...'}} ->>>>>>> add wallet widget in confirm (send) view
@@ -49,29 +43,8 @@
-<<<<<<< eb8c739515d024200f5ea2bad72fffb21437375b -
- - -
-
    -
  • - - {{item.name || item.id}} - - {{item.availableBalanceStr}} - -
  • -
-
-
-
-
- -======= - ->>>>>>> add wallet widget in confirm (send) view +
Add Description diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index c11c545bd..fcf6d857e 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -113,6 +113,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.feeLevel = config.settings ? config.settings.feeLevel : ''; var amount = $scope.toAmount = parseInt($stateParams.toAmount); + $scope.minBalance = amount; $scope.amountStr = txFormatService.formatAmountStr($scope.toAmount); $scope.toAddress = $stateParams.toAddress; @@ -129,9 +130,12 @@ angular.module('copayApp.controllers').controller('confirmController', function( }; $scope.$on('Wallet/Changed', function(event, wallet) { + if (!wallet) { + $log.debug('No wallet provided'); + return; + } $log.debug('Wallet changed: ' + wallet.name); setWallet(wallet, true); - $scope.$apply(); }); function setWallet(wallet, delayed) { diff --git a/src/js/directives/directives.js b/src/js/directives/directives.js index 513be5ea4..4a512fba5 100644 --- a/src/js/directives/directives.js +++ b/src/js/directives/directives.js @@ -143,7 +143,7 @@ angular.module('copayApp.directives') } } }) - .directive('wallets', function(profileService) { + .directive('wallets', function($log, profileService, walletService, lodash) { return { restrict: 'E', templateUrl: 'views/includes/wallets.html', @@ -155,17 +155,41 @@ angular.module('copayApp.directives') opts.n = attrs.n; scope.content = {}; - scope.content.wallets = profileService.getWallets(opts); + scope.content.wallets = []; + var minBalance = attrs.minBalance ? parseInt(attrs.minBalance) : 0; + var wallets = profileService.getWallets(opts); + var filteredWallets = []; + var index = 0; + + if (minBalance) + filterWallet(); scope.$on("$ionicSlides.sliderInitialized", function(event, data) { scope.slider = data.slider; - scope.$emit('Wallet/Changed', scope.content.wallets[0]); }); scope.$on("$ionicSlides.slideChangeEnd", function(event, data) { scope.content.index = data.slider.activeIndex; scope.$emit('Wallet/Changed', scope.content.wallets[scope.content.index]); }); + + function filterWallet() { + if (index == wallets.length) { + if (!lodash.isEmpty(filteredWallets)) { + scope.content.wallets = filteredWallets; + scope.$emit('Wallet/Changed', scope.content.wallets[0]); + } + return; + } + + walletService.getStatus(wallets[index], {}, function(err, status) { + if (err) $log.error(err); + if (!status.availableBalanceSat) $log.debug('Balance not available on wallet: ' + wallets[index].name); + if (status.availableBalanceSat > minBalance) filteredWallets.push(wallets[index]); + index++; + filterWallet(); + }); + }; } } });