2023-08-17 13:58:04 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
import QtQml.Models 2.15
|
2023-03-31 11:26:50 +00:00
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Popups.Dialog 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
2023-04-13 08:09:06 +00:00
|
|
|
import StatusQ.Core.Utils 0.1
|
2023-03-31 11:26:50 +00:00
|
|
|
|
2023-06-23 06:17:04 +00:00
|
|
|
import AppLayouts.Communities.panels 1.0
|
2023-03-31 11:26:50 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
StatusDialog {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property alias model: tokenHoldersPanel.model
|
|
|
|
property string collectibleName
|
2023-08-10 09:39:52 +00:00
|
|
|
property string chainName
|
2024-07-22 13:52:44 +00:00
|
|
|
property string networkThatIsNotActive
|
2023-08-10 09:39:52 +00:00
|
|
|
|
|
|
|
// Fees related properties:
|
|
|
|
property bool isFeeLoading
|
|
|
|
property string feeText: ""
|
|
|
|
property string feeErrorText: ""
|
|
|
|
property string feeLabel: qsTr("Remotely destruct %1 token on %2").arg(root.collectibleName).arg(root.chainName)
|
2023-03-31 11:26:50 +00:00
|
|
|
|
2023-08-17 13:58:04 +00:00
|
|
|
readonly property alias tokenCount: d.tokenCount
|
2023-09-01 09:27:44 +00:00
|
|
|
readonly property string selectedAccount: d.accountAddress
|
|
|
|
readonly property var selectedWalletsAndAmounts: {
|
|
|
|
//depedency
|
|
|
|
d.tokenCount
|
|
|
|
return ModelUtils.modelToArray(d.walletsAndAmountsList)
|
|
|
|
}
|
2023-08-17 13:58:04 +00:00
|
|
|
|
2023-08-10 09:39:52 +00:00
|
|
|
// Account expected roles: address, name, color, emoji, walletType
|
|
|
|
property var accounts
|
2023-09-01 09:27:44 +00:00
|
|
|
|
2023-08-17 13:58:04 +00:00
|
|
|
signal remotelyDestructClicked(var walletsAndAmounts, string accountAddress)
|
2024-07-22 13:52:44 +00:00
|
|
|
signal enableNetwork
|
2023-08-10 09:39:52 +00:00
|
|
|
|
2023-03-31 11:26:50 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
2023-08-10 09:39:52 +00:00
|
|
|
property string accountAddress
|
2023-03-31 11:26:50 +00:00
|
|
|
readonly property int maxHeight: 560 // by design
|
|
|
|
property int tokenCount: 0
|
2023-08-17 13:58:04 +00:00
|
|
|
readonly property ListModel walletsAndAmountsList: ListModel {}
|
2023-08-10 09:39:52 +00:00
|
|
|
readonly property bool isFeeError: root.feeErrorText !== ""
|
2023-03-31 11:26:50 +00:00
|
|
|
|
|
|
|
function getVerticalPadding() {
|
|
|
|
return root.topPadding + root.bottomPadding
|
|
|
|
}
|
|
|
|
|
|
|
|
function getHorizontalPadding() {
|
|
|
|
return root.leftPadding + root.rightPadding
|
|
|
|
}
|
|
|
|
|
2023-04-27 10:12:09 +00:00
|
|
|
function updateTokensToDestruct(walletAddress, amount) {
|
2023-08-17 13:58:04 +00:00
|
|
|
const index = ModelUtils.indexOf(d.walletsAndAmountsList,
|
|
|
|
"walletAddress", walletAddress)
|
|
|
|
|
|
|
|
if (index !== -1)
|
|
|
|
d.walletsAndAmountsList.setProperty(index, "amount", amount)
|
|
|
|
else
|
|
|
|
d.walletsAndAmountsList.append({ walletAddress, amount })
|
2023-04-27 10:12:09 +00:00
|
|
|
|
|
|
|
updateTokensCount()
|
2023-03-31 11:26:50 +00:00
|
|
|
}
|
2023-04-27 10:12:09 +00:00
|
|
|
|
2023-08-17 13:58:04 +00:00
|
|
|
function clearTokensToDestruct(walletAddress) {
|
|
|
|
const index = ModelUtils.indexOf(d.walletsAndAmountsList,
|
|
|
|
"walletAddress", walletAddress)
|
|
|
|
d.walletsAndAmountsList.remove(index)
|
2023-04-27 10:12:09 +00:00
|
|
|
updateTokensCount()
|
|
|
|
}
|
|
|
|
|
2023-08-17 13:58:04 +00:00
|
|
|
function updateTokensCount() {
|
|
|
|
const amounts = ModelUtils.modelToFlatArray(
|
|
|
|
d.walletsAndAmountsList, "amount")
|
|
|
|
const sum = amounts.reduce((a, b) => a + b, 0)
|
|
|
|
d.tokenCount = sum
|
|
|
|
}
|
2023-03-31 11:26:50 +00:00
|
|
|
}
|
|
|
|
|
2023-05-15 14:52:50 +00:00
|
|
|
title: qsTr("Remotely destruct %1 token").arg(root.collectibleName)
|
2023-03-31 11:26:50 +00:00
|
|
|
implicitWidth: 600 // by design
|
2023-05-31 20:58:23 +00:00
|
|
|
padding: 0
|
2023-03-31 11:26:50 +00:00
|
|
|
|
2023-08-10 09:39:52 +00:00
|
|
|
contentItem: ColumnLayout {
|
2024-10-15 19:26:12 +00:00
|
|
|
spacing: Theme.padding
|
2023-08-10 09:39:52 +00:00
|
|
|
TokenHoldersPanel {
|
|
|
|
id: tokenHoldersPanel
|
|
|
|
tokenName: root.collectibleName
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
isSelectorMode: true
|
|
|
|
onSelfDestructAmountChanged: d.updateTokensToDestruct(walletAddress, amount)
|
2023-08-17 13:58:04 +00:00
|
|
|
onSelfDestructRemoved: d.clearTokensToDestruct(walletAddress)
|
2023-08-10 09:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FeesBox {
|
|
|
|
id: feesBox
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
2024-07-22 13:52:44 +00:00
|
|
|
Layout.bottomMargin: networkWarningPanel.visible ? 0 : 16
|
2023-08-10 09:39:52 +00:00
|
|
|
Layout.leftMargin: 16
|
|
|
|
Layout.rightMargin: 16
|
|
|
|
|
|
|
|
implicitWidth: 0
|
|
|
|
accountErrorText: root.feeErrorText
|
|
|
|
placeholderText: qsTr("Select a hodler to see remote destruction gas fees")
|
|
|
|
showAccountsSelector: true
|
2023-08-17 13:58:04 +00:00
|
|
|
model: d.tokenCount > 0 ? singleFeeModel : undefined
|
2023-08-10 09:39:52 +00:00
|
|
|
accountsSelector.model: root.accounts
|
|
|
|
|
2024-06-07 12:27:56 +00:00
|
|
|
Binding {
|
|
|
|
target: d
|
|
|
|
property: "accountAddress"
|
|
|
|
value: feesBox.accountsSelector.currentAccountAddress
|
2023-08-10 09:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: singleFeeModel
|
|
|
|
|
|
|
|
readonly property string title: root.feeLabel
|
|
|
|
readonly property string feeText: root.isFeeLoading ?
|
|
|
|
"" : root.feeText
|
|
|
|
readonly property bool error: d.isFeeError
|
|
|
|
}
|
|
|
|
}
|
2024-07-22 13:52:44 +00:00
|
|
|
|
|
|
|
NetworkWarningPanel {
|
|
|
|
id: networkWarningPanel
|
|
|
|
|
|
|
|
visible: !!root.networkThatIsNotActive
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.bottomMargin: 16
|
|
|
|
Layout.leftMargin: 18
|
|
|
|
Layout.rightMargin: 18
|
|
|
|
|
|
|
|
networkThatIsNotActive: root.chainName
|
|
|
|
onEnableNetwork: root.enableNetwork()
|
|
|
|
}
|
2023-03-31 11:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
footer: StatusDialogFooter {
|
2024-10-15 19:26:12 +00:00
|
|
|
spacing: Theme.padding
|
2023-03-31 11:26:50 +00:00
|
|
|
rightButtons: ObjectModel {
|
2023-07-05 15:17:51 +00:00
|
|
|
StatusFlatButton {
|
|
|
|
text: qsTr("Cancel")
|
|
|
|
onClicked: {
|
|
|
|
root.close()
|
|
|
|
}
|
|
|
|
}
|
2023-03-31 11:26:50 +00:00
|
|
|
StatusButton {
|
|
|
|
enabled: d.tokenCount > 0
|
2023-05-15 14:52:50 +00:00
|
|
|
text: qsTr("Remotely destruct %n token(s)", "", d.tokenCount)
|
2023-03-31 11:26:50 +00:00
|
|
|
type: StatusBaseButton.Type.Danger
|
2023-08-17 13:58:04 +00:00
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
const walletsAndAmounts = ModelUtils.modelToArray(
|
|
|
|
d.walletsAndAmountsList)
|
|
|
|
|
|
|
|
root.remotelyDestructClicked(walletsAndAmounts,
|
|
|
|
d.accountAddress)
|
|
|
|
}
|
2023-03-31 11:26:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|