From 9ee04fe45f6169be52ede33fa81802115ca8abba Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 8 Sep 2014 17:31:18 -0300 Subject: [PATCH] Fixed 'Use all funds' link for amounts below fee --- js/controllers/send.js | 3 ++- test/unit/controllers/controllersSpec.js | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index 2b37844d6..691ab4085 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -394,7 +394,8 @@ angular.module('copayApp.controllers').controller('SendController', }; $scope.getAvailableAmount = function() { - return ((($rootScope.availableBalance * config.unitToSatoshi).toFixed(0) - bitcore.TransactionBuilder.FEE_PER_1000B_SAT) / config.unitToSatoshi); + var amount = ((($rootScope.availableBalance * config.unitToSatoshi).toFixed(0) - bitcore.TransactionBuilder.FEE_PER_1000B_SAT) / config.unitToSatoshi); + return amount > 0 ? amount : 0; }; $scope.topAmount = function(form) { diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index b99da8e3c..ef6a820e6 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -411,6 +411,13 @@ describe("Unit: Controllers", function() { var amount = scope.getAvailableAmount(); expect(amount).to.equal(123356); }); + it('should return 0 if available amount below minimum fee', function() { + inject(function($compile, $rootScope, $controller) { + $rootScope.availableBalance = 1; + }); + var amount = scope.getAvailableAmount(); + expect(amount).to.equal(0); + }); }); describe('Import Controller', function() {