diff --git a/public/views/includes/wallets.html b/public/views/includes/wallets.html
index ed88f8302..978d7804e 100644
--- a/public/views/includes/wallets.html
+++ b/public/views/includes/wallets.html
@@ -1,6 +1,6 @@
-
+
-
+
{{wallet.name || wallet.id}}
diff --git a/public/views/tab-receive.html b/public/views/tab-receive.html
index 6f310209b..4e9576bf8 100644
--- a/public/views/tab-receive.html
+++ b/public/views/tab-receive.html
@@ -34,7 +34,8 @@
...
{{addr}}
-
+
+
diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js
index af4440289..6572247bc 100644
--- a/src/js/controllers/confirm.js
+++ b/src/js/controllers/confirm.js
@@ -92,18 +92,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
};
$scope.init = function() {
- $scope.wallet = profileService.getWallets()[0];
- $scope.notAvailable = false;
- $scope.hasWallet = $scope.wallet ? true : false;
-
- if ($stateParams.paypro) {
- return setFromPayPro($stateParams.paypro, function(err) {
- if (err && !isChromeApp) {
- showAlert(gettext('Could not fetch payment'));
- }
- });
- }
-
+ // TODO (URL , etc)
if (!$stateParams.toAddress || !$stateParams.toAmount) {
$log.error('Bad params at amount')
throw ('bad params');
@@ -115,7 +104,6 @@ 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;
@@ -123,8 +111,46 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.description = $stateParams.description;
$scope.paypro = $stateParams.paypro;
- var network = (new bitcore.Address($scope.toAddress)).network.name;
- $scope.network = network;
+ var networkName = (new bitcore.Address($scope.toAddress)).network.name;
+ $scope.network = networkName;
+
+ $scope.notAvailable = false;
+ var wallets = profileService.getWallets({
+ onlyComplete: true,
+ network: networkName,
+ });
+
+ var filteredWallets = [];
+ var index = 0;
+
+ filterWallet();
+
+ 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) {
+ 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();
+ });
+ };
txFormatService.formatAlternativeStr(amount, function(v) {
$scope.alternativeAmountStr = v;
diff --git a/src/js/controllers/tab-receive.js b/src/js/controllers/tab-receive.js
index d9f2009be..342080515 100644
--- a/src/js/controllers/tab-receive.js
+++ b/src/js/controllers/tab-receive.js
@@ -5,11 +5,11 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
$scope.isCordova = platformInfo.isCordova;
$scope.init = function() {
- $scope.defaultWallet = profileService.getWallets()[0];
- $scope.hasWallet = $scope.defaultWallet ? true : false;
+ $scope.wallets = profileService.getWallets({
+ onlyComplete: true
+ });
$scope.isCordova = platformInfo.isCordova;
$scope.isNW = platformInfo.isNW;
- $scope.setAddress(false);
}
$scope.$on('Wallet/Changed', function(event, wallet) {
diff --git a/src/js/directives/directives.js b/src/js/directives/directives.js
index 5ddc43718..e9a1e5ee1 100644
--- a/src/js/directives/directives.js
+++ b/src/js/directives/directives.js
@@ -147,57 +147,18 @@ angular.module('copayApp.directives')
return {
restrict: 'E',
templateUrl: 'views/includes/wallets.html',
- scope: false,
+ scope: {
+ wallets: '=wallets'
+ },
link: function(scope, element, attrs) {
- var opts = {};
- opts.onlyComplete = attrs.onlyComplete == 'true' ? true : null;
- opts.network = attrs.network;
- opts.n = attrs.n;
-
- scope.content = {};
- scope.content.wallets = [];
- scope.content.notAvailable = false;
- var wallets = profileService.getWallets(opts);
- var minBalance = attrs.minBalance ? parseInt(attrs.minBalance) : 0;
- var filteredWallets = [];
- var index = 0;
-
- if (minBalance)
- filterWallet();
- else {
- scope.content.wallets = wallets;
- scope.$emit('Wallet/Changed', scope.content.wallets[0]);
- }
-
scope.$on("$ionicSlides.sliderInitialized", function(event, data) {
scope.slider = data.slider;
+ scope.$emit('Wallet/Changed', scope.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]);
+ scope.$emit('Wallet/Changed', scope.wallets[data.slider.activeIndex]);
});
-
- function filterWallet() {
- if (index == wallets.length) {
- if (!lodash.isEmpty(filteredWallets)) {
- scope.content.wallets = filteredWallets;
- scope.$emit('Wallet/Changed', scope.content.wallets[0]);
- } else {
- scope.content.notAvailable = true;
- $log.warn('No wallet available to make the payment');
- }
- return;
- }
-
- walletService.getStatus(wallets[index], {}, function(err, status) {
- if (err) $log.error(err);
- if (!status.availableBalanceSat) $log.debug('No balance available in: ' + wallets[index].name);
- if (status.availableBalanceSat > minBalance) filteredWallets.push(wallets[index]);
- index++;
- filterWallet();
- });
- };
}
}
});