diff --git a/js/controllers/send.js b/js/controllers/send.js index 7b2e76b15..b1816ee87 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -71,9 +71,9 @@ angular.module('copayApp.controllers').controller('SendController', configurable: true }); + $scope.loadTxs = function() { controllerUtils.updateTxs(); - setTimeout(function() { $scope.loading = false; $rootScope.$digest(); @@ -120,6 +120,9 @@ angular.module('copayApp.controllers').controller('SendController', if (msg.match('BIG')) msg = 'The transaction have too many inputs. Try creating many transactions for smaller amounts.' + if (msg.match('totalNeededAmount')) + msg = 'Not enough funds.' + var message = 'The transaction' + (w.isShared() ? ' proposal' : '') + ' could not be created: ' + msg; $scope.error = message; $scope.loading = false; @@ -400,17 +403,8 @@ angular.module('copayApp.controllers').controller('SendController', }); }; - $scope.getAvailableAmount = function() { - if (!$rootScope.safeUnspentCount) return null; - - var estimatedFee = copay.Wallet.estimatedFee($rootScope.safeUnspentCount); - var amount = ((($rootScope.availableBalance * w.settings.unitToSatoshi).toFixed(0) - estimatedFee) / w.settings.unitToSatoshi); - - return amount > 0 ? amount : 0; - }; - - $scope.topAmount = function(form) { - $scope.amount = $scope.getAvailableAmount(); + $scope.setTopAmount = function() { + $scope.amount = $rootScope.topAmount; }; @@ -449,6 +443,7 @@ angular.module('copayApp.controllers').controller('SendController', $scope.loadTxs(); return; } + $scope.error = undefined; var p = w.txProposals.getTxProposal(ntxid); if (p.builder.isFullySigned()) { diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 53f8a1b94..ae31d25b3 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -812,6 +812,7 @@ Wallet.prototype._lockIncomming = function() { Wallet.prototype._setBlockchainListeners = function() { var self = this; self.blockchain.removeAllListeners(); + self.subscribeToAddresses(); log.debug('Setting Blockchain listeners for', this.getName()); self.blockchain.on('reconnect', function(attempts) { @@ -2179,6 +2180,7 @@ Wallet.prototype.getAddressesStr = function(opts) { Wallet.prototype.subscribeToAddresses = function() { var addrInfo = this.publicKeyRing.getAddressesInfo(); +console.log('[Wallet.js.2181:addrInfo:]',addrInfo); //TODO this.blockchain.subscribe(_.pluck(addrInfo, 'addressStr')); log.debug('Subscribed to ' + addrInfo.length + ' addresses'); //TODO }; diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index d8c013283..c5c46a7ba 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -272,6 +272,12 @@ angular.module('copayApp.services') r.lockedBalance = (balanceSat - safeBalanceSat) * satToUnit; r.lockedBalanceBTC = (balanceSat - safeBalanceSat) / COIN; + + if (r.safeUnspentCount){ + var estimatedFee = copay.Wallet.estimatedFee(r.safeUnspentCount); + r.topAmount = (((r.availableBalance * w.settings.unitToSatoshi).toFixed(0) - estimatedFee) / w.settings.unitToSatoshi); + } + var balanceByAddr = {}; for (var ii in balanceByAddrSat) { balanceByAddr[ii] = balanceByAddrSat[ii] * satToUnit; @@ -279,6 +285,8 @@ angular.module('copayApp.services') r.balanceByAddr = balanceByAddr; root.updateAddressList(); + + if (rateService.isAvailable()) { r.totalBalanceAlternative = rateService.toFiat(balanceSat, w.settings.alternativeIsoCode); r.alternativeIsoCode = w.settings.alternativeIsoCode; diff --git a/views/send.html b/views/send.html index 6a49ed54f..697108974 100644 --- a/views/send.html +++ b/views/send.html @@ -88,9 +88,9 @@ - Use all funds ({{availableBalance}} {{$root.wallet.settings.unitName}}) + ng-show="topAmount && (!$root.merchant || +$root.merchant.total === 0)" + ng-click="setTopAmount(sendForm)"> + Use all funds {{$root.wallet.settings.unitName}}