2022-12-14 21:06:14 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Controls.Validators 0.1
|
|
|
|
|
|
|
|
import "../controls"
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
id: root
|
|
|
|
|
2023-01-08 22:23:51 +00:00
|
|
|
property alias input: topAmountToSendInput
|
2023-02-17 12:56:31 +00:00
|
|
|
readonly property double inputNumber: topAmountToSendInput.text ? LocaleUtils.numberFromLocaleString(topAmountToSendInput.text) : 0
|
2023-02-17 14:09:15 +00:00
|
|
|
readonly property int minSendCryptoDecimals: !inputIsFiat ? LocaleUtils.fractionalPartLength(inputNumber) : 0
|
|
|
|
readonly property int minReceiveCryptoDecimals: !inputIsFiat ? minSendCryptoDecimals + 1 : 0
|
|
|
|
readonly property int minSendFiatDecimals: inputIsFiat ? LocaleUtils.fractionalPartLength(inputNumber) : 0
|
|
|
|
readonly property int minReceiveFiatDecimals: inputIsFiat ? minSendFiatDecimals + 1 : 0
|
2022-12-14 21:06:14 +00:00
|
|
|
|
2023-02-17 12:56:31 +00:00
|
|
|
property string selectedSymbol
|
2022-12-14 21:06:14 +00:00
|
|
|
property bool isBridgeTx: false
|
|
|
|
property bool interactive: false
|
2023-02-17 12:56:31 +00:00
|
|
|
property double maxInputBalance
|
2023-01-08 22:23:51 +00:00
|
|
|
property bool inputIsFiat: false
|
2023-02-17 12:56:31 +00:00
|
|
|
property double cryptoValueToSend
|
2023-01-08 22:23:51 +00:00
|
|
|
Binding {
|
|
|
|
target: root
|
|
|
|
property: "cryptoValueToSend"
|
2023-01-27 09:41:18 +00:00
|
|
|
value: {
|
2023-02-17 12:56:31 +00:00
|
|
|
const value = !inputIsFiat ? inputNumber : getCryptoValue(fiatValueToSend)
|
|
|
|
return root.selectedSymbol, value
|
2023-01-27 09:41:18 +00:00
|
|
|
}
|
2023-01-08 22:23:51 +00:00
|
|
|
delayed: true
|
|
|
|
}
|
|
|
|
property var fiatValueToSend
|
|
|
|
Binding {
|
|
|
|
target: root
|
|
|
|
property: "fiatValueToSend"
|
2023-01-27 09:41:18 +00:00
|
|
|
value: {
|
2023-02-17 12:56:31 +00:00
|
|
|
const value = inputIsFiat ? inputNumber : getFiatValue(cryptoValueToSend)
|
|
|
|
return root.selectedSymbol, value
|
2023-01-27 09:41:18 +00:00
|
|
|
}
|
2023-01-08 22:23:51 +00:00
|
|
|
delayed: true
|
|
|
|
}
|
2022-12-19 13:02:56 +00:00
|
|
|
property string currentCurrency
|
|
|
|
property var getFiatValue: function(cryptoValue) {}
|
|
|
|
property var getCryptoValue: function(fiatValue) {}
|
2023-02-17 12:56:31 +00:00
|
|
|
property var formatCurrencyAmount: function() {}
|
2022-12-14 21:06:14 +00:00
|
|
|
|
|
|
|
signal reCalculateSuggestedRoute()
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
2023-01-08 22:23:51 +00:00
|
|
|
readonly property string zeroString: LocaleUtils.numberToLocaleString(0, 2)
|
2022-12-14 21:06:14 +00:00
|
|
|
property Timer waitTimer: Timer {
|
|
|
|
interval: 1000
|
|
|
|
onTriggered: reCalculateSuggestedRoute()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-17 12:56:31 +00:00
|
|
|
onMaxInputBalanceChanged: {
|
|
|
|
floatValidator.top = maxInputBalance
|
2022-12-19 13:02:56 +00:00
|
|
|
input.validate()
|
|
|
|
}
|
|
|
|
|
2022-12-14 21:06:14 +00:00
|
|
|
StatusBaseText {
|
|
|
|
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
|
|
|
|
text: root.isBridgeTx ? qsTr("Amount to bridge") : qsTr("Amount to send")
|
|
|
|
font.pixelSize: 13
|
|
|
|
lineHeight: 18
|
|
|
|
lineHeightMode: Text.FixedHeight
|
|
|
|
color: Theme.palette.directColor1
|
|
|
|
}
|
|
|
|
RowLayout {
|
2023-01-08 22:23:51 +00:00
|
|
|
id: topItem
|
2023-02-17 12:56:31 +00:00
|
|
|
property double topAmountToSend: !inputIsFiat ? cryptoValueToSend : fiatValueToSend
|
|
|
|
property string topAmountSymbol: !inputIsFiat ? root.selectedSymbol : root.currentCurrency
|
2022-12-14 21:06:14 +00:00
|
|
|
Layout.alignment: Qt.AlignLeft
|
|
|
|
AmountInputWithCursor {
|
2023-01-08 22:23:51 +00:00
|
|
|
id: topAmountToSendInput
|
2022-12-14 21:06:14 +00:00
|
|
|
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
|
|
|
Layout.maximumWidth: 163
|
|
|
|
Layout.preferredWidth: (!!text) ? input.edit.paintedWidth : textMetrics.advanceWidth
|
|
|
|
placeholderText: d.zeroString
|
2022-12-19 13:02:56 +00:00
|
|
|
input.edit.color: input.valid ? Theme.palette.directColor1 : Theme.palette.dangerColor1
|
2022-12-14 21:06:14 +00:00
|
|
|
input.edit.readOnly: !root.interactive
|
|
|
|
validators: [
|
|
|
|
StatusFloatValidator {
|
|
|
|
id: floatValidator
|
|
|
|
bottom: 0
|
2023-02-17 12:56:31 +00:00
|
|
|
top: root.maxInputBalance
|
2022-12-14 21:06:14 +00:00
|
|
|
errorMessage: ""
|
|
|
|
}
|
|
|
|
]
|
|
|
|
TextMetrics {
|
|
|
|
id: textMetrics
|
2023-01-08 22:23:51 +00:00
|
|
|
text: topAmountToSendInput.placeholderText
|
|
|
|
font: topAmountToSendInput.input.placeholder.font
|
2022-12-14 21:06:14 +00:00
|
|
|
}
|
|
|
|
Keys.onReleased: {
|
2023-01-08 22:23:51 +00:00
|
|
|
const amount = topAmountToSendInput.text.trim()
|
2022-12-14 21:06:14 +00:00
|
|
|
if (!Utils.containsOnlyDigits(amount) || isNaN(amount)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
d.waitTimer.restart()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Item {
|
2023-01-08 22:23:51 +00:00
|
|
|
id: bottomItem
|
2023-02-17 12:56:31 +00:00
|
|
|
property double bottomAmountToSend: inputIsFiat ? cryptoValueToSend : fiatValueToSend
|
|
|
|
property string bottomAmountSymbol: inputIsFiat ? selectedSymbol : currentCurrency
|
2022-12-14 21:06:14 +00:00
|
|
|
Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
|
2023-01-08 22:23:51 +00:00
|
|
|
Layout.preferredWidth: txtBottom.width
|
|
|
|
Layout.preferredHeight: txtBottom.height
|
2022-12-14 21:06:14 +00:00
|
|
|
StatusBaseText {
|
2023-01-08 22:23:51 +00:00
|
|
|
id: txtBottom
|
2022-12-14 21:06:14 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: parent.left
|
2023-02-17 12:56:31 +00:00
|
|
|
text: root.formatCurrencyAmount(bottomItem.bottomAmountToSend, bottomItem.bottomAmountSymbol)
|
2022-12-14 21:06:14 +00:00
|
|
|
font.pixelSize: 13
|
|
|
|
color: Theme.palette.directColor5
|
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
onClicked: {
|
2023-01-08 22:23:51 +00:00
|
|
|
topAmountToSendInput.validate()
|
|
|
|
if(!!topAmountToSendInput.text) {
|
2023-02-17 12:56:31 +00:00
|
|
|
topAmountToSendInput.text = root.formatCurrencyAmount(bottomItem.bottomAmountToSend, bottomItem.bottomAmountSymbol, {onlyAmount: true})
|
2022-12-14 21:06:14 +00:00
|
|
|
}
|
2023-01-08 22:23:51 +00:00
|
|
|
inputIsFiat = !inputIsFiat
|
|
|
|
d.waitTimer.restart()
|
2022-12-14 21:06:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|