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
|
2022-12-14 21:06:14 +00:00
|
|
|
|
|
|
|
property var selectedAsset
|
|
|
|
property bool isBridgeTx: false
|
|
|
|
property bool interactive: false
|
2022-12-29 16:44:51 +00:00
|
|
|
property var maxFiatBalance
|
2023-01-08 22:23:51 +00:00
|
|
|
property bool inputIsFiat: false
|
|
|
|
property var cryptoValueToSend
|
|
|
|
Binding {
|
|
|
|
target: root
|
|
|
|
property: "cryptoValueToSend"
|
2023-01-27 09:41:18 +00:00
|
|
|
value: {
|
|
|
|
const value = !inputIsFiat ? getCryptoCurrencyAmount(LocaleUtils.numberFromLocaleString(topAmountToSendInput.text)) : getCryptoValue(fiatValueToSend ? fiatValueToSend.amount : 0.0)
|
|
|
|
return root.selectedAsset, value
|
|
|
|
}
|
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: {
|
|
|
|
const value = inputIsFiat ? getFiatCurrencyAmount(LocaleUtils.numberFromLocaleString(topAmountToSendInput.text)) : getFiatValue(cryptoValueToSend ? cryptoValueToSend.amount : 0.0)
|
|
|
|
return root.selectedAsset, value
|
|
|
|
}
|
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-01-08 22:23:51 +00:00
|
|
|
property var getFiatCurrencyAmount: function(fiatValue) {}
|
|
|
|
property var getCryptoCurrencyAmount: function(cryptoValue) {}
|
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-01-08 22:23:51 +00:00
|
|
|
function formatValue(value) {
|
|
|
|
if (!value) {
|
|
|
|
return zeroString
|
|
|
|
}
|
|
|
|
return LocaleUtils.currencyAmountToLocaleString(value)
|
2022-12-14 21:06:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 13:02:56 +00:00
|
|
|
onMaxFiatBalanceChanged: {
|
2023-01-08 22:23:51 +00:00
|
|
|
floatValidator.top = maxFiatBalance ? maxFiatBalance.amount : 0.0
|
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
|
|
|
|
property var topAmountToSend: !inputIsFiat ? cryptoValueToSend : fiatValueToSend
|
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
|
2022-12-29 16:44:51 +00:00
|
|
|
top: root.maxFiatBalance.amount
|
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
|
|
|
|
property var bottomAmountToSend: inputIsFiat ? cryptoValueToSend : fiatValueToSend
|
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-01-08 22:23:51 +00:00
|
|
|
text: d.formatValue(bottomItem.bottomAmountToSend)
|
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) {
|
|
|
|
topAmountToSendInput.text = LocaleUtils.currencyAmountToLocaleString(bottomItem.bottomAmountToSend, {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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|