Skip to content

Commit 3d2f4d2

Browse files
committed
feat(wallet): transaction fee validation change
jQuery validation mechanism didn't work well with jQuery.ui autocomplete, so I had to implement a the field checks manually. Added precision as a parameter for decimals validation routine.
1 parent 4cc44a6 commit 3d2f4d2

File tree

4 files changed

+54
-21
lines changed

4 files changed

+54
-21
lines changed

css/style.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,8 +1218,12 @@ input.tabs-radio:checked + label img {
12181218
top: 0;
12191219
bottom: 0;
12201220
right: 0;
1221-
margin-right: -.25rem;
1222-
padding: 0;
1221+
margin: 2px;
1222+
border-style: none none none solid;
1223+
}
1224+
1225+
.custom-combobox-toggle:hover {
1226+
border-style: none none none solid;
12231227
}
12241228

12251229
.custom-combobox-input {

js/waves.money.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ var Money = function(amount, currency) {
9999

100100
this.formatAmount = function (stripZeroes) {
101101
if (stripZeroes)
102-
return this.amount.toString();
102+
return this.toTokens().toString();
103103

104104
return format(this.amount);
105105
}

js/waves.ui.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,12 @@ var Waves = (function(Waves, $, undefined) {
552552
$.validator.addMethod('address', function(value, element){
553553
return this.optional(element) || Waves.Addressing.validateDisplayAddress(value);
554554
}, "Account number must be a sequence of 35 alphanumeric characters with no spaces, optionally starting with '1W'");
555-
$.validator.addMethod('decimal', function(value, element) {
556-
return this.optional(element) || /^(?:-?\d+)?(?:\.\d+)?$/.test(value);
557-
}, "Amount is expected with a dot (.) as a decimal separator");
555+
$.validator.addMethod('decimal', function(value, element, params) {
556+
var maxdigits = $.isNumeric(params) ? params : Waves.UI.constants.AMOUNT_DECIMAL_PLACES;
557+
558+
var regex = new RegExp("^(?:-?\\d+)?(?:\\.\\d{1," + maxdigits + "})?$");
559+
return this.optional(element) || regex.test(value);
560+
}, "Amount is expected with a dot (.) as a decimal separator with no more than {0} fraction digits");
558561
$.validator.addMethod('password', function(value, element){
559562
if (this.optional(element))
560563
return true;

js/waves.ui.wallet.js

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,25 @@ var Waves = (function(Waves, $, undefined) {
4444
Waves.UI.sendWavesForm = {
4545
id : 'send-waves-form',
4646
containerId : 'wB-butSend-WAV',
47+
feeInputSelector : '.custom-combobox-input',
48+
errorClass : 'wInput-error',
4749
validator : undefined,
4850
getForm : function() {
4951
return $('#' + Waves.UI.sendWavesForm.id);
5052
},
5153
setupValidation : function() {
5254
$('#' + this.containerId).on($.modal.BEFORE_OPEN, function(event, modal) {
5355
Waves.UI.sendWavesForm.validator = Waves.UI.sendWavesForm.getForm().validate({
54-
errorClass : 'wInput-error',
56+
errorClass : Waves.UI.sendWavesForm.errorClass,
5557
rules : {
5658
wavesrecipient : {
5759
required : true,
5860
address : true
5961
},
6062
wavessendamount : {
6163
required : true,
62-
decimal : true,
64+
decimal : Currency.WAV.precision,
6365
min : Waves.UI.constants.MINIMUM_PAYMENT_AMOUNT
64-
},
65-
wavessendfee : {
66-
required : true,
67-
decimal : true,
68-
min : Waves.UI.constants.MINIMUM_TRANSACTION_FEE
6966
}
7067
},
7168
messages : {
@@ -74,15 +71,9 @@ var Waves = (function(Waves, $, undefined) {
7471
},
7572
wavessendamount : {
7673
required : 'Amount to send is required',
77-
decimal : 'Amount to send must be a decimal number with dot (.) as a decimal separator',
74+
decimal : 'Amount to send must be a decimal number with dot (.) as a decimal separator with no more than {0} fraction digits',
7875
min : 'Payment amount is too small. It should be greater or equal to ' +
7976
Waves.UI.constants.MINIMUM_PAYMENT_AMOUNT.toFixed(Waves.UI.constants.AMOUNT_DECIMAL_PLACES)
80-
},
81-
wavessendfee : {
82-
required : 'Transaction fee is required',
83-
decimal : 'Transaction fee must be a decimal number with dot (.) as a decimal separator',
84-
min : 'Transactions fee is too small. It should be greater or equal to ' +
85-
Waves.UI.constants.MINIMUM_TRANSACTION_FEE
8677
}
8778
}
8879
});
@@ -91,11 +82,46 @@ var Waves = (function(Waves, $, undefined) {
9182
$('#' + this.containerId).on($.modal.BEFORE_CLOSE, function(event, modal) {
9283
if (Waves.UI.sendWavesForm.validator !== undefined)
9384
Waves.UI.sendWavesForm.validator.resetForm();
85+
86+
$(this.feeInputSelector).parent().removeClass(this.errorClass);
9487
});
9588
},
9689

9790
isValid : function() {
98-
return this.getForm().valid();
91+
if (!this.getForm().valid())
92+
return false;
93+
94+
// manually validate tx fee cos jquery.validation conflicts with autocomplete.combobox
95+
var element = $(this.feeInputSelector);
96+
var value = element.val();
97+
98+
if (!$.validator.methods.required.call(this.validator, value, element[0], true)) {
99+
$.growl.error({ message: 'Transaction fee is required' });
100+
element.parent().addClass(this.errorClass);
101+
102+
return false;
103+
}
104+
105+
if (!$.validator.methods.min.call(this.validator, value, element[0], Waves.UI.constants.MINIMUM_TRANSACTION_FEE)) {
106+
$.growl.error({ message: 'Transaction fee is too small. It should be greater or equal to ' +
107+
Waves.UI.constants.MINIMUM_TRANSACTION_FEE });
108+
element.parent().addClass(this.errorClass);
109+
110+
return false;
111+
}
112+
113+
if (!$.validator.methods.decimal.call(this.validator, value, element[0], Currency.WAV.precision)) {
114+
$.growl.error({ message: 'Transaction fee must be a decimal number with dot (.) as ' +
115+
'a decimal separator with no more than ' + Currency.WAV.precision +
116+
' fraction digits' });
117+
element.parent().addClass(this.errorClass);
118+
119+
return false;
120+
}
121+
122+
element.parent().removeClass(this.errorClass);
123+
124+
return true;
99125
}
100126
};
101127

0 commit comments

Comments
 (0)