2023-09-15 08:51:06 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
2022-12-14 21:06:14 +00:00
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
2023-09-15 08:51:06 +00:00
|
|
|
import StatusQ.Core.Utils 0.1 as SQUtils
|
2022-12-14 21:06:14 +00:00
|
|
|
import StatusQ.Controls.Validators 0.1
|
|
|
|
|
|
|
|
import "../controls"
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
id: root
|
|
|
|
|
2023-09-15 08:51:06 +00:00
|
|
|
readonly property alias input: topAmountToSendInput
|
|
|
|
readonly property bool inputNumberValid: !!input.text && !isNaN(d.parsedInput)
|
|
|
|
|
|
|
|
readonly property int minSendCryptoDecimals:
|
|
|
|
!inputIsFiat ? LocaleUtils.fractionalPartLength(d.inputNumber) : 0
|
|
|
|
readonly property int minReceiveCryptoDecimals:
|
|
|
|
!inputIsFiat ? minSendCryptoDecimals + 1 : 0
|
|
|
|
readonly property int minSendFiatDecimals:
|
|
|
|
inputIsFiat ? LocaleUtils.fractionalPartLength(d.inputNumber) : 0
|
|
|
|
readonly property int minReceiveFiatDecimals:
|
|
|
|
inputIsFiat ? minSendFiatDecimals + 1 : 0
|
|
|
|
|
2024-02-05 16:44:49 +00:00
|
|
|
property var selectedHolding // Crypto asset symbol like ETH
|
2023-09-15 08:51:06 +00:00
|
|
|
property string currentCurrency // Fiat currency symbol like USD
|
|
|
|
|
|
|
|
property int multiplierIndex // How divisible the token is, 18 for ETH
|
|
|
|
|
|
|
|
property double maxInputBalance
|
2022-12-14 21:06:14 +00:00
|
|
|
|
|
|
|
property bool isBridgeTx: false
|
|
|
|
property bool interactive: false
|
2023-01-08 22:23:51 +00:00
|
|
|
property bool inputIsFiat: false
|
2023-09-15 08:51:06 +00:00
|
|
|
|
|
|
|
// Crypto value to send expressed in base units (like wei for ETH),
|
|
|
|
// as a string representing integer decimal
|
|
|
|
readonly property alias cryptoValueToSend: d.cryptoValueRawToSend
|
|
|
|
|
|
|
|
readonly property alias cryptoValueToSendFloat: d.cryptoValueToSend
|
|
|
|
|
|
|
|
property var formatCurrencyAmount:
|
|
|
|
(amount, symbol, options = null, locale = null) => {}
|
2022-12-14 21:06:14 +00:00
|
|
|
|
|
|
|
signal reCalculateSuggestedRoute()
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
2023-09-15 08:51:06 +00:00
|
|
|
|
|
|
|
property double cryptoValueToSend
|
|
|
|
property double fiatValueToSend
|
|
|
|
|
|
|
|
Binding on cryptoValueToSend {
|
|
|
|
value: {
|
2024-02-05 16:44:49 +00:00
|
|
|
root.selectedHolding
|
|
|
|
if(!root.selectedHolding || !root.selectedHolding.marketDetails || !root.selectedHolding.marketDetails.currencyPrice) {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return root.inputIsFiat ? d.fiatValueToSend/root.selectedHolding.marketDetails.currencyPrice.amount
|
2023-09-15 08:51:06 +00:00
|
|
|
: d.inputNumber
|
|
|
|
}
|
|
|
|
delayed: true
|
|
|
|
}
|
|
|
|
|
|
|
|
Binding on fiatValueToSend {
|
|
|
|
value: {
|
2024-02-05 16:44:49 +00:00
|
|
|
root.selectedHolding
|
|
|
|
if(!root.selectedHolding || !root.selectedHolding.marketDetails || !root.selectedHolding.marketDetails.currencyPrice) {
|
|
|
|
return 0
|
|
|
|
}
|
2023-09-15 08:51:06 +00:00
|
|
|
return root.inputIsFiat ? d.inputNumber
|
2024-02-05 16:44:49 +00:00
|
|
|
: d.cryptoValueToSend * root.selectedHolding.marketDetails.currencyPrice.amount
|
2023-09-15 08:51:06 +00:00
|
|
|
}
|
|
|
|
delayed: true
|
|
|
|
}
|
|
|
|
|
2024-02-05 16:44:49 +00:00
|
|
|
readonly property string selectedSymbol: !!root.selectedHolding && !!root.selectedHolding.symbol ? root.selectedHolding.symbol: ""
|
|
|
|
|
2023-09-15 08:51:06 +00:00
|
|
|
readonly property string cryptoValueRawToSend: {
|
|
|
|
if (!root.inputNumberValid)
|
|
|
|
return "0"
|
|
|
|
|
|
|
|
return SQUtils.AmountsArithmetic.fromNumber(
|
|
|
|
d.cryptoValueToSend, root.multiplierIndex).toString()
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly property string zeroString:
|
|
|
|
LocaleUtils.numberToLocaleString(0, 2, LocaleUtils.userInputLocale)
|
|
|
|
|
|
|
|
readonly property double parsedInput:
|
|
|
|
LocaleUtils.numberFromLocaleString(topAmountToSendInput.text,
|
|
|
|
LocaleUtils.userInputLocale)
|
|
|
|
|
|
|
|
readonly property double inputNumber:
|
|
|
|
root.inputNumberValid ? d.parsedInput : 0
|
|
|
|
|
|
|
|
readonly property Timer waitTimer: Timer {
|
2022-12-14 21:06:14 +00:00
|
|
|
interval: 1000
|
|
|
|
onTriggered: reCalculateSuggestedRoute()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-17 12:56:31 +00:00
|
|
|
onMaxInputBalanceChanged: {
|
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
|
2023-09-15 08:51:06 +00:00
|
|
|
|
|
|
|
text: root.isBridgeTx ? qsTr("Amount to bridge")
|
|
|
|
: qsTr("Amount to send")
|
2022-12-14 21:06:14 +00:00
|
|
|
font.pixelSize: 13
|
|
|
|
lineHeight: 18
|
|
|
|
lineHeightMode: Text.FixedHeight
|
|
|
|
color: Theme.palette.directColor1
|
|
|
|
}
|
2023-09-15 08:51:06 +00:00
|
|
|
|
2022-12-14 21:06:14 +00:00
|
|
|
RowLayout {
|
2023-01-08 22:23:51 +00:00
|
|
|
id: topItem
|
2023-09-15 08:51:06 +00:00
|
|
|
|
|
|
|
property double topAmountToSend: !inputIsFiat ? d.cryptoValueToSend
|
|
|
|
: d.fiatValueToSend
|
2024-02-05 16:44:49 +00:00
|
|
|
property string topAmountSymbol: !inputIsFiat ? d.selectedSymbol
|
2023-09-15 08:51:06 +00:00
|
|
|
: root.currentCurrency
|
2022-12-14 21:06:14 +00:00
|
|
|
Layout.alignment: Qt.AlignLeft
|
2023-09-15 08:51:06 +00:00
|
|
|
|
2022-12-14 21:06:14 +00:00
|
|
|
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
|
2023-06-09 10:38:40 +00:00
|
|
|
Layout.maximumWidth: 250
|
2023-09-15 08:51:06 +00:00
|
|
|
Layout.preferredWidth: !!text ? input.edit.paintedWidth
|
|
|
|
: textMetrics.advanceWidth
|
2022-12-14 21:06:14 +00:00
|
|
|
placeholderText: d.zeroString
|
2023-09-15 08:51:06 +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
|
2023-09-15 08:51:06 +00:00
|
|
|
|
2022-12-14 21:06:14 +00:00
|
|
|
validators: [
|
|
|
|
StatusFloatValidator {
|
|
|
|
id: floatValidator
|
|
|
|
bottom: 0
|
|
|
|
errorMessage: ""
|
2023-04-04 16:13:33 +00:00
|
|
|
locale: LocaleUtils.userInputLocale
|
2023-09-15 08:51:06 +00:00
|
|
|
},
|
|
|
|
StatusValidator {
|
|
|
|
errorMessage: ""
|
|
|
|
|
|
|
|
validate: (text) => {
|
|
|
|
const num = parseFloat(text)
|
|
|
|
|
|
|
|
if (isNaN(num))
|
|
|
|
return true
|
|
|
|
|
|
|
|
return num <= root.maxInputBalance
|
|
|
|
}
|
2022-12-14 21:06:14 +00:00
|
|
|
}
|
|
|
|
]
|
2023-09-15 08:51:06 +00:00
|
|
|
|
2022-12-14 21:06:14 +00:00
|
|
|
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
|
|
|
}
|
2023-09-15 08:51:06 +00:00
|
|
|
|
2022-12-14 21:06:14 +00:00
|
|
|
Keys.onReleased: {
|
2023-09-15 08:51:06 +00:00
|
|
|
const amount = LocaleUtils.numberFromLocaleString(
|
|
|
|
topAmountToSendInput.text,
|
|
|
|
LocaleUtils.userInputLocale)
|
|
|
|
if (!isNaN(amount))
|
|
|
|
d.waitTimer.restart()
|
2022-12-14 21:06:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Item {
|
2023-01-08 22:23:51 +00:00
|
|
|
id: bottomItem
|
2023-09-15 08:51:06 +00:00
|
|
|
|
|
|
|
property double bottomAmountToSend: inputIsFiat ? d.cryptoValueToSend
|
|
|
|
: d.fiatValueToSend
|
2024-02-05 16:44:49 +00:00
|
|
|
property string bottomAmountSymbol: inputIsFiat ? d.selectedSymbol
|
2023-09-15 08:51:06 +00:00
|
|
|
: 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
|
2023-09-15 08:51:06 +00:00
|
|
|
|
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-09-15 08:51:06 +00:00
|
|
|
text: root.formatCurrencyAmount(bottomItem.bottomAmountToSend,
|
|
|
|
bottomItem.bottomAmountSymbol)
|
2022-12-14 21:06:14 +00:00
|
|
|
font.pixelSize: 13
|
|
|
|
color: Theme.palette.directColor5
|
|
|
|
}
|
2023-09-15 08:51:06 +00:00
|
|
|
|
2022-12-14 21:06:14 +00:00
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
2023-09-15 08:51:06 +00:00
|
|
|
|
2022-12-14 21:06:14 +00:00
|
|
|
onClicked: {
|
2023-01-08 22:23:51 +00:00
|
|
|
topAmountToSendInput.validate()
|
|
|
|
if(!!topAmountToSendInput.text) {
|
2023-09-15 08:51:06 +00:00
|
|
|
topAmountToSendInput.text = root.formatCurrencyAmount(
|
|
|
|
bottomItem.bottomAmountToSend,
|
|
|
|
bottomItem.bottomAmountSymbol,
|
|
|
|
{ noSymbol: true, rawAmount: true },
|
|
|
|
LocaleUtils.userInputLocale)
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|