2023-04-25 21:24:04 +00:00
|
|
|
import QtQuick 2.15
|
2023-06-14 15:25:48 +00:00
|
|
|
import QtQuick.Controls 2.15
|
2023-04-25 21:24:04 +00:00
|
|
|
import QtQuick.Layouts 1.15
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2024-10-10 17:01:47 +00:00
|
|
|
import StatusQ 0.1
|
2023-06-14 15:25:48 +00:00
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
2023-03-13 16:32:14 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
import shared.panels 1.0
|
|
|
|
|
2023-06-23 06:17:04 +00:00
|
|
|
import AppLayouts.Communities.controls 1.0
|
|
|
|
import AppLayouts.Communities.helpers 1.0
|
|
|
|
import AppLayouts.Communities.panels 1.0
|
|
|
|
import AppLayouts.Communities.popups 1.0
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
|
|
|
|
2023-03-13 16:32:14 +00:00
|
|
|
StatusScrollView {
|
|
|
|
id: root
|
|
|
|
|
2023-06-21 14:20:39 +00:00
|
|
|
// id, name, image, color, owner properties expected
|
|
|
|
required property var communityDetails
|
|
|
|
|
2023-03-13 16:32:14 +00:00
|
|
|
// Token models:
|
|
|
|
required property var assetsModel
|
|
|
|
required property var collectiblesModel
|
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
// Community members model:
|
|
|
|
required property var membersModel
|
|
|
|
|
2023-07-25 14:14:42 +00:00
|
|
|
// A model containing accounts from which the fee can be paid:
|
|
|
|
required property var accountsModel
|
2023-09-01 04:28:50 +00:00
|
|
|
|
|
|
|
// Text to display as total fee
|
|
|
|
required property string totalFeeText
|
|
|
|
// Text to display in case of error
|
|
|
|
required property string feeErrorText
|
|
|
|
// Array containing the fees for each token
|
|
|
|
// [{contractUniqueKey: string, feeText: string}]
|
|
|
|
required property var feesPerSelectedContract
|
|
|
|
// Bool property indicating whether the fees are available
|
|
|
|
required property bool feesAvailable
|
2023-06-06 15:32:53 +00:00
|
|
|
|
2024-07-22 13:52:44 +00:00
|
|
|
property string enabledChainIds
|
|
|
|
|
2023-03-13 16:32:14 +00:00
|
|
|
property int viewWidth: 560 // by design
|
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
readonly property var selectedHoldingsModel: ListModel {}
|
2023-09-01 04:28:50 +00:00
|
|
|
// Array containing the contract keys and amounts of the tokens to be airdropped
|
|
|
|
readonly property alias selectedContractKeysAndAmounts: d.selectedContractKeysAndAmounts
|
|
|
|
// Array containing the addresses to which the tokens will be airdropped
|
|
|
|
readonly property alias selectedAddressesToAirdrop: d.selectedAddressesToAirdrop
|
|
|
|
// The address of the account from which the fee will be paid
|
|
|
|
readonly property alias selectedFeeAccount: d.selectedFeeAccount
|
|
|
|
// Bool property indicating whether the fees are shown
|
|
|
|
readonly property bool showingFees: d.showFees
|
|
|
|
|
|
|
|
onFeesPerSelectedContractChanged: {
|
|
|
|
feesModel.clear()
|
2023-09-01 09:27:44 +00:00
|
|
|
|
|
|
|
let feeSource = feesPerSelectedContract
|
|
|
|
if(!feeSource || feeSource.length === 0) // if no fees are available, show the placeholder text based on selection
|
|
|
|
feeSource = ModelUtils.modelToArray(root.selectedHoldingsModel, ["contractUniqueKey"])
|
|
|
|
|
|
|
|
feeSource.forEach(entry => {
|
2023-09-01 04:28:50 +00:00
|
|
|
feesModel.append({
|
|
|
|
contractUniqueKey: entry.contractUniqueKey,
|
|
|
|
title: qsTr("Airdrop %1 on %2")
|
|
|
|
.arg(ModelUtils.getByKey(root.selectedHoldingsModel, "contractUniqueKey", entry.contractUniqueKey, "symbol"))
|
|
|
|
.arg(ModelUtils.getByKey(root.selectedHoldingsModel, "contractUniqueKey", entry.contractUniqueKey, "networkText")),
|
2023-09-01 09:27:44 +00:00
|
|
|
feeText: entry.feeText ?? ""
|
2023-09-01 04:28:50 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2023-06-14 15:25:48 +00:00
|
|
|
ModelChangeTracker {
|
|
|
|
id: holdingsModelTracker
|
|
|
|
|
|
|
|
model: selectedHoldingsModel
|
|
|
|
}
|
|
|
|
|
|
|
|
ModelChangeTracker {
|
|
|
|
id: addressesModelTracker
|
|
|
|
|
|
|
|
model: addresses
|
|
|
|
}
|
|
|
|
|
|
|
|
ModelChangeTracker {
|
|
|
|
id: membersModelTracker
|
|
|
|
|
|
|
|
model: selectedMembersModel
|
|
|
|
}
|
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
readonly property bool isFullyFilled: tokensSelector.count > 0 &&
|
|
|
|
airdropRecipientsSelector.count > 0 &&
|
|
|
|
airdropRecipientsSelector.valid
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2023-07-20 19:58:51 +00:00
|
|
|
signal airdropClicked(var airdropTokens, var addresses, string feeAccountAddress)
|
2023-06-06 15:32:53 +00:00
|
|
|
|
2023-06-14 07:19:45 +00:00
|
|
|
signal navigateToMintTokenSettings(bool isAssetType)
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2024-07-22 13:52:44 +00:00
|
|
|
signal enableNetwork(int chainId)
|
|
|
|
|
2023-06-01 10:38:56 +00:00
|
|
|
function selectToken(key, amount, type) {
|
2023-06-21 16:40:26 +00:00
|
|
|
if(selectedHoldingsModel)
|
|
|
|
selectedHoldingsModel.clear()
|
2023-08-10 12:23:59 +00:00
|
|
|
|
2023-06-01 10:38:56 +00:00
|
|
|
const entry = d.prepareEntry(key, amount, type)
|
2023-04-25 21:24:04 +00:00
|
|
|
entry.valid = true
|
|
|
|
selectedHoldingsModel.append(entry)
|
2023-04-17 12:11:31 +00:00
|
|
|
}
|
|
|
|
|
2023-06-05 13:49:36 +00:00
|
|
|
function addAddresses(_addresses) {
|
|
|
|
addresses.addAddresses(_addresses)
|
|
|
|
}
|
|
|
|
|
2023-03-13 16:32:14 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
readonly property int maxAirdropTokens: 5
|
|
|
|
readonly property int dropdownHorizontalOffset: 4
|
|
|
|
readonly property int dropdownVerticalOffset: 1
|
2023-04-17 12:11:31 +00:00
|
|
|
|
2023-06-14 15:25:48 +00:00
|
|
|
readonly property bool showFees: root.selectedHoldingsModel.count > 0
|
|
|
|
&& airdropRecipientsSelector.valid
|
|
|
|
&& airdropRecipientsSelector.count > 0
|
|
|
|
|
2024-07-22 13:52:44 +00:00
|
|
|
property string networkThatIsNotActive
|
|
|
|
property int networkIdThatIsNotActive
|
|
|
|
|
2023-09-01 04:28:50 +00:00
|
|
|
readonly property var selectedContractKeysAndAmounts: {
|
|
|
|
//Depedencies:
|
|
|
|
root.selectedHoldingsModel
|
|
|
|
holdingsModelTracker.revision
|
2023-06-14 15:25:48 +00:00
|
|
|
|
2023-09-01 04:28:50 +00:00
|
|
|
return ModelUtils.modelToArray(
|
|
|
|
root.selectedHoldingsModel,
|
|
|
|
["contractUniqueKey", "amount"])
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly property var selectedAddressesToAirdrop: {
|
|
|
|
//Dependecies:
|
|
|
|
addresses
|
|
|
|
addressesModelTracker.revision
|
|
|
|
|
|
|
|
return ModelUtils.modelToArray(
|
|
|
|
addresses, ["address"]).map(e => e.address)
|
|
|
|
.concat([...selectedKeysFilter.keys])
|
|
|
|
}
|
|
|
|
|
2024-06-07 12:27:56 +00:00
|
|
|
readonly property string selectedFeeAccount: feesBox.accountsSelector.currentAccountAddress
|
2023-06-14 15:25:48 +00:00
|
|
|
|
2023-06-01 10:38:56 +00:00
|
|
|
function prepareEntry(key, amount, type) {
|
2023-08-10 12:23:59 +00:00
|
|
|
const tokenModel = type === Constants.TokenType.ERC20
|
|
|
|
? root.assetsModel : root.collectiblesModel
|
2023-06-26 11:48:45 +00:00
|
|
|
const modelItem = PermissionsHelpers.getTokenByKey(
|
2023-06-14 15:25:48 +00:00
|
|
|
tokenModel, key)
|
2023-08-10 12:23:59 +00:00
|
|
|
const multiplierIndex = modelItem.multiplierIndex
|
|
|
|
const amountNumber = AmountsArithmetic.toNumber(
|
|
|
|
amount, multiplierIndex)
|
|
|
|
const amountLocalized = LocaleUtils.numberToLocaleString(
|
|
|
|
amountNumber, -1)
|
2023-04-25 21:24:04 +00:00
|
|
|
return {
|
2023-06-14 07:19:45 +00:00
|
|
|
key, amount, type,
|
2023-08-10 12:23:59 +00:00
|
|
|
tokenText: amountLocalized + " " + modelItem.name,
|
2023-04-25 21:24:04 +00:00
|
|
|
tokenImage: modelItem.iconSource,
|
2024-07-22 13:52:44 +00:00
|
|
|
networkId: modelItem.chainId,
|
2023-04-25 21:24:04 +00:00
|
|
|
networkText: modelItem.chainName,
|
|
|
|
networkImage: Style.svg(modelItem.chainIcon),
|
2023-08-18 10:00:46 +00:00
|
|
|
remainingSupply: modelItem.remainingSupply,
|
2023-08-10 12:23:59 +00:00
|
|
|
multiplierIndex: modelItem.multiplierIndex,
|
2023-05-25 10:00:38 +00:00
|
|
|
infiniteSupply: modelItem.infiniteSupply,
|
|
|
|
contractUniqueKey: modelItem.contractUniqueKey,
|
2023-06-14 15:25:48 +00:00
|
|
|
accountName: modelItem.accountName,
|
|
|
|
symbol: modelItem.symbol
|
2023-04-25 21:24:04 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-14 15:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ListModel {
|
|
|
|
id: feesModel
|
2023-04-25 21:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Instantiator {
|
|
|
|
id: recipientsCountInstantiator
|
|
|
|
|
|
|
|
model: selectedHoldingsModel
|
|
|
|
|
|
|
|
property bool infinity: true
|
|
|
|
property int maximumRecipientsCount
|
2023-04-17 12:11:31 +00:00
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
function findRecipientsCount() {
|
|
|
|
let min = Number.MAX_SAFE_INTEGER
|
|
|
|
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
|
|
const item = objectAt(i)
|
|
|
|
|
|
|
|
if (!item || item.infiniteSupply)
|
|
|
|
continue
|
|
|
|
|
2023-08-18 10:00:46 +00:00
|
|
|
const dividient = AmountsArithmetic.fromString(item.remainingSupply)
|
2023-08-10 12:23:59 +00:00
|
|
|
const divisor = AmountsArithmetic.fromString(item.amount)
|
|
|
|
|
|
|
|
const quotient = AmountsArithmetic.toNumber(
|
|
|
|
AmountsArithmetic.div(dividient, divisor))
|
|
|
|
|
|
|
|
min = Math.min(quotient, min)
|
2023-04-25 21:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
infinity = min === Number.MAX_SAFE_INTEGER
|
|
|
|
maximumRecipientsCount = infinity ? 0 : min
|
2023-04-17 12:11:31 +00:00
|
|
|
}
|
2023-04-25 21:24:04 +00:00
|
|
|
|
|
|
|
delegate: QtObject {
|
2023-08-18 10:00:46 +00:00
|
|
|
readonly property string remainingSupply: model.remainingSupply
|
2023-08-10 12:23:59 +00:00
|
|
|
readonly property string amount: model.amount
|
2023-04-25 21:24:04 +00:00
|
|
|
readonly property bool infiniteSupply: model.infiniteSupply
|
|
|
|
|
2023-08-10 12:23:59 +00:00
|
|
|
readonly property bool valid: {
|
|
|
|
if (infiniteSupply)
|
|
|
|
return true
|
|
|
|
|
|
|
|
const recipientsCount = airdropRecipientsSelector.count
|
|
|
|
const demand = AmountsArithmetic.times(
|
|
|
|
AmountsArithmetic.fromString(amount),
|
|
|
|
recipientsCount)
|
|
|
|
|
2023-08-18 10:00:46 +00:00
|
|
|
const available = AmountsArithmetic.fromString(remainingSupply)
|
2023-08-10 12:23:59 +00:00
|
|
|
|
|
|
|
return AmountsArithmetic.cmp(demand, available) <= 0
|
|
|
|
}
|
|
|
|
|
2023-04-27 22:13:59 +00:00
|
|
|
|
2023-08-18 10:00:46 +00:00
|
|
|
onRemainingSupplyChanged: recipientsCountInstantiator.findRecipientsCount()
|
2023-04-25 21:24:04 +00:00
|
|
|
onAmountChanged: recipientsCountInstantiator.findRecipientsCount()
|
|
|
|
onInfiniteSupplyChanged: recipientsCountInstantiator.findRecipientsCount()
|
2023-04-27 22:13:59 +00:00
|
|
|
|
|
|
|
onValidChanged: model.valid = valid
|
|
|
|
Component.onCompleted: model.valid = valid
|
2023-04-25 21:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onCountChanged: findRecipientsCount()
|
2023-03-13 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
SequenceColumnLayout {
|
2023-03-13 16:32:14 +00:00
|
|
|
id: mainLayout
|
|
|
|
width: root.viewWidth
|
|
|
|
spacing: 0
|
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
AirdropTokensSelector {
|
2023-03-13 16:32:14 +00:00
|
|
|
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")
|
|
|
|
addButton.visible: model.count < d.maxAirdropTokens
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
model: root.selectedHoldingsModel
|
2023-03-13 16:32:14 +00:00
|
|
|
|
|
|
|
HoldingsDropdown {
|
|
|
|
id: dropdown
|
|
|
|
|
2023-06-21 14:20:39 +00:00
|
|
|
communityId: communityDetails.id
|
2023-03-13 16:32:14 +00:00
|
|
|
assetsModel: root.assetsModel
|
|
|
|
collectiblesModel: root.collectiblesModel
|
|
|
|
isENSTab: false
|
2023-06-14 07:19:45 +00:00
|
|
|
noDataTextForAssets: qsTr("First you need to mint or import an asset before you can perform an airdrop")
|
|
|
|
noDataTextForCollectibles: qsTr("First you need to mint or import a collectible before you can perform an airdrop")
|
2023-03-13 16:32:14 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
onOpened: {
|
|
|
|
usedTokens = ModelUtils.modelToArray(
|
|
|
|
root.selectedHoldingsModel, ["key", "amount"])
|
2023-03-13 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
2024-07-22 13:52:44 +00:00
|
|
|
function isChainEnabled(entry) {
|
|
|
|
// If the tokens' network is not activated, show a warning to the user
|
|
|
|
if (!!entry && !root.enabledChainIds.includes(entry.networkId)) {
|
|
|
|
d.networkThatIsNotActive = entry.networkText
|
|
|
|
d.networkIdThatIsNotActive = entry.networkId
|
|
|
|
} else {
|
|
|
|
d.networkThatIsNotActive = ""
|
|
|
|
d.networkIdThatIsNotActive = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-14 07:19:45 +00:00
|
|
|
onAddAsset: {
|
|
|
|
const entry = d.prepareEntry(key, amount, Constants.TokenType.ERC20)
|
|
|
|
entry.valid = true
|
|
|
|
|
|
|
|
selectedHoldingsModel.append(entry)
|
|
|
|
dropdown.close()
|
2024-07-22 13:52:44 +00:00
|
|
|
|
|
|
|
isChainEnabled(entry)
|
2023-06-14 07:19:45 +00:00
|
|
|
}
|
|
|
|
|
2023-03-13 16:32:14 +00:00
|
|
|
onAddCollectible: {
|
2023-06-01 10:38:56 +00:00
|
|
|
const entry = d.prepareEntry(key, amount, Constants.TokenType.ERC721)
|
2023-04-27 22:13:59 +00:00
|
|
|
entry.valid = true
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
selectedHoldingsModel.append(entry)
|
2023-03-13 16:32:14 +00:00
|
|
|
dropdown.close()
|
2024-07-22 13:52:44 +00:00
|
|
|
|
|
|
|
isChainEnabled(entry)
|
2023-03-13 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 07:19:45 +00:00
|
|
|
onUpdateAsset: {
|
|
|
|
const itemIndex = prepareUpdateIndex(key)
|
|
|
|
|
|
|
|
const entry = d.prepareEntry(key, amount, Constants.TokenType.ERC20)
|
|
|
|
|
|
|
|
root.selectedHoldingsModel.set(itemIndex, entry)
|
|
|
|
dropdown.close()
|
|
|
|
}
|
|
|
|
|
2023-03-13 16:32:14 +00:00
|
|
|
onUpdateCollectible: {
|
|
|
|
const itemIndex = prepareUpdateIndex(key)
|
2023-04-25 21:24:04 +00:00
|
|
|
|
2023-06-01 10:38:56 +00:00
|
|
|
const entry = d.prepareEntry(key, amount, Constants.TokenType.ERC721)
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
root.selectedHoldingsModel.set(itemIndex, entry)
|
2023-03-13 16:32:14 +00:00
|
|
|
dropdown.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
onRemoveClicked: {
|
|
|
|
root.selectedHoldingsModel.remove(tokensSelector.editedIndex)
|
|
|
|
dropdown.close()
|
|
|
|
}
|
2023-03-24 12:41:46 +00:00
|
|
|
|
|
|
|
onNavigateToMintTokenSettings: {
|
2023-06-14 07:19:45 +00:00
|
|
|
root.navigateToMintTokenSettings(isAssetType)
|
2023-03-24 12:41:46 +00:00
|
|
|
close()
|
|
|
|
}
|
2023-03-13 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-04-25 21:24:04 +00:00
|
|
|
const modelItem = selectedHoldingsModel.get(index)
|
2023-06-14 07:19:45 +00:00
|
|
|
|
|
|
|
switch(modelItem.type) {
|
2023-11-07 22:45:47 +00:00
|
|
|
case Constants.TokenType.ERC20:
|
2023-06-14 07:19:45 +00:00
|
|
|
dropdown.assetKey = modelItem.key
|
|
|
|
dropdown.assetAmount = modelItem.amount
|
2023-08-10 12:23:59 +00:00
|
|
|
dropdown.assetMultiplierIndex = modelItem.multiplierIndex
|
2023-11-07 22:45:47 +00:00
|
|
|
dropdown.setActiveTab(Constants.TokenType.ERC20)
|
2023-06-14 07:19:45 +00:00
|
|
|
break
|
2023-11-07 22:45:47 +00:00
|
|
|
case Constants.TokenType.ERC721:
|
2023-06-14 07:19:45 +00:00
|
|
|
dropdown.collectibleKey = modelItem.key
|
|
|
|
dropdown.collectibleAmount = modelItem.amount
|
2023-11-07 22:45:47 +00:00
|
|
|
dropdown.setActiveTab(Constants.TokenType.ERC721)
|
2023-06-14 07:19:45 +00:00
|
|
|
break
|
|
|
|
default:
|
|
|
|
console.warn("Unsupported token type.")
|
|
|
|
}
|
|
|
|
|
2023-03-13 16:32:14 +00:00
|
|
|
dropdown.openUpdateFlow()
|
|
|
|
|
|
|
|
editedIndex = index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
SequenceColumnLayout.Separator {}
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
AirdropRecipientsSelector {
|
|
|
|
id: airdropRecipientsSelector
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
addressesModel: addresses
|
2023-03-13 10:16:08 +00:00
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
infiniteMaxNumberOfRecipients:
|
|
|
|
recipientsCountInstantiator.infinity
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
maxNumberOfRecipients:
|
|
|
|
recipientsCountInstantiator.maximumRecipientsCount
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
membersModel: SortFilterProxyModel {
|
2023-06-14 15:25:48 +00:00
|
|
|
id: selectedMembersModel
|
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
sourceModel: membersModel
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
filters: ExpressionFilter {
|
|
|
|
id: selectedKeysFilter
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2023-05-11 10:44:47 +00:00
|
|
|
property var keys: new Set()
|
2023-03-13 10:02:41 +00:00
|
|
|
|
2023-07-20 19:58:51 +00:00
|
|
|
expression: keys.has(model.airdropAddress) && model.airdropAddress !== ""
|
2023-04-25 21:24:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onRemoveMemberRequested: {
|
2023-07-20 19:58:51 +00:00
|
|
|
const airdropAddress = ModelUtils.get(membersModel, index, "airdropAddress")
|
2023-04-25 21:24:04 +00:00
|
|
|
|
2023-07-20 19:58:51 +00:00
|
|
|
selectedKeysFilter.keys.delete(airdropAddress)
|
2023-05-11 10:44:47 +00:00
|
|
|
selectedKeysFilter.keys = new Set([...selectedKeysFilter.keys])
|
2023-04-25 21:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onAddAddressesRequested: (addresses_) => {
|
|
|
|
addresses.addAddressesFromString(addresses_)
|
|
|
|
airdropRecipientsSelector.clearAddressesInput()
|
|
|
|
airdropRecipientsSelector.positionAddressesListAtEnd()
|
|
|
|
}
|
|
|
|
|
|
|
|
onRemoveAddressRequested: addresses.remove(index)
|
|
|
|
|
|
|
|
ListModel {
|
|
|
|
id: addresses
|
|
|
|
|
2023-06-05 13:49:36 +00:00
|
|
|
function addAddresses(_addresses) {
|
2023-04-25 21:24:04 +00:00
|
|
|
const existing = new Set()
|
|
|
|
|
|
|
|
for (let i = 0; i < count; i++)
|
|
|
|
existing.add(get(i).address)
|
|
|
|
|
2023-06-05 13:49:36 +00:00
|
|
|
_addresses.forEach(address => {
|
|
|
|
if (existing.has(address))
|
2023-04-25 21:24:04 +00:00
|
|
|
return
|
|
|
|
|
2023-06-05 13:49:36 +00:00
|
|
|
const valid = Utils.isValidAddress(address)
|
|
|
|
append({ valid, address })
|
2023-04-25 21:24:04 +00:00
|
|
|
})
|
|
|
|
}
|
2023-06-05 13:49:36 +00:00
|
|
|
|
|
|
|
function addAddressesFromString(addressesString) {
|
|
|
|
const words = addressesString.trim().split(/[\s+,]/)
|
|
|
|
const wordsNonEmpty = words.filter(word => !!word)
|
|
|
|
|
|
|
|
addAddresses(wordsNonEmpty)
|
|
|
|
}
|
2023-04-25 21:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function openPopup(popup) {
|
|
|
|
popup.parent = addButton
|
|
|
|
popup.x = addButton.width + d.dropdownHorizontalOffset
|
|
|
|
popup.y = 0
|
|
|
|
|
|
|
|
popup.open()
|
2023-03-13 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
addButton.onClicked: openPopup(recipientTypeSelectionDropdown)
|
|
|
|
|
|
|
|
RecipientTypeSelectionDropdown {
|
|
|
|
id: recipientTypeSelectionDropdown
|
|
|
|
|
|
|
|
onEthAddressesSelected: {
|
|
|
|
airdropRecipientsSelector.showAddressesInputWhenEmpty = true
|
|
|
|
airdropRecipientsSelector.forceInputFocus()
|
|
|
|
recipientTypeSelectionDropdown.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
onCommunityMembersSelected: {
|
|
|
|
recipientTypeSelectionDropdown.close()
|
|
|
|
membersDropdown.selectedKeys = selectedKeysFilter.keys
|
2023-04-28 09:40:58 +00:00
|
|
|
|
2023-05-11 10:44:47 +00:00
|
|
|
const hasSelection = selectedKeysFilter.keys.size !== 0
|
2023-04-28 09:40:58 +00:00
|
|
|
|
|
|
|
membersDropdown.mode = hasSelection
|
|
|
|
? MembersDropdown.Mode.Update
|
|
|
|
: MembersDropdown.Mode.Add
|
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
airdropRecipientsSelector.openPopup(membersDropdown)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MembersDropdown {
|
|
|
|
id: membersDropdown
|
|
|
|
|
2023-04-28 09:40:58 +00:00
|
|
|
forceButtonDisabled:
|
|
|
|
mode === MembersDropdown.Mode.Update &&
|
2023-05-11 10:44:47 +00:00
|
|
|
[...selectedKeys].sort().join() === [...selectedKeysFilter.keys].sort().join()
|
2023-04-28 09:40:58 +00:00
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
model: SortFilterProxyModel {
|
|
|
|
sourceModel: membersModel
|
|
|
|
|
2024-10-10 17:01:47 +00:00
|
|
|
sorters : [
|
|
|
|
StringSorter {
|
|
|
|
roleName: "preferredDisplayName"
|
|
|
|
caseSensitivity: Qt.CaseInsensitive
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2023-04-25 21:24:04 +00:00
|
|
|
filters: [
|
2024-10-10 17:01:47 +00:00
|
|
|
FastExpressionFilter {
|
2023-04-25 21:24:04 +00:00
|
|
|
enabled: membersDropdown.searchText !== ""
|
|
|
|
|
|
|
|
expression: {
|
|
|
|
const filter = membersDropdown.searchText.toLowerCase()
|
2024-10-10 17:01:47 +00:00
|
|
|
return model.alias.toLowerCase().includes(filter)
|
2023-04-25 21:24:04 +00:00
|
|
|
|| model.displayName.toLowerCase().includes(filter)
|
|
|
|
|| model.ensName.toLowerCase().includes(filter)
|
|
|
|
|| model.localNickname.toLowerCase().includes(filter)
|
|
|
|
|| model.pubKey.toLowerCase().includes(filter)
|
|
|
|
}
|
2024-10-10 17:01:47 +00:00
|
|
|
expectedRoles: ["alias", "displayName", "ensName", "localNickname", "pubKey"]
|
2023-07-20 19:58:51 +00:00
|
|
|
},
|
2024-10-10 17:01:47 +00:00
|
|
|
ValueFilter {
|
|
|
|
roleName: "airdropAddress"
|
|
|
|
value: ""
|
|
|
|
inverted: true
|
2023-04-25 21:24:04 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
onBackButtonClicked: {
|
|
|
|
close()
|
|
|
|
airdropRecipientsSelector.openPopup(
|
|
|
|
recipientTypeSelectionDropdown)
|
|
|
|
}
|
|
|
|
|
|
|
|
onAddButtonClicked: {
|
|
|
|
selectedKeysFilter.keys = selectedKeys
|
|
|
|
close()
|
|
|
|
}
|
|
|
|
}
|
2023-03-13 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 15:25:48 +00:00
|
|
|
SequenceColumnLayout.Separator {}
|
|
|
|
|
2023-07-20 10:38:49 +00:00
|
|
|
FeesBox {
|
2023-07-25 14:14:42 +00:00
|
|
|
id: feesBox
|
2023-06-14 15:25:48 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
|
2023-07-20 10:38:49 +00:00
|
|
|
model: feesModel
|
2023-07-25 14:14:42 +00:00
|
|
|
accountsSelector.model: root.accountsModel
|
|
|
|
|
2023-09-01 04:28:50 +00:00
|
|
|
totalFeeText: root.totalFeeText
|
2023-07-20 10:38:49 +00:00
|
|
|
placeholderText: qsTr("Add valid “What” and “To” values to see fees")
|
2023-07-25 14:14:42 +00:00
|
|
|
|
2023-09-01 04:28:50 +00:00
|
|
|
accountErrorText: root.feeErrorText
|
2023-06-14 15:25:48 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 22:13:59 +00:00
|
|
|
WarningPanel {
|
2023-06-14 15:25:48 +00:00
|
|
|
id: notEnoughTokensWarning
|
|
|
|
|
2023-04-27 22:13:59 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: Style.current.padding
|
|
|
|
|
|
|
|
text: qsTr("Not enough tokens to send to all recipients. Reduce the number of recipients or change the number of tokens sent to each recipient.")
|
|
|
|
|
|
|
|
visible: !recipientsCountInstantiator.infinity &&
|
|
|
|
recipientsCountInstantiator.maximumRecipientsCount < airdropRecipientsSelector.count
|
|
|
|
}
|
|
|
|
|
2024-07-22 13:52:44 +00:00
|
|
|
NetworkWarningPanel {
|
|
|
|
visible: !!d.networkThatIsNotActive
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: Style.current.padding
|
|
|
|
networkThatIsNotActive: d.networkThatIsNotActive
|
|
|
|
onEnableNetwork: {
|
|
|
|
root.enableNetwork(d.networkIdThatIsNotActive)
|
|
|
|
d.networkThatIsNotActive = ""
|
|
|
|
d.networkIdThatIsNotActive = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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")
|
2023-09-01 04:28:50 +00:00
|
|
|
enabled: root.isFullyFilled && root.feesAvailable && root.feeErrorText === ""
|
2023-03-13 16:32:14 +00:00
|
|
|
|
|
|
|
onClicked: {
|
2024-06-07 12:27:56 +00:00
|
|
|
feesPopup.accountAddress = feesBox.accountsSelector.currentAccountAddress
|
|
|
|
feesPopup.accountName = feesBox.accountsSelector.currentAccount.name ?? ""
|
2023-06-06 15:32:53 +00:00
|
|
|
feesPopup.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-21 16:49:57 +00:00
|
|
|
SignTransactionsPopup {
|
2023-06-06 15:32:53 +00:00
|
|
|
id: feesPopup
|
|
|
|
|
2023-07-25 14:14:42 +00:00
|
|
|
property string accountAddress
|
|
|
|
|
2023-06-06 15:32:53 +00:00
|
|
|
destroyOnClose: false
|
|
|
|
|
2023-06-14 15:25:48 +00:00
|
|
|
model: feesModel
|
|
|
|
|
2023-09-01 04:28:50 +00:00
|
|
|
totalFeeText: root.totalFeeText
|
|
|
|
errorText: root.feeErrorText
|
2023-06-06 15:32:53 +00:00
|
|
|
|
|
|
|
onOpened: {
|
|
|
|
const title1 = qsTr("Sign transaction - Airdrop %n token(s)", "",
|
|
|
|
selectedHoldingsModel.rowCount())
|
|
|
|
const title2 = qsTr("to %n recipient(s)", "",
|
|
|
|
addresses.count + airdropRecipientsSelector.membersModel.count)
|
|
|
|
|
|
|
|
title = `${title1} ${title2}`
|
|
|
|
}
|
|
|
|
|
|
|
|
onSignTransactionClicked: {
|
2023-03-13 16:32:14 +00:00
|
|
|
const airdropTokens = ModelUtils.modelToArray(
|
|
|
|
root.selectedHoldingsModel,
|
2023-05-25 10:00:38 +00:00
|
|
|
["contractUniqueKey", "amount"])
|
2023-04-25 21:24:04 +00:00
|
|
|
|
|
|
|
const addresses_ = ModelUtils.modelToArray(
|
|
|
|
addresses, ["address"]).map(e => e.address)
|
2023-03-13 16:32:14 +00:00
|
|
|
|
2023-07-20 19:58:51 +00:00
|
|
|
const airdropAddresses = [...selectedKeysFilter.keys]
|
2023-03-13 10:16:08 +00:00
|
|
|
|
2023-07-20 19:58:51 +00:00
|
|
|
root.airdropClicked(airdropTokens, addresses_.concat(airdropAddresses),
|
2023-07-25 14:14:42 +00:00
|
|
|
accountAddress)
|
2023-03-13 16:32:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|