Merge pull request #667 from cmgustavo/bug/input-send-form
Bug/input send form
This commit is contained in:
commit
3de3184412
3 changed files with 19 additions and 14 deletions
|
|
@ -653,9 +653,10 @@
|
||||||
<label for="amount">Amount
|
<label for="amount">Amount
|
||||||
<small ng-hide="!sendForm.amount.$pristine">required</small>
|
<small ng-hide="!sendForm.amount.$pristine">required</small>
|
||||||
<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">
|
<small class="has-error" ng-show="sendForm.amount.$invalid && !sendForm.amount.$pristine && !notEnoughAmount">
|
||||||
not valid.</small>
|
not valid
|
||||||
<small ng-show="notEnoughAmount">{{notEnoughAmount}}</small>
|
</small>
|
||||||
|
<small ng-show="notEnoughAmount">Insufficient funds!</small>
|
||||||
</label>
|
</label>
|
||||||
<div class="small-9 columns">
|
<div class="small-9 columns">
|
||||||
<input type="number" id="amount" ng-disabled="loading"
|
<input type="number" id="amount" ng-disabled="loading"
|
||||||
|
|
|
||||||
|
|
@ -39,16 +39,18 @@ angular.module('copayApp.directives')
|
||||||
])
|
])
|
||||||
.directive('enoughAmount', ['$rootScope',
|
.directive('enoughAmount', ['$rootScope',
|
||||||
function($rootScope) {
|
function($rootScope) {
|
||||||
|
var bitcore = require('bitcore');
|
||||||
|
var feeSat = bitcore.TransactionBuilder.FEE_PER_1000B_SAT;
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, element, attrs, ctrl) {
|
link: function(scope, element, attrs, ctrl) {
|
||||||
var val = function(value) {
|
var val = function(value) {
|
||||||
var vStr = new String(value);
|
var availableBalanceNum = ($rootScope.availableBalance * bitcore.util.COIN).toFixed(0);
|
||||||
var vNum = Number(vStr);
|
var vNum = Number((value * bitcore.util.COIN).toFixed(0)) + feeSat;
|
||||||
if (typeof vNum == "number" && vNum > 0) {
|
if (typeof vNum == "number" && vNum > 0) {
|
||||||
if ($rootScope.availableBalance <= vNum) {
|
if (availableBalanceNum < vNum) {
|
||||||
ctrl.$setValidity('enoughAmount', false);
|
ctrl.$setValidity('enoughAmount', false);
|
||||||
scope.notEnoughAmount = 'Insufficient funds!';
|
scope.notEnoughAmount = true;
|
||||||
} else {
|
} else {
|
||||||
ctrl.$setValidity('enoughAmount', true);
|
ctrl.$setValidity('enoughAmount', true);
|
||||||
scope.notEnoughAmount = null;
|
scope.notEnoughAmount = null;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ describe("Unit: Testing Directives", function() {
|
||||||
describe('Validate Amount', function() {
|
describe('Validate Amount', function() {
|
||||||
beforeEach(inject(function($compile, $rootScope) {
|
beforeEach(inject(function($compile, $rootScope) {
|
||||||
$scope = $rootScope;
|
$scope = $rootScope;
|
||||||
$rootScope.availableBalance = 2;
|
$rootScope.availableBalance = 0.101;
|
||||||
var element = angular.element(
|
var element = angular.element(
|
||||||
'<form name="form">' +
|
'<form name="form">' +
|
||||||
'<input type="number" id="amount" name="amount" placeholder="Amount" ng-model="amount" min="0.0001" max="10000000" enough-amount required>' +
|
'<input type="number" id="amount" name="amount" placeholder="Amount" ng-model="amount" min="0.0001" max="10000000" enough-amount required>' +
|
||||||
|
|
@ -47,19 +47,21 @@ describe("Unit: Testing Directives", function() {
|
||||||
form = $scope.form;
|
form = $scope.form;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should validate between min and max value', function() {
|
it('should validate', function() {
|
||||||
form.amount.$setViewValue(1.2);
|
form.amount.$setViewValue(0.1);
|
||||||
|
expect(form.amount.$invalid).to.equal(false);
|
||||||
|
form.amount.$setViewValue(0.1009);
|
||||||
expect(form.amount.$invalid).to.equal(false);
|
expect(form.amount.$invalid).to.equal(false);
|
||||||
});
|
});
|
||||||
it('should not validate between min and max value', function() {
|
it('should not validate', function() {
|
||||||
form.amount.$setViewValue(0);
|
form.amount.$setViewValue(0);
|
||||||
expect(form.amount.$invalid).to.equal(true);
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
form.amount.$setViewValue(9999999999999);
|
form.amount.$setViewValue(9999999999);
|
||||||
expect(form.amount.$invalid).to.equal(true);
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
});
|
|
||||||
it('should not validate because not enough amount', function() {
|
|
||||||
form.amount.$setViewValue(2.1);
|
form.amount.$setViewValue(2.1);
|
||||||
expect(form.amount.$invalid).to.equal(true);
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
|
form.amount.$setViewValue(0.10091);
|
||||||
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue