fix(wallet): Clicking Request Address when sending -1 STT crashes the app

Validation check is updated, so user cannot enter zero or less than zero value in amount input field.
Also in utils.nim a crash prevention check is added so if we try to convert a less than zero float number to an unsigned number, app won't crash any more, but that casting will return a zero as unsigned int number.

Fixes: #2755
This commit is contained in:
Sale Djenic 2021-07-05 11:56:16 +02:00 committed by Iuri Matias
parent 1b06ed5d98
commit a9fd4513aa
2 changed files with 5 additions and 2 deletions

View File

@ -45,7 +45,10 @@ proc handleRPCErrors*(response: string) =
proc toStUInt*[bits: static[int]](flt: float, T: typedesc[StUint[bits]]): T =
var stringValue = fmt"{flt:<.0f}"
stringValue.removeSuffix('.')
result = parse($stringValue, StUint[bits])
if (flt >= 0):
result = parse($stringValue, StUint[bits])
else:
result = parse("0", StUint[bits])
proc toUInt256*(flt: float): UInt256 =
toStUInt(flt, StUInt[256])

View File

@ -43,7 +43,7 @@ Item {
} else if (isNaN(inputAmount.text)) {
error = invalidInputErrorMessage
isValid = false
} else if (input === 0.00 && hasTyped) {
} else if (input <= 0.00 && hasTyped) {
error = greaterThan0ErrorMessage
isValid = false
} else if (validateBalance && input > balance && !noInput) {