From 55b2224593b76bd4b93a0f4c2e453ef598b5c3b2 Mon Sep 17 00:00:00 2001 From: Cuteivist Date: Wed, 17 Jul 2024 18:48:16 +0200 Subject: [PATCH] fix(wallet): Validate decimals for crypto when sending (#15523) --- .../shared/popups/send/views/AmountToSend.qml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ui/imports/shared/popups/send/views/AmountToSend.qml b/ui/imports/shared/popups/send/views/AmountToSend.qml index 70f1debcf1..6378e99110 100644 --- a/ui/imports/shared/popups/send/views/AmountToSend.qml +++ b/ui/imports/shared/popups/send/views/AmountToSend.qml @@ -117,6 +117,10 @@ ColumnLayout { input.validate() } + onSelectedHoldingChanged: { + input.validate() + } + StatusBaseText { text: root.caption font.pixelSize: 13 @@ -145,9 +149,17 @@ ColumnLayout { errorMessage: "" validate: (text) => { - var num = LocaleUtils.numberFromLocaleString(topAmountToSendInput.text, + const num = LocaleUtils.numberFromLocaleString(topAmountToSendInput.text, topAmountToSendInput.locale) - return !isNaN(num) && num > 0 && num <= root.maxInputBalance + if (isNaN(num) || num <= 0 || num > root.maxInputBalance) { + return false + } + if(!root.selectedHolding || !root.selectedHolding.marketDetails || !root.selectedHolding.marketDetails.currencyPrice) { + return false + } + const cryptoValueToSend = root.inputIsFiat ? num / root.selectedHolding.marketDetails.currencyPrice.amount : num + const cryptoValueToSendRaw = SQUtils.AmountsArithmetic.fromNumber(cryptoValueToSend, root.multiplierIndex).toString() + return cryptoValueToSendRaw >= 1 } } ]