From a9fd4513aaa16b4b9a051d41029ed5b701cc0590 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Mon, 5 Jul 2021 11:56:16 +0200 Subject: [PATCH] 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 --- src/status/utils.nim | 5 ++++- ui/shared/AssetAndAmountInput.qml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/status/utils.nim b/src/status/utils.nim index 738065e026..f46a11405e 100644 --- a/src/status/utils.nim +++ b/src/status/utils.nim @@ -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]) diff --git a/ui/shared/AssetAndAmountInput.qml b/ui/shared/AssetAndAmountInput.qml index 3fb2aa0100..536eeb6204 100644 --- a/ui/shared/AssetAndAmountInput.qml +++ b/ui/shared/AssetAndAmountInput.qml @@ -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) {