fix(wallet): make it possible to send a 0 tx with a warning

Fixes #2652
This commit is contained in:
Jonathan Rainville 2021-07-07 14:37:49 -04:00 committed by Iuri Matias
parent b99300bf10
commit 2716abf096
5 changed files with 26 additions and 11 deletions

View File

@ -59,6 +59,7 @@ Theme {
property color primary: blue
property color danger: red
property color success: green
property color warning: orange
property color primaryMenuItemHover: blue
property color primaryMenuItemTextHover: almostBlack
property color backgroundTertiary: tenPercentBlue

View File

@ -59,6 +59,7 @@ Theme {
property color primary: blue
property color danger: red
property color success: green
property color warning: orange
property color primaryMenuItemHover: blue
property color primaryMenuItemTextHover: white
property color backgroundTertiary: tenPercentBlue

View File

@ -7,8 +7,7 @@ import "../imports"
Item {
//% "Insufficient balance"
property string balanceErrorMessage: qsTrId("insufficient-balance")
//% "Must be greater than 0"
property string greaterThan0ErrorMessage: qsTrId("must-be-greater-than-0")
property string greaterThanOrEqualTo0ErrorMessage: qsTr("Must be greater than or equal to 0")
//% "This needs to be a number"
property string invalidInputErrorMessage: qsTrId("this-needs-to-be-a-number")
//% "Please enter an amount"
@ -23,6 +22,8 @@ Item {
property bool isDirty: false
property bool validateBalance: true
property bool isValid: false
property string validationError
property var formattedInputValue
id: root
@ -35,7 +36,7 @@ Item {
let error = ""
const hasTyped = checkDirty ? isDirty : true
const balance = parseFloat(txtBalance.text || "0.00")
const input = parseFloat(inputAmount.text || "0.00")
formattedInputValue = parseFloat(inputAmount.text || "0.00")
const noInput = inputAmount.text === ""
if (noInput && hasTyped) {
error = noInputErrorMessage
@ -43,19 +44,19 @@ Item {
} else if (isNaN(inputAmount.text)) {
error = invalidInputErrorMessage
isValid = false
} else if (input <= 0.00 && hasTyped) {
error = greaterThan0ErrorMessage
} else if (formattedInputValue < 0.00 && hasTyped) {
error = greaterThanOrEqualTo0ErrorMessage
isValid = false
} else if (validateBalance && input > balance && !noInput) {
} else if (validateBalance && formattedInputValue > balance && !noInput) {
error = balanceErrorMessage
isValid = false
}
if (!isValid) {
inputAmount.validationError = error
root.validationError = error
txtBalanceDesc.color = Style.current.danger
txtBalance.color = Style.current.danger
} else {
inputAmount.validationError = ""
root.validationError = ""
txtBalanceDesc.color = Style.current.secondaryText
txtBalance.color = Qt.binding(function() { return txtBalance.hovered ? Style.current.textColor : Style.current.secondaryText })
}
@ -127,6 +128,17 @@ Item {
customHeight: 56
validationErrorAlignment: TextEdit.AlignRight
validationErrorTopMargin: 8
validationErrorColor: formattedInputValue === 0 ? Style.current.warning : Style.current.danger
validationError: {
if (root.validationError) {
return root.validationError
}
if (formattedInputValue === 0) {
return qsTr("The amount is 0. Proceed only if this is desired.")
}
return ""
}
Keys.onReleased: {
let amount = inputAmount.text.trim()

View File

@ -13,6 +13,7 @@ Item {
property string validationError: ""
property alias validationErrorAlignment: validationErrorText.horizontalAlignment
property int validationErrorTopMargin: 1
property color validationErrorColor: Style.current.danger
property string label: ""
readonly property bool hasLabel: label !== ""
property color bgColor: Style.current.inputBackground
@ -70,7 +71,7 @@ Item {
border.width: (!!validationError || inputValue.focus) ? 1 : 0
border.color: {
if (!!validationError) {
return Style.current.danger
return validationErrorColor
}
if (!inputBox.readOnly && inputValue.focus) {
return Style.current.inputBorderFocus
@ -180,7 +181,7 @@ Item {
readOnly: true
font.pixelSize: 12
height: 16
color: Style.current.danger
color: validationErrorColor
width: inputRectangle.width
wrapMode: TextEdit.Wrap
}

View File

@ -152,7 +152,7 @@ Item {
StyledText {
id: profileNotFoundMessage
color: Style.current.darkGrey
color: Style.current.secondaryText
visible: root.showProfileNotFoundMessage
font.pixelSize: 15
anchors.horizontalCenter: parent.horizontalCenter