Merge pull request #721 from maraoz/feature/autotop-send

send all available balance button
This commit is contained in:
Ryan X. Charles 2014-06-24 07:34:06 -07:00
commit b64449ae09
3 changed files with 17 additions and 4 deletions

View File

@ -675,6 +675,7 @@
<div class="row collapse"> <div class="row collapse">
<label for="amount">Amount <label for="amount">Amount
<small ng-hide="!sendForm.amount.$pristine">required</small> <small ng-hide="!sendForm.amount.$pristine">required</small>
<i class="fi-arrow-up" title="Send all funds" ng-click="topAmount()"></i>
<small class="is-valid" ng-show="!sendForm.amount.$invalid && !sendForm.amount.$pristine">Valid</small> <small class="is-valid" ng-show="!sendForm.amount.$invalid && !sendForm.amount.$pristine">Valid</small>
<small class="has-error" ng-show="sendForm.amount.$invalid && !sendForm.amount.$pristine && !notEnoughAmount"> <small class="has-error" ng-show="sendForm.amount.$invalid && !sendForm.amount.$pristine && !notEnoughAmount">
Not valid Not valid
@ -717,7 +718,7 @@
<small class="is-valid" ng-show="!sendForm.comment.$invalid && !sendForm.comment.$pristine">valid!</small> <small class="is-valid" ng-show="!sendForm.comment.$invalid && !sendForm.comment.$pristine">valid!</small>
<small class="has-error" ng-show="sendForm.comment.$invalid && !sendForm.comment.$pristine">too long!</small> <small class="has-error" ng-show="sendForm.comment.$invalid && !sendForm.comment.$pristine">too long!</small>
</label> </label>
<div class="small-12 columns"> <div class="large-12 columns">
<textarea id="comment" ng-disabled="loading" <textarea id="comment" ng-disabled="loading"
name="comment" placeholder="Leave a private message to your copayers" ng-model="commentText" ng-maxlength="100"></textarea> name="comment" placeholder="Leave a private message to your copayers" ng-model="commentText" ng-maxlength="100"></textarea>
</div> </div>

View File

@ -33,7 +33,7 @@ angular.module('copayApp.controllers').controller('SendController',
$scope.submitForm = function(form) { $scope.submitForm = function(form) {
if (form.$invalid) { if (form.$invalid) {
$rootScope.$flashMessage = { $rootScope.$flashMessage = {
message: 'You can not send a proposal transaction. Please, try again', message: 'Unable to send a transaction proposal. Please, try again',
type: 'error' type: 'error'
}; };
return; return;
@ -254,4 +254,9 @@ angular.module('copayApp.controllers').controller('SendController',
}); });
}; };
$scope.topAmount = function() {
var maxSat = ($rootScope.availableBalance * config.unitToSatoshi).toFixed(0)
- bitcore.TransactionBuilder.FEE_PER_1000B_SAT;
$scope.amount = maxSat / config.unitToSatoshi;
};
}); });

View File

@ -128,10 +128,12 @@ describe("Unit: Controllers", function() {
); );
scope.model = { scope.model = {
newaddress: null, newaddress: null,
newlabel: null newlabel: null,
}; };
$compile(element)(scope); $compile(element)(scope);
$controller('SendController', {$scope: scope}); $controller('SendController', {$scope: scope,
$modal: {},
});
scope.$digest(); scope.$digest();
form = scope.form; form = scope.form;
})); }));
@ -244,6 +246,7 @@ describe("Unit: Controllers", function() {
var sendCtrl; var sendCtrl;
beforeEach(inject(function($controller, $rootScope) { beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new(); scope = $rootScope.$new();
$rootScope.availableBalance = 123456;
sendCtrl = $controller('SendController', { sendCtrl = $controller('SendController', {
$scope: scope, $scope: scope,
$modal: {}, $modal: {},
@ -253,6 +256,10 @@ describe("Unit: Controllers", function() {
it('should have a SendController', function() { it('should have a SendController', function() {
expect(scope.isMobile).not.to.equal(null); expect(scope.isMobile).not.to.equal(null);
}); });
it('should autotop balance correctly', function() {
scope.topAmount();
expect(scope.amount).to.equal(123356);
});
}); });
}); });