2023-08-10 12:23:59 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
2023-01-18 19:54:14 +00:00
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
|
|
|
|
import shared.controls 1.0
|
|
|
|
|
2023-04-19 12:39:50 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
|
2023-01-18 19:54:14 +00:00
|
|
|
ColumnLayout {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property int mode: HoldingTypes.Mode.Add
|
|
|
|
property alias tokenName: item.name
|
|
|
|
property alias tokenShortName: item.shortName
|
2023-04-19 12:39:50 +00:00
|
|
|
property alias tokenAmount: item.amount
|
2023-01-18 19:54:14 +00:00
|
|
|
property alias tokenImage: item.iconSource
|
2024-05-28 13:11:29 +00:00
|
|
|
property alias tokenDecimals: item.decimals
|
2023-01-18 19:54:14 +00:00
|
|
|
property alias amountText: amountInput.text
|
|
|
|
property alias amount: amountInput.amount
|
2024-03-05 14:12:03 +00:00
|
|
|
property alias decimals: amountInput.tokenDecimals
|
2023-08-10 12:23:59 +00:00
|
|
|
property alias multiplierIndex: amountInput.multiplierIndex
|
2023-01-18 19:54:14 +00:00
|
|
|
property alias tokenCategoryText: tokenLabel.text
|
2023-04-19 12:39:50 +00:00
|
|
|
property alias networkLabelText: d.networkLabelText
|
2023-01-18 19:54:14 +00:00
|
|
|
property alias addOrUpdateButtonEnabled: addOrUpdateButton.enabled
|
|
|
|
property alias allowDecimals: amountInput.allowDecimals
|
2023-04-19 12:39:50 +00:00
|
|
|
readonly property bool amountValid: amountInput.valid && !!amountInput.text
|
|
|
|
|
|
|
|
property var networksModel
|
2023-01-18 19:54:14 +00:00
|
|
|
|
|
|
|
signal addClicked
|
|
|
|
signal updateClicked
|
|
|
|
signal removeClicked
|
|
|
|
|
2023-08-10 12:23:59 +00:00
|
|
|
function setAmount(amount, multiplierIndex = 0) {
|
|
|
|
console.assert(typeof amount === "string")
|
|
|
|
amountInput.setAmount(amount, multiplierIndex)
|
2023-01-18 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
// values from design
|
|
|
|
readonly property int defaultHeight: 44
|
|
|
|
readonly property int defaultSpacing: 8
|
2023-04-19 12:39:50 +00:00
|
|
|
|
|
|
|
property string networkLabelText: qsTr("Network for airdrop")
|
2023-01-18 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 12:39:50 +00:00
|
|
|
component CustomText: StatusBaseText {
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
font.pixelSize: 12
|
|
|
|
elide: Text.ElideRight
|
2023-01-18 19:54:14 +00:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
Layout.leftMargin: d.defaultSpacing
|
2023-04-19 12:39:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spacing: d.defaultSpacing
|
|
|
|
|
|
|
|
CustomText {
|
|
|
|
id: tokenLabel
|
|
|
|
|
|
|
|
Layout.topMargin: 2 * d.defaultSpacing
|
2023-01-18 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TokenItem {
|
|
|
|
id: item
|
2023-04-19 12:39:50 +00:00
|
|
|
|
2023-01-18 19:54:14 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
|
2023-04-19 12:39:50 +00:00
|
|
|
Loader {
|
2023-04-27 21:38:09 +00:00
|
|
|
id: networksComboBoxLoader
|
|
|
|
|
2023-04-19 12:39:50 +00:00
|
|
|
active: !!root.networksModel
|
|
|
|
visible: active
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: 14
|
|
|
|
Layout.bottomMargin: d.defaultSpacing
|
|
|
|
|
|
|
|
sourceComponent: ColumnLayout {
|
2023-04-27 21:38:09 +00:00
|
|
|
spacing: 10
|
|
|
|
|
|
|
|
property alias currentAmount: inlineNetworksComboBox.currentAmount
|
2024-03-05 14:12:03 +00:00
|
|
|
property alias decimals: inlineNetworksComboBox.decimals
|
2023-08-10 12:23:59 +00:00
|
|
|
property alias currentMultiplierIndex:
|
|
|
|
inlineNetworksComboBox.currentMultiplierIndex
|
|
|
|
property alias currentInfiniteAmount:
|
|
|
|
inlineNetworksComboBox.currentInfiniteAmount
|
2023-04-19 12:39:50 +00:00
|
|
|
|
|
|
|
CustomText {
|
|
|
|
id: networkLabel
|
|
|
|
|
|
|
|
text: d.networkLabelText
|
|
|
|
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
font.pixelSize: 12
|
|
|
|
elide: Text.ElideRight
|
|
|
|
}
|
|
|
|
|
|
|
|
InlineNetworksComboBox {
|
2023-04-27 21:38:09 +00:00
|
|
|
id: inlineNetworksComboBox
|
|
|
|
|
2023-04-19 12:39:50 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
model: root.networksModel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-18 19:54:14 +00:00
|
|
|
AmountInput {
|
|
|
|
id: amountInput
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
2023-04-27 21:38:09 +00:00
|
|
|
Layout.bottomMargin: (validationError !== "") ? root.spacing * 2 : 0
|
2023-01-18 19:54:14 +00:00
|
|
|
customHeight: d.defaultHeight
|
|
|
|
allowDecimals: true
|
|
|
|
keepHeight: true
|
2023-04-27 21:38:09 +00:00
|
|
|
|
|
|
|
validateMaximumAmount:
|
|
|
|
!!networksComboBoxLoader.item &&
|
|
|
|
!networksComboBoxLoader.item.currentInfiniteAmount
|
|
|
|
|
|
|
|
maximumAmount: !!networksComboBoxLoader.item
|
2023-08-10 12:23:59 +00:00
|
|
|
? networksComboBoxLoader.item.currentAmount : "0"
|
2024-03-05 14:12:03 +00:00
|
|
|
tokenDecimals: !!networksComboBoxLoader.item
|
2024-05-28 13:11:29 +00:00
|
|
|
? networksComboBoxLoader.item.decimals : root.tokenDecimals
|
2023-08-10 12:23:59 +00:00
|
|
|
multiplierIndex: !!networksComboBoxLoader.item
|
|
|
|
? networksComboBoxLoader.item.currentMultiplierIndex : 0
|
2023-04-27 21:38:09 +00:00
|
|
|
|
2023-03-23 09:54:16 +00:00
|
|
|
onKeyPressed: {
|
2023-08-10 12:23:59 +00:00
|
|
|
if(!addOrUpdateButton.enabled)
|
|
|
|
return
|
2023-03-23 09:54:16 +00:00
|
|
|
|
2024-04-15 05:28:29 +00:00
|
|
|
// additionally accept dot (.) and convert it to the correct decimal point char
|
|
|
|
if (event.key === Qt.Key_Period || event.key === Qt.Key_Comma) {
|
|
|
|
// Only one decimal point is allowed
|
|
|
|
if(amountInput.text.indexOf(amountInput.locale.decimalPoint) === -1)
|
|
|
|
amountInput.textField.insert(amountInput.textField.cursorPosition, amountInput.locale.decimalPoint)
|
|
|
|
event.accepted = true
|
|
|
|
} else if ((event.key > Qt.Key_9 && event.key <= Qt.Key_BraceRight) || event.key === Qt.Key_Space) {
|
|
|
|
event.accepted = true
|
|
|
|
} else if(event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
|
2023-03-23 09:54:16 +00:00
|
|
|
addOrUpdateButton.clicked()
|
2024-04-15 05:28:29 +00:00
|
|
|
}
|
2023-03-23 09:54:16 +00:00
|
|
|
}
|
|
|
|
onVisibleChanged: {
|
|
|
|
if(visible)
|
|
|
|
forceActiveFocus()
|
|
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
|
|
if(visible)
|
|
|
|
forceActiveFocus()
|
|
|
|
}
|
2023-01-18 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StatusButton {
|
|
|
|
id: addOrUpdateButton
|
|
|
|
|
2023-08-10 12:23:59 +00:00
|
|
|
text: root.mode === HoldingTypes.Mode.Add ? qsTr("Add")
|
|
|
|
: qsTr("Update")
|
2023-01-18 19:54:14 +00:00
|
|
|
Layout.preferredHeight: d.defaultHeight
|
|
|
|
Layout.topMargin: d.defaultSpacing
|
|
|
|
Layout.fillWidth: true
|
|
|
|
onClicked: root.mode === HoldingTypes.Mode.Add
|
|
|
|
? root.addClicked() : root.updateClicked()
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusFlatButton {
|
|
|
|
text: qsTr("Remove")
|
|
|
|
Layout.preferredHeight: d.defaultHeight
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: d.defaultSpacing
|
2023-01-24 21:49:07 +00:00
|
|
|
visible: root.mode === HoldingTypes.Mode.UpdateOrRemove
|
2023-01-18 19:54:14 +00:00
|
|
|
type: StatusBaseButton.Type.Danger
|
|
|
|
|
|
|
|
onClicked: root.removeClicked()
|
|
|
|
}
|
|
|
|
}
|