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
|
||||
<small ng-hide="!sendForm.amount.$pristine">required</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">
|
||||
not valid.</small>
|
||||
<small ng-show="notEnoughAmount">{{notEnoughAmount}}</small>
|
||||
<small class="has-error" ng-show="sendForm.amount.$invalid && !sendForm.amount.$pristine && !notEnoughAmount">
|
||||
not valid
|
||||
</small>
|
||||
<small ng-show="notEnoughAmount">Insufficient funds!</small>
|
||||
</label>
|
||||
<div class="small-9 columns">
|
||||
<input type="number" id="amount" ng-disabled="loading"
|
||||
|
|
|
|||
|
|
@ -39,16 +39,18 @@ angular.module('copayApp.directives')
|
|||
])
|
||||
.directive('enoughAmount', ['$rootScope',
|
||||
function($rootScope) {
|
||||
var bitcore = require('bitcore');
|
||||
var feeSat = bitcore.TransactionBuilder.FEE_PER_1000B_SAT;
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function(scope, element, attrs, ctrl) {
|
||||
var val = function(value) {
|
||||
var vStr = new String(value);
|
||||
var vNum = Number(vStr);
|
||||
var availableBalanceNum = ($rootScope.availableBalance * bitcore.util.COIN).toFixed(0);
|
||||
var vNum = Number((value * bitcore.util.COIN).toFixed(0)) + feeSat;
|
||||
if (typeof vNum == "number" && vNum > 0) {
|
||||
if ($rootScope.availableBalance <= vNum) {
|
||||
if (availableBalanceNum < vNum) {
|
||||
ctrl.$setValidity('enoughAmount', false);
|
||||
scope.notEnoughAmount = 'Insufficient funds!';
|
||||
scope.notEnoughAmount = true;
|
||||
} else {
|
||||
ctrl.$setValidity('enoughAmount', true);
|
||||
scope.notEnoughAmount = null;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ describe("Unit: Testing Directives", function() {
|
|||
describe('Validate Amount', function() {
|
||||
beforeEach(inject(function($compile, $rootScope) {
|
||||
$scope = $rootScope;
|
||||
$rootScope.availableBalance = 2;
|
||||
$rootScope.availableBalance = 0.101;
|
||||
var element = angular.element(
|
||||
'<form name="form">' +
|
||||
'<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;
|
||||
}));
|
||||
|
||||
it('should validate between min and max value', function() {
|
||||
form.amount.$setViewValue(1.2);
|
||||
it('should validate', function() {
|
||||
form.amount.$setViewValue(0.1);
|
||||
expect(form.amount.$invalid).to.equal(false);
|
||||
form.amount.$setViewValue(0.1009);
|
||||
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);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
form.amount.$setViewValue(9999999999999);
|
||||
form.amount.$setViewValue(9999999999);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
});
|
||||
it('should not validate because not enough amount', function() {
|
||||
form.amount.$setViewValue(2.1);
|
||||
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