isolated scope - wallets filtered from controller

This commit is contained in:
Javier 2016-08-24 19:32:49 -03:00
commit 19419526e4
6 changed files with 55 additions and 67 deletions

View file

@ -42,10 +42,10 @@
<div class="item item-icon-left">
<i class="icon ion-briefcase size-21"></i>
<label translate>From</label>
<span class="badge badge-assertive" ng-show="content.notAvailable" translate>Not available</span>
<span class="badge badge-assertive" ng-show="notAvailable" translate>Not available</span>
</div>
<wallets ng-if="hasWallet" only-complete="true" network="{{network}}" min-balance="{{minBalance}}"></wallets>
<wallets ng-if="wallets[0]" wallets="wallets"></wallets>
<div class="item item-icon-left item-icon-right" ng-click="showDescriptionPopup()">
<span ng-show="!description">Add Description</span>

View file

@ -1,6 +1,6 @@
<div class="wallets" ng-show="content.wallets[0]">
<div class="wallets" ng-show="wallets[0]">
<ion-slides class="slides" slider="data.slider">
<ion-slide-page ng-repeat="wallet in content.wallets track by $index">
<ion-slide-page ng-repeat="wallet in wallets track by $index">
<div class="item item-icon-left">
<i class="icon ion-briefcase size-21" ng-style="{'color':wallet.color}"></i>
{{wallet.name || wallet.id}}

View file

@ -34,7 +34,8 @@
<span ng-show="generatingAddress">...</span>
<span ng-show="!generatingAddress" copy-to-clipboard="addr">{{addr}}</span>
</div>
<wallets ng-if="hasWallet" only-complete="true"></wallets>
<wallets ng-if="wallets[0]" wallets="wallets"></wallets>
</div>
</ion-content>
</ion-view>

View file

@ -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;

View file

@ -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) {

View file

@ -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();
});
};
}
}
});