Merged 575.

This commit is contained in:
Brendon Duncan 2018-09-21 14:58:39 -07:00
commit cecad4a072
2 changed files with 172 additions and 157 deletions

View file

@ -1,7 +1,12 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('walletSelectorController', function($scope, $state, sendFlowService, configService, gettextCatalog, profileService, txFormatService) { (function () {
angular
.module('copayApp.controllers')
.controller('walletSelectorController', walletSelectorController);
function walletSelectorController ($scope, $state, sendFlowService, configService, gettextCatalog, ongoingProcess, profileService, walletService, txFormatService) {
var fromWalletId = ''; var fromWalletId = '';
var priceDisplayAsFiat = false; var priceDisplayAsFiat = false;
var unitDecimals = 0; var unitDecimals = 0;
@ -116,32 +121,41 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
if ($scope.type === 'origin') { if ($scope.type === 'origin') {
$scope.headerTitle = gettextCatalog.getString('Choose a wallet to send from'); $scope.headerTitle = gettextCatalog.getString('Choose a wallet to send from');
if ($scope.params.amount) { if ($scope.params.amount || $scope.coin) {
walletsAll = profileService.getWallets({coin: $scope.coin}); walletsAll = profileService.getWallets({coin: $scope.coin});
ongoingProcess.set('scanning', true);
walletsAll.forEach(function forWallet(wallet) { walletsAll.forEach(function forWallet(wallet) {
if (wallet.status.availableBalanceSat > $scope.params.amount) { if (!wallet.status && !wallet.cachedStatus) {
walletService.getStatus(wallet, {}, function(err, status) {
wallet.status = status;
if (status.availableBalanceSat > ($scope.params.amount ? $scope.params.amount : 0)) {
walletsSufficientFunds.push(wallet); walletsSufficientFunds.push(wallet);
} else { } else {
$scope.walletsInsufficientFunds.push(wallet); $scope.walletsInsufficientFunds.push(wallet);
} }
}); if ($scope.coin === 'btc') { // As this is a promise
if ($scope.coin === 'btc') {
$scope.walletsBtc = walletsSufficientFunds; $scope.walletsBtc = walletsSufficientFunds;
} else { } else {
$scope.walletsBch = walletsSufficientFunds; $scope.walletsBch = walletsSufficientFunds;
} }
ongoingProcess.set('scanning', false);
});
} else {
var walletStatus = null;
if (wallet.status && wallet.status.isValid) {
walletStatus = wallet.status;
} else if (wallet.cachedStatus && wallet.status.isValid) {
walletStatus = wallet.cachedStatus;
}
} else if ($scope.coin) { if (walletStatus && walletStatus.availableBalanceSat > ($scope.params.amount ? $scope.params.amount : 0)) {
walletsAll = profileService.getWallets({coin: $scope.coin});
walletsAll.forEach(function forWallet(wallet){
if (wallet.status.availableBalanceSat > 0) {
walletsSufficientFunds.push(wallet); walletsSufficientFunds.push(wallet);
} else { } else {
$scope.walletsInsufficientFunds.push(wallet); $scope.walletsInsufficientFunds.push(wallet);
} }
ongoingProcess.set('scanning', false);
}
}); });
if ($scope.coin === 'btc') { if ($scope.coin === 'btc') {
@ -186,4 +200,5 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
sendFlowService.router.goBack(); sendFlowService.router.goBack();
} }
}); }
})();

View file

@ -13,7 +13,7 @@
<div class="header--request__amount-alt" ng-show="requestAmountSecondary" translate>{{requestAmountSecondary}} {{requestCurrencySecondary}}</div> <div class="header--request__amount-alt" ng-show="requestAmountSecondary" translate>{{requestAmountSecondary}} {{requestCurrencySecondary}}</div>
</div> </div>
<div class="wallets-header"> <div class="wallets-header">
<div class="title"> <div class="title" ng-if="walletsBch.length > 0 || walletsBtc.length > 0 || walletsInsufficientFunds.length > 0">
{{headerTitle}} {{headerTitle}}
</div> </div>
</div> </div>