2023-03-13 16:32:14 +00:00
|
|
|
import QtQuick 2.14
|
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
import QtQuick.Layouts 1.14
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
import shared.panels 1.0
|
|
|
|
|
|
|
|
import AppLayouts.Chat.helpers 1.0
|
|
|
|
import AppLayouts.Chat.panels.communities 1.0
|
|
|
|
import AppLayouts.Chat.controls.community 1.0
|
|
|
|
|
|
|
|
// TEMPORAL - BASIC IMPLEMENTATION
|
|
|
|
StatusScrollView {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
// Token models:
|
|
|
|
required property var assetsModel
|
|
|
|
required property var collectiblesModel
|
|
|
|
|
|
|
|
property int viewWidth: 560 // by design
|
|
|
|
|
|
|
|
// roles: type, key, name, amount, imageSource
|
|
|
|
property var selectedHoldingsModel: ListModel {}
|
|
|
|
|
|
|
|
readonly property bool isFullyFilled: selectedHoldingsModel.count > 0 &&
|
2023-03-13 10:02:41 +00:00
|
|
|
addressess.model.count > 0
|
2023-03-13 16:32:14 +00:00
|
|
|
|
|
|
|
signal airdropClicked(var airdropTokens, string address)
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
readonly property int maxAirdropTokens: 5
|
|
|
|
readonly property int dropdownHorizontalOffset: 4
|
|
|
|
readonly property int dropdownVerticalOffset: 1
|
|
|
|
}
|
|
|
|
|
|
|
|
contentWidth: mainLayout.width
|
|
|
|
contentHeight: mainLayout.height
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
id: mainLayout
|
|
|
|
width: root.viewWidth
|
|
|
|
spacing: 0
|
|
|
|
|
|
|
|
StatusItemSelector {
|
|
|
|
id: tokensSelector
|
|
|
|
|
|
|
|
property int editedIndex: -1
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
icon: Style.svg("token")
|
|
|
|
title: qsTr("What")
|
2023-03-13 10:02:41 +00:00
|
|
|
placeholderText: qsTr("Example: 1 SOCK")
|
2023-03-13 16:32:14 +00:00
|
|
|
tagLeftPadding: 2
|
|
|
|
asset.height: 28
|
|
|
|
asset.width: asset.height
|
2023-03-13 10:02:41 +00:00
|
|
|
addButton.visible: model.count < d.maxAirdropTokens
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2023-03-13 10:02:41 +00:00
|
|
|
model: HoldingsSelectionModel {
|
2023-03-13 16:32:14 +00:00
|
|
|
sourceModel: root.selectedHoldingsModel
|
|
|
|
|
|
|
|
assetsModel: root.assetsModel
|
|
|
|
collectiblesModel: root.collectiblesModel
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: All this code is repeated inside `CommunityNewPermissionView`. Check how to reuse it.
|
|
|
|
HoldingsDropdown {
|
|
|
|
id: dropdown
|
|
|
|
|
|
|
|
assetsModel: root.assetsModel
|
|
|
|
collectiblesModel: root.collectiblesModel
|
|
|
|
isENSTab: false
|
2023-03-23 16:21:15 +00:00
|
|
|
isCollectiblesOnly: true
|
2023-03-13 16:32:14 +00:00
|
|
|
|
|
|
|
function addItem(type, item, amount) {
|
|
|
|
const key = item.key
|
|
|
|
|
|
|
|
root.selectedHoldingsModel.append(
|
|
|
|
{ type, key, amount })
|
|
|
|
}
|
|
|
|
|
|
|
|
function getHoldingIndex(key) {
|
|
|
|
return ModelUtils.indexOf(root.selectedHoldingsModel, "key", key)
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareUpdateIndex(key) {
|
|
|
|
const itemIndex = tokensSelector.editedIndex
|
|
|
|
const existingIndex = getHoldingIndex(key)
|
|
|
|
|
|
|
|
if (itemIndex !== -1 && existingIndex !== -1 && itemIndex !== existingIndex) {
|
|
|
|
const previousKey = root.selectedHoldingsModel.get(itemIndex).key
|
|
|
|
root.selectedHoldingsModel.remove(existingIndex)
|
|
|
|
return getHoldingIndex(previousKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemIndex === -1) {
|
|
|
|
return existingIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
onAddAsset: {
|
|
|
|
const modelItem = CommunityPermissionsHelpers.getTokenByKey(
|
|
|
|
root.assetsModel, key)
|
|
|
|
addItem(HoldingTypes.Type.Asset, modelItem, amount)
|
|
|
|
dropdown.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
onAddCollectible: {
|
|
|
|
const modelItem = CommunityPermissionsHelpers.getTokenByKey(
|
|
|
|
root.collectiblesModel, key)
|
|
|
|
addItem(HoldingTypes.Type.Collectible, modelItem, amount)
|
|
|
|
dropdown.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
onUpdateAsset: {
|
|
|
|
const itemIndex = prepareUpdateIndex(key)
|
|
|
|
const modelItem = CommunityPermissionsHelpers.getTokenByKey(root.assetsModel, key)
|
|
|
|
|
|
|
|
root.selectedHoldingsModel.set(
|
|
|
|
itemIndex, { type: HoldingTypes.Type.Asset, key, amount })
|
|
|
|
dropdown.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
onUpdateCollectible: {
|
|
|
|
const itemIndex = prepareUpdateIndex(key)
|
|
|
|
const modelItem = CommunityPermissionsHelpers.getTokenByKey(
|
|
|
|
root.collectiblesModel, key)
|
|
|
|
|
|
|
|
root.selectedHoldingsModel.set(
|
|
|
|
itemIndex,
|
|
|
|
{ type: HoldingTypes.Type.Collectible, key, amount })
|
|
|
|
dropdown.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
onRemoveClicked: {
|
|
|
|
root.selectedHoldingsModel.remove(tokensSelector.editedIndex)
|
|
|
|
dropdown.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addButton.onClicked: {
|
|
|
|
dropdown.parent = tokensSelector.addButton
|
|
|
|
dropdown.x = tokensSelector.addButton.width + d.dropdownHorizontalOffset
|
|
|
|
dropdown.y = 0
|
|
|
|
dropdown.open()
|
|
|
|
|
|
|
|
editedIndex = -1
|
|
|
|
}
|
|
|
|
|
|
|
|
onItemClicked: {
|
|
|
|
if (mouse.button !== Qt.LeftButton)
|
|
|
|
return
|
|
|
|
|
|
|
|
dropdown.parent = item
|
|
|
|
dropdown.x = mouse.x + d.dropdownHorizontalOffset
|
|
|
|
dropdown.y = d.dropdownVerticalOffset
|
|
|
|
|
2023-03-13 10:02:41 +00:00
|
|
|
const modelItem = tokensSelector.model.get(index)
|
2023-03-13 16:32:14 +00:00
|
|
|
|
|
|
|
switch(modelItem.type) {
|
|
|
|
case HoldingTypes.Type.Asset:
|
|
|
|
dropdown.assetKey = modelItem.key
|
|
|
|
dropdown.assetAmount = modelItem.amount
|
|
|
|
break
|
|
|
|
case HoldingTypes.Type.Collectible:
|
|
|
|
dropdown.collectibleKey = modelItem.key
|
|
|
|
dropdown.collectibleAmount = modelItem.amount
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
console.warn("Unsupported holdings type.")
|
|
|
|
}
|
|
|
|
|
|
|
|
dropdown.setActiveTab(modelItem.type)
|
|
|
|
dropdown.openUpdateFlow()
|
|
|
|
|
|
|
|
editedIndex = index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
Layout.leftMargin: 16
|
|
|
|
Layout.preferredWidth: 2
|
|
|
|
Layout.preferredHeight: 24
|
|
|
|
color: Style.current.separator
|
|
|
|
}
|
|
|
|
|
|
|
|
// TEMPORAL
|
|
|
|
StatusInput {
|
|
|
|
id: addressInput
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
placeholderText: qsTr("Example: 0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7999")
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
Layout.leftMargin: 16
|
|
|
|
Layout.preferredWidth: 2
|
|
|
|
Layout.preferredHeight: 24
|
|
|
|
color: Style.current.separator
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusItemSelector {
|
|
|
|
id: addressess
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
icon: Style.svg("member")
|
|
|
|
title: qsTr("To")
|
2023-03-13 10:02:41 +00:00
|
|
|
placeholderText: qsTr("Example: 12 addresses and 3 members")
|
2023-03-13 16:32:14 +00:00
|
|
|
tagLeftPadding: 2
|
|
|
|
asset.height: 28
|
|
|
|
asset.width: asset.height
|
|
|
|
|
2023-03-13 10:02:41 +00:00
|
|
|
model: ListModel {}
|
|
|
|
|
2023-03-13 16:32:14 +00:00
|
|
|
addButton.onClicked: {
|
|
|
|
if(addressInput.text.length > 0)
|
2023-03-13 10:02:41 +00:00
|
|
|
model.append({text: addressInput.text})
|
2023-03-13 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
2023-03-13 10:02:41 +00:00
|
|
|
onItemClicked: addressess.model.remove(index)
|
2023-03-13 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StatusButton {
|
|
|
|
Layout.preferredHeight: 44
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: Style.current.bigPadding
|
|
|
|
text: qsTr("Create airdrop")
|
|
|
|
enabled: root.isFullyFilled
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
const airdropTokens = ModelUtils.modelToArray(
|
|
|
|
root.selectedHoldingsModel,
|
|
|
|
["key", "type", "amount"])
|
|
|
|
|
2023-03-13 10:02:41 +00:00
|
|
|
root.airdropClicked(airdropTokens, addressess.model)
|
2023-03-13 16:32:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|