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
|
|
|
|
|
|
|
|
property alias input: amountToSendInput
|
|
|
|
|
2022-12-29 16:44:51 +00:00
|
|
|
property var locale
|
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
|
2022-12-14 21:06:14 +00:00
|
|
|
property bool cryptoFiatFlipped: false
|
|
|
|
property string cryptoValueToSend: !cryptoFiatFlipped ? amountToSendInput.text : txtFiatBalance.text
|
2022-12-19 13:02:56 +00:00
|
|
|
property string currentCurrency
|
|
|
|
property var getFiatValue: function(cryptoValue) {}
|
|
|
|
property var getCryptoValue: function(fiatValue) {}
|
2022-12-14 21:06:14 +00:00
|
|
|
|
|
|
|
signal reCalculateSuggestedRoute()
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
readonly property string zeroString: formatValue(0, 2)
|
|
|
|
property Timer waitTimer: Timer {
|
|
|
|
interval: 1000
|
|
|
|
onTriggered: reCalculateSuggestedRoute()
|
|
|
|
}
|
|
|
|
function formatValue(value, precision) {
|
|
|
|
const precisionVal = !!precision ? precision : (value === 0 ? 2 : 0)
|
2022-12-29 16:44:51 +00:00
|
|
|
return LocaleUtils.numberToLocaleString(value, precisionVal, root.locale)
|
2022-12-14 21:06:14 +00:00
|
|
|
}
|
|
|
|
function getFiatValue(value) {
|
|
|
|
if(!root.selectedAsset || !value)
|
|
|
|
return zeroString
|
2022-12-19 13:02:56 +00:00
|
|
|
let cryptoValue = root.getFiatValue(value)
|
2022-12-14 21:06:14 +00:00
|
|
|
return formatValue(parseFloat(cryptoValue))
|
|
|
|
}
|
|
|
|
function getCryptoValue(value) {
|
|
|
|
if(!root.selectedAsset || !value)
|
|
|
|
return zeroString
|
2022-12-19 13:02:56 +00:00
|
|
|
let cryptoValue = root.getCryptoValue(value)
|
2022-12-14 21:06:14 +00:00
|
|
|
return formatValue(parseFloat(cryptoValue))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onSelectedAssetChanged: {
|
|
|
|
if(!!root.selectedAsset) {
|
|
|
|
txtFiatBalance.text = !cryptoFiatFlipped ? d.getFiatValue(amountToSendInput.text): d.getCryptoValue(amountToSendInput.text)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 13:02:56 +00:00
|
|
|
onMaxFiatBalanceChanged: {
|
2022-12-29 16:44:51 +00:00
|
|
|
floatValidator.top = maxFiatBalance.amount
|
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 {
|
|
|
|
Layout.alignment: Qt.AlignLeft
|
|
|
|
AmountInputWithCursor {
|
|
|
|
id: amountToSendInput
|
|
|
|
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
|
|
|
|
text: amountToSendInput.placeholderText
|
|
|
|
font: amountToSendInput.input.placeholder.font
|
|
|
|
}
|
|
|
|
Keys.onReleased: {
|
|
|
|
const amount = amountToSendInput.text.trim()
|
|
|
|
if (!Utils.containsOnlyDigits(amount) || isNaN(amount)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
txtFiatBalance.text = !cryptoFiatFlipped ? d.getFiatValue(amount): d.getCryptoValue(amount)
|
|
|
|
d.waitTimer.restart()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
2022-12-19 13:02:56 +00:00
|
|
|
text: root.currentCurrency.toUpperCase()
|
2022-12-14 21:06:14 +00:00
|
|
|
font.pixelSize: amountToSendInput.input.edit.font.pixelSize
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
visible: cryptoFiatFlipped
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Item {
|
|
|
|
id: fiatBalanceLayout
|
|
|
|
Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
|
|
|
|
Layout.preferredWidth: txtFiatBalance.width + currencyText.width
|
|
|
|
Layout.preferredHeight: txtFiatBalance.height
|
|
|
|
StatusBaseText {
|
|
|
|
id: txtFiatBalance
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: parent.left
|
|
|
|
text: d.getFiatValue(amountToSendInput.text)
|
|
|
|
font.pixelSize: 13
|
|
|
|
color: Theme.palette.directColor5
|
|
|
|
}
|
|
|
|
StatusBaseText {
|
|
|
|
id: currencyText
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: txtFiatBalance.right
|
|
|
|
anchors.leftMargin: 4
|
2022-12-19 13:02:56 +00:00
|
|
|
text: !cryptoFiatFlipped ? root.currentCurrency.toUpperCase() : !!root.selectedAsset ? root.selectedAsset.symbol.toUpperCase() : ""
|
2022-12-14 21:06:14 +00:00
|
|
|
font.pixelSize: 13
|
|
|
|
color: Theme.palette.directColor5
|
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
onClicked: {
|
|
|
|
cryptoFiatFlipped = !cryptoFiatFlipped
|
|
|
|
amountToSendInput.validate()
|
|
|
|
if(!!amountToSendInput.text) {
|
|
|
|
const tempVal = Number.fromLocaleString(txtFiatBalance.text)
|
|
|
|
txtFiatBalance.text = !!amountToSendInput.text ? amountToSendInput.text : d.zeroString
|
|
|
|
amountToSendInput.text = tempVal
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|