2023-05-18 16:08:30 +00:00
|
|
|
|
import QtQuick 2.15
|
2023-08-30 08:25:32 +00:00
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
|
import QtQml.Models 2.15
|
2023-05-18 16:08:30 +00:00
|
|
|
|
import QtGraphicalEffects 1.0
|
|
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
import StatusQ.Popups.Dialog 0.1
|
|
|
|
|
import StatusQ.Core.Theme 0.1
|
2023-08-07 13:31:07 +00:00
|
|
|
|
import StatusQ.Core.Utils 0.1 as SQUtils
|
2023-05-18 16:08:30 +00:00
|
|
|
|
|
2023-06-23 06:17:04 +00:00
|
|
|
|
import AppLayouts.Communities.panels 1.0
|
2023-05-18 16:08:30 +00:00
|
|
|
|
|
|
|
|
|
import utils 1.0
|
2023-08-30 08:25:32 +00:00
|
|
|
|
import shared.controls 1.0
|
|
|
|
|
|
2023-05-18 16:08:30 +00:00
|
|
|
|
|
|
|
|
|
StatusDialog {
|
|
|
|
|
id: root
|
|
|
|
|
|
|
|
|
|
property string communityName
|
2023-08-07 13:31:07 +00:00
|
|
|
|
property bool isAsset // If asset isAsset = true; if collectible --> isAsset = false
|
2023-05-18 16:08:30 +00:00
|
|
|
|
property string tokenName
|
2023-08-10 12:23:59 +00:00
|
|
|
|
property string remainingTokens
|
|
|
|
|
property int multiplierIndex
|
2023-05-18 16:08:30 +00:00
|
|
|
|
property url tokenSource
|
2023-08-07 13:31:07 +00:00
|
|
|
|
property string chainName
|
|
|
|
|
|
2023-09-01 09:27:44 +00:00
|
|
|
|
readonly property alias amountToBurn: d.amountToBurn
|
|
|
|
|
readonly property alias selectedAccountAddress: d.accountAddress
|
|
|
|
|
|
2023-08-07 13:31:07 +00:00
|
|
|
|
// Fees related properties:
|
|
|
|
|
property string feeText
|
|
|
|
|
property string feeErrorText: ""
|
|
|
|
|
property bool isFeeLoading
|
|
|
|
|
readonly property string feeLabel: qsTr("Burn %1 token on %2").arg(root.tokenName).arg(root.chainName)
|
|
|
|
|
|
|
|
|
|
// Account expected roles: address, name, color, emoji, walletType
|
|
|
|
|
property var accounts
|
2023-05-18 16:08:30 +00:00
|
|
|
|
|
2023-08-10 12:23:59 +00:00
|
|
|
|
signal burnClicked(string burnAmount, string accountAddress)
|
2023-05-18 16:08:30 +00:00
|
|
|
|
signal cancelClicked
|
|
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
|
id: d
|
|
|
|
|
|
2023-08-10 12:23:59 +00:00
|
|
|
|
readonly property real remainingTokensFloat:
|
|
|
|
|
SQUtils.AmountsArithmetic.toNumber(
|
|
|
|
|
root.remainingTokens, root.multiplierIndex)
|
|
|
|
|
|
|
|
|
|
readonly property string remainingTokensDisplayText:
|
|
|
|
|
LocaleUtils.numberToLocaleString(remainingTokensFloat)
|
|
|
|
|
|
2023-08-07 13:31:07 +00:00
|
|
|
|
property string accountAddress
|
2023-09-01 09:27:44 +00:00
|
|
|
|
property string amountToBurn: !isFormValid ? "" :
|
|
|
|
|
specificAmountButton.checked ? amountInput.amount : root.remainingTokens
|
2023-08-30 08:25:32 +00:00
|
|
|
|
|
2023-08-07 13:31:07 +00:00
|
|
|
|
readonly property bool isFeeError: root.feeErrorText !== ""
|
2023-08-30 08:25:32 +00:00
|
|
|
|
|
|
|
|
|
readonly property bool isFormValid:
|
|
|
|
|
(specificAmountButton.checked && amountInput.valid && amountInput.text)
|
|
|
|
|
|| allTokensButton.checked
|
2023-05-18 16:08:30 +00:00
|
|
|
|
|
|
|
|
|
function initialize() {
|
|
|
|
|
specificAmountButton.checked = true
|
2023-08-30 08:25:32 +00:00
|
|
|
|
amountInput.forceActiveFocus()
|
2023-05-18 16:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getVerticalPadding() {
|
|
|
|
|
return root.topPadding + root.bottomPadding
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getHorizontalPadding() {
|
|
|
|
|
return root.leftPadding + root.rightPadding
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 08:25:32 +00:00
|
|
|
|
width: 600 // by design
|
2023-05-18 16:08:30 +00:00
|
|
|
|
implicitHeight: content.implicitHeight + footer.height + header.height + d.getVerticalPadding()
|
|
|
|
|
|
|
|
|
|
contentItem: ColumnLayout {
|
|
|
|
|
id: content
|
|
|
|
|
|
|
|
|
|
spacing: Style.current.padding
|
|
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
2023-08-30 08:25:32 +00:00
|
|
|
|
text: {
|
|
|
|
|
if (Number.isInteger(d.remainingTokensFloat))
|
|
|
|
|
return qsTr("How many of %1’s remaining %Ln %2 token(s) would you like to burn?",
|
|
|
|
|
"", d.remainingTokensFloat).arg(root.communityName).arg(root.tokenName)
|
|
|
|
|
|
|
|
|
|
return qsTr("How many of %1’s remaining %2 %3 tokens would you like to burn?")
|
|
|
|
|
.arg(root.communityName).arg(d.remainingTokensDisplayText).arg(root.tokenName)
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-18 16:08:30 +00:00
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
|
lineHeight: 1.2
|
|
|
|
|
font.pixelSize: Style.current.primaryTextFontSize
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 08:25:32 +00:00
|
|
|
|
Item {
|
2023-05-18 16:08:30 +00:00
|
|
|
|
Layout.bottomMargin: 12
|
|
|
|
|
Layout.leftMargin: -Style.current.halfPadding
|
2023-08-30 08:25:32 +00:00
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
|
|
implicitHeight: childrenRect.height
|
2023-05-18 16:08:30 +00:00
|
|
|
|
|
2023-08-30 08:25:32 +00:00
|
|
|
|
readonly property int spacing: 26
|
2023-05-18 16:08:30 +00:00
|
|
|
|
|
|
|
|
|
ColumnLayout {
|
2023-08-30 08:25:32 +00:00
|
|
|
|
id: specificAmountColumn
|
|
|
|
|
|
2023-05-18 16:08:30 +00:00
|
|
|
|
StatusRadioButton {
|
|
|
|
|
id: specificAmountButton
|
|
|
|
|
|
2023-08-30 08:25:32 +00:00
|
|
|
|
Layout.preferredWidth: amountInput.Layout.preferredWidth
|
|
|
|
|
+ amountInput.Layout.leftMargin
|
|
|
|
|
|
2023-05-18 16:08:30 +00:00
|
|
|
|
text: qsTr("Specific amount")
|
|
|
|
|
font.pixelSize: Style.current.primaryTextFontSize
|
|
|
|
|
ButtonGroup.group: radioGroup
|
|
|
|
|
|
2023-09-01 09:27:44 +00:00
|
|
|
|
onToggled: if(checked) amountInput.forceActiveFocus()
|
2023-05-18 16:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 08:25:32 +00:00
|
|
|
|
AmountInput {
|
|
|
|
|
id: amountInput
|
2023-05-18 16:08:30 +00:00
|
|
|
|
|
|
|
|
|
Layout.preferredWidth: 192
|
|
|
|
|
Layout.leftMargin: 30
|
2023-08-30 08:25:32 +00:00
|
|
|
|
customHeight: 44
|
|
|
|
|
|
|
|
|
|
allowDecimals: root.multiplierIndex > 0
|
|
|
|
|
maximumAmount: root.remainingTokens
|
|
|
|
|
multiplierIndex: root.multiplierIndex
|
|
|
|
|
|
|
|
|
|
validateMaximumAmount: true
|
|
|
|
|
allowZero: false
|
|
|
|
|
|
|
|
|
|
placeholderText: qsTr("Enter amount")
|
|
|
|
|
labelText: ""
|
|
|
|
|
|
|
|
|
|
maximumExceededErrorText: qsTr("Exceeds available remaining")
|
2023-05-18 16:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatusRadioButton {
|
|
|
|
|
id: allTokensButton
|
|
|
|
|
|
2023-08-30 08:25:32 +00:00
|
|
|
|
anchors.left: specificAmountColumn.right
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
anchors.leftMargin: parent.spacing
|
2023-05-18 16:08:30 +00:00
|
|
|
|
|
2023-08-10 12:23:59 +00:00
|
|
|
|
text: qsTr("All available remaining (%1)").arg(d.remainingTokensDisplayText)
|
2023-05-18 16:08:30 +00:00
|
|
|
|
font.pixelSize: Style.current.primaryTextFontSize
|
|
|
|
|
ButtonGroup.group: radioGroup
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ButtonGroup { id: radioGroup }
|
|
|
|
|
}
|
2023-08-07 13:31:07 +00:00
|
|
|
|
|
|
|
|
|
StatusDialogDivider {
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FeesBox {
|
|
|
|
|
id: feesBox
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
|
|
placeholderText: qsTr("Choose number of tokens to burn to see gas fees")
|
|
|
|
|
accountErrorText: root.feeErrorText
|
|
|
|
|
implicitWidth: 0
|
|
|
|
|
model: d.isFormValid ? singleFeeModel : undefined
|
2023-08-09 12:31:58 +00:00
|
|
|
|
accountsSelector.model: root.accounts
|
2023-08-07 13:31:07 +00:00
|
|
|
|
|
|
|
|
|
accountsSelector.onCurrentIndexChanged: {
|
|
|
|
|
if (accountsSelector.currentIndex < 0)
|
|
|
|
|
return
|
|
|
|
|
|
2023-08-30 08:25:32 +00:00
|
|
|
|
const item = SQUtils.ModelUtils.get(
|
|
|
|
|
accountsSelector.model,
|
|
|
|
|
accountsSelector.currentIndex)
|
|
|
|
|
|
2023-08-07 13:31:07 +00:00
|
|
|
|
d.accountAddress = item.address
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
|
id: singleFeeModel
|
|
|
|
|
|
|
|
|
|
readonly property string title: root.feeLabel
|
2023-08-30 08:25:32 +00:00
|
|
|
|
readonly property string feeText: root.isFeeLoading
|
|
|
|
|
? "" : root.feeText
|
2023-08-07 13:31:07 +00:00
|
|
|
|
readonly property bool error: d.isFeeError
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-18 16:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
header: StatusDialogHeader {
|
2023-08-07 13:31:07 +00:00
|
|
|
|
headline.title: qsTr("Burn %1 tokens").arg(root.tokenName)
|
2023-08-30 08:25:32 +00:00
|
|
|
|
headline.subtitle: qsTr("%1 %2 remaining in smart contract")
|
|
|
|
|
.arg(d.remainingTokensDisplayText).arg(root.tokenName)
|
|
|
|
|
|
2023-05-18 16:08:30 +00:00
|
|
|
|
leftComponent: Rectangle {
|
|
|
|
|
height: 40
|
|
|
|
|
width: height
|
|
|
|
|
radius: root.isAsset ? height/2 : 8
|
|
|
|
|
color:Theme.palette.baseColor2
|
|
|
|
|
|
|
|
|
|
Image {
|
|
|
|
|
id: image
|
|
|
|
|
|
|
|
|
|
source: root.tokenSource
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
|
visible: false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpacityMask {
|
|
|
|
|
anchors.fill: image
|
|
|
|
|
source: image
|
|
|
|
|
maskSource: parent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
actions.closeButton.onClicked: root.close()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
footer: StatusDialogFooter {
|
|
|
|
|
spacing: Style.current.padding
|
|
|
|
|
rightButtons: ObjectModel {
|
|
|
|
|
StatusButton {
|
|
|
|
|
text: qsTr("Cancel")
|
|
|
|
|
normalColor: "transparent"
|
|
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
|
root.cancelClicked()
|
|
|
|
|
close()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatusButton {
|
2023-08-07 13:31:07 +00:00
|
|
|
|
enabled: d.isFormValid && !d.isFeeError && !root.isFeeLoading
|
2023-08-30 08:25:32 +00:00
|
|
|
|
&& root.feeText !== ""
|
2023-05-18 16:08:30 +00:00
|
|
|
|
text: qsTr("Burn tokens")
|
|
|
|
|
type: StatusBaseButton.Type.Danger
|
2023-08-30 08:25:32 +00:00
|
|
|
|
|
2023-05-18 16:08:30 +00:00
|
|
|
|
onClicked: {
|
2023-08-30 08:25:32 +00:00
|
|
|
|
if (specificAmountButton.checked)
|
|
|
|
|
root.burnClicked(amountInput.amount, d.accountAddress)
|
|
|
|
|
else
|
2023-08-07 13:31:07 +00:00
|
|
|
|
root.burnClicked(root.remainingTokens, d.accountAddress)
|
2023-05-18 16:08:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onOpened: d.initialize()
|
|
|
|
|
}
|