2023-07-04 15:11:41 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
|
2024-01-24 16:35:53 +00:00
|
|
|
import StatusQ 0.1
|
2023-07-04 15:11:41 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
|
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
StatusListView {
|
|
|
|
id: root
|
|
|
|
|
2024-03-19 08:41:41 +00:00
|
|
|
required property var selectedSharedAddressesMap // Map[address, [selected, isAirdrop]]
|
|
|
|
|
2024-01-24 16:35:53 +00:00
|
|
|
property var walletAssetsModel
|
2023-07-04 15:11:41 +00:00
|
|
|
property bool hasPermissions
|
2024-03-28 23:05:59 +00:00
|
|
|
|
|
|
|
property var uniquePermissionAssetsKeys
|
|
|
|
property var uniquePermissionCollectiblesKeys
|
|
|
|
|
|
|
|
property var walletCollectiblesModel
|
|
|
|
property var communityCollectiblesModel
|
|
|
|
property string communityId
|
2023-07-04 15:11:41 +00:00
|
|
|
|
2024-01-24 16:35:53 +00:00
|
|
|
property var getCurrencyAmount: function (balance, symbol){}
|
|
|
|
|
2024-03-19 08:41:41 +00:00
|
|
|
signal toggleAddressSelection(string keyUid, string address)
|
|
|
|
signal airdropAddressSelected (string address)
|
2023-07-04 15:11:41 +00:00
|
|
|
|
|
|
|
leftMargin: d.absLeftMargin
|
2024-10-15 19:26:12 +00:00
|
|
|
topMargin: Theme.padding
|
|
|
|
rightMargin: Theme.padding
|
|
|
|
bottomMargin: Theme.padding
|
2023-07-04 15:11:41 +00:00
|
|
|
|
2024-03-28 23:05:59 +00:00
|
|
|
|
|
|
|
ModelChangeTracker {
|
|
|
|
id: communityCollectiblesModelTracker
|
|
|
|
|
|
|
|
model: communityCollectiblesModel
|
|
|
|
|
|
|
|
onRevisionChanged: {
|
|
|
|
const collectibles = ModelUtils.modelToArray(
|
|
|
|
communityCollectiblesModel,
|
|
|
|
["key", "name", "symbol", "icon", "communityId"])
|
|
|
|
.filter(e => e.communityId === communityId)
|
|
|
|
|
|
|
|
const keysToNames = {}
|
|
|
|
|
|
|
|
for (const c of collectibles)
|
|
|
|
keysToNames[c.key] = {
|
|
|
|
name: c.name,
|
|
|
|
symbol: c.symbol,
|
|
|
|
icon: c.icon
|
|
|
|
}
|
|
|
|
|
|
|
|
d.collectiblesMetadata
|
|
|
|
= uniquePermissionCollectiblesKeys.map(k => keysToNames[k])
|
|
|
|
d.collectiblesNames = d.collectiblesMetadata.map(c => c.name)
|
|
|
|
|
|
|
|
const namesToSymbols = {}
|
|
|
|
d.collectiblesMetadata.forEach(c => namesToSymbols[c.name] = c.symbol)
|
|
|
|
d.collectiblesNamesToSymbols = namesToSymbols
|
|
|
|
|
|
|
|
const namesToImages = {}
|
|
|
|
d.collectiblesMetadata.forEach(c => namesToImages[c.name] = c.icon)
|
|
|
|
d.collectiblesNamesToImages = namesToImages
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: revisionChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
ModelChangeTracker {
|
|
|
|
id: filteredWalletCollectiblesTracker
|
|
|
|
|
|
|
|
model: filteredWalletCollectibles
|
|
|
|
}
|
|
|
|
|
2023-07-04 15:11:41 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
2024-03-28 23:05:59 +00:00
|
|
|
property var collectiblesMetadata: []
|
|
|
|
property var collectiblesNames: []
|
|
|
|
property var collectiblesNamesToSymbols: ({})
|
|
|
|
property var collectiblesNamesToImages: ({})
|
|
|
|
|
2024-03-19 08:41:41 +00:00
|
|
|
readonly property int selectedSharedAddressesCount: root.selectedSharedAddressesMap.size
|
|
|
|
|
2023-07-04 15:11:41 +00:00
|
|
|
// UI
|
|
|
|
readonly property int absLeftMargin: 12
|
|
|
|
|
|
|
|
readonly property ButtonGroup airdropGroup: ButtonGroup {
|
|
|
|
exclusive: true
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly property ButtonGroup addressesGroup: ButtonGroup {
|
|
|
|
exclusive: false
|
|
|
|
}
|
|
|
|
|
2024-03-28 23:05:59 +00:00
|
|
|
function getTotalBalance(balances, decimals) {
|
2024-01-24 16:35:53 +00:00
|
|
|
let totalBalance = 0
|
2024-03-28 23:05:59 +00:00
|
|
|
for(let i = 0; i < balances.count; i++) {
|
2024-01-24 16:35:53 +00:00
|
|
|
let balancePerAddressPerChain = ModelUtils.get(balances, i)
|
|
|
|
totalBalance += AmountsArithmetic.toNumber(balancePerAddressPerChain.balance, decimals)
|
|
|
|
}
|
|
|
|
return totalBalance
|
|
|
|
}
|
2023-07-04 15:11:41 +00:00
|
|
|
}
|
|
|
|
|
2024-03-28 23:05:59 +00:00
|
|
|
SortFilterProxyModel {
|
|
|
|
id: filteredWalletCollectibles
|
|
|
|
|
|
|
|
sourceModel: walletCollectiblesModel
|
|
|
|
|
|
|
|
filters: [
|
|
|
|
ValueFilter {
|
|
|
|
roleName: "communityId"
|
|
|
|
value: root.communityId
|
|
|
|
},
|
|
|
|
FastExpressionFilter {
|
|
|
|
expression: d.collectiblesNames.includes(model.name)
|
|
|
|
expectedRoles: ["name"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
ListModel {
|
|
|
|
id: walletAccountCollectiblesModel
|
|
|
|
|
|
|
|
readonly property var data: {
|
|
|
|
filteredWalletCollectiblesTracker.revision
|
|
|
|
const usedCollectibles = ModelUtils.modelToArray(filteredWalletCollectibles)
|
|
|
|
|
|
|
|
const collectiblesGroupingMap = {}
|
|
|
|
|
|
|
|
for (const c of usedCollectibles) {
|
|
|
|
const key = `${c.name}_${c.ownership[0].accountAddress}`
|
|
|
|
|
|
|
|
if (!collectiblesGroupingMap[key])
|
|
|
|
collectiblesGroupingMap[key] = []
|
|
|
|
|
|
|
|
collectiblesGroupingMap[key].push(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
const collectiblesGrouped = Object.values(collectiblesGroupingMap).map(e => {
|
|
|
|
const firstEntry = e[0]
|
|
|
|
|
|
|
|
return {
|
|
|
|
symbol: d.collectiblesNamesToSymbols[firstEntry.name] || "",
|
|
|
|
enabledNetworkBalance: e.length,
|
|
|
|
account: firstEntry.ownership[0].accountAddress,
|
|
|
|
imageUrl: d.collectiblesNamesToImages[firstEntry.name] || ""
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return collectiblesGrouped
|
|
|
|
}
|
|
|
|
|
|
|
|
onDataChanged: {
|
|
|
|
clear()
|
|
|
|
append(data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-15 19:26:12 +00:00
|
|
|
spacing: Theme.halfPadding
|
2023-07-04 15:11:41 +00:00
|
|
|
delegate: StatusListItem {
|
2023-08-24 20:36:38 +00:00
|
|
|
readonly property string address: model.address.toLowerCase()
|
2024-04-01 14:24:18 +00:00
|
|
|
readonly property int tokenCount: tagsCount
|
2023-08-24 20:36:38 +00:00
|
|
|
|
|
|
|
id: listItem
|
2023-07-04 15:11:41 +00:00
|
|
|
width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin
|
|
|
|
statusListItemTitle.font.weight: Font.Medium
|
|
|
|
title: model.name
|
2024-03-28 23:05:59 +00:00
|
|
|
tertiaryTitle: root.hasPermissions && !tagsCount ? qsTr("No relevant tokens") : ""
|
2024-01-24 16:35:53 +00:00
|
|
|
|
2024-09-02 11:29:55 +00:00
|
|
|
ObjectProxyModel {
|
2024-01-24 16:35:53 +00:00
|
|
|
id: filteredBalances
|
2024-09-02 11:29:55 +00:00
|
|
|
|
2024-01-24 16:35:53 +00:00
|
|
|
sourceModel: root.walletAssetsModel
|
2024-03-28 23:05:59 +00:00
|
|
|
|
2024-09-02 11:29:55 +00:00
|
|
|
delegate: SortFilterProxyModel {
|
|
|
|
readonly property SortFilterProxyModel balances: this
|
|
|
|
|
|
|
|
sourceModel: model.balances
|
2024-03-28 23:05:59 +00:00
|
|
|
filters: RegExpFilter {
|
|
|
|
roleName: "account"
|
|
|
|
pattern: listItem.address
|
|
|
|
syntax: RegExpFilter.FixedString
|
|
|
|
caseSensitivity: Qt.CaseInsensitive
|
2024-01-24 16:35:53 +00:00
|
|
|
}
|
|
|
|
}
|
2024-09-02 11:29:55 +00:00
|
|
|
|
|
|
|
expectedRoles: "balances"
|
|
|
|
exposedRoles: "balances"
|
2024-01-24 16:35:53 +00:00
|
|
|
}
|
2024-03-28 23:05:59 +00:00
|
|
|
|
|
|
|
SortFilterProxyModel {
|
|
|
|
id: accountCollectiblesModel
|
|
|
|
|
|
|
|
sourceModel: walletAccountCollectiblesModel
|
|
|
|
|
|
|
|
filters: RegExpFilter {
|
|
|
|
roleName: "account"
|
|
|
|
pattern: listItem.address
|
|
|
|
syntax: RegExpFilter.FixedString
|
|
|
|
caseSensitivity: Qt.CaseInsensitive
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConcatModel {
|
|
|
|
id: concatModel
|
|
|
|
|
2024-04-09 12:24:53 +00:00
|
|
|
markerRoleName: "type"
|
|
|
|
|
2024-03-28 23:05:59 +00:00
|
|
|
sources: [
|
|
|
|
SourceModel {
|
2024-04-09 12:24:53 +00:00
|
|
|
model: walletAccountAssetsModel
|
|
|
|
markerRoleValue: Constants.TokenType.ERC20
|
2024-03-28 23:05:59 +00:00
|
|
|
},
|
|
|
|
SourceModel {
|
2024-04-09 12:24:53 +00:00
|
|
|
model: accountCollectiblesModel
|
|
|
|
markerRoleValue: Constants.TokenType.ERC721
|
2024-03-28 23:05:59 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2023-07-04 15:11:41 +00:00
|
|
|
tagsModel: SortFilterProxyModel {
|
2024-03-28 23:05:59 +00:00
|
|
|
sourceModel: concatModel
|
|
|
|
|
|
|
|
filters: ValueFilter {
|
|
|
|
roleName: "enabledNetworkBalance"
|
|
|
|
value: 0
|
|
|
|
inverted: true
|
|
|
|
}
|
|
|
|
|
2024-04-01 14:24:18 +00:00
|
|
|
sorters: [
|
|
|
|
RoleSorter {
|
|
|
|
roleName: "symbol"
|
|
|
|
}
|
|
|
|
]
|
2024-03-28 23:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SortFilterProxyModel {
|
2023-07-04 15:11:41 +00:00
|
|
|
id: walletAccountAssetsModel
|
2024-03-28 23:05:59 +00:00
|
|
|
|
2024-01-24 16:35:53 +00:00
|
|
|
sourceModel: filteredBalances
|
2023-07-04 15:11:41 +00:00
|
|
|
|
2024-01-24 16:35:53 +00:00
|
|
|
function filterPredicate(symbol) {
|
2024-03-28 23:05:59 +00:00
|
|
|
return root.uniquePermissionAssetsKeys.includes(symbol.toUpperCase())
|
2023-07-04 15:11:41 +00:00
|
|
|
}
|
|
|
|
|
2024-03-28 23:05:59 +00:00
|
|
|
proxyRoles: [
|
|
|
|
FastExpressionRole {
|
|
|
|
name: "enabledNetworkBalance"
|
|
|
|
expression: d.getTotalBalance(model.balances, model.decimals)
|
|
|
|
expectedRoles: ["balances", "decimals"]
|
|
|
|
},
|
|
|
|
FastExpressionRole {
|
|
|
|
name: "imageUrl"
|
|
|
|
|
|
|
|
function getIcon(symbol) {
|
|
|
|
return Constants.tokenIcon(symbol.toUpperCase())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Singletons cannot be used directly in sfpm's expressions
|
|
|
|
expression: getIcon(model.symbol)
|
|
|
|
expectedRoles: ["symbol"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2024-01-24 16:35:53 +00:00
|
|
|
filters: FastExpressionFilter {
|
|
|
|
expression: walletAccountAssetsModel.filterPredicate(model.symbol)
|
|
|
|
expectedRoles: ["symbol"]
|
2023-07-04 15:11:41 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-28 23:05:59 +00:00
|
|
|
|
2024-10-15 19:26:12 +00:00
|
|
|
statusListItemInlineTagsSlot.spacing: Theme.padding
|
2024-03-28 23:05:59 +00:00
|
|
|
|
2023-07-04 15:11:41 +00:00
|
|
|
tagsDelegate: Row {
|
|
|
|
spacing: 4
|
|
|
|
StatusRoundedImage {
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
width: 16
|
|
|
|
height: 16
|
2024-03-28 23:05:59 +00:00
|
|
|
image.source: model.imageUrl
|
2023-07-04 15:11:41 +00:00
|
|
|
}
|
|
|
|
StatusBaseText {
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
font.pixelSize: Theme.tertiaryTextFontSize
|
2024-04-09 12:24:53 +00:00
|
|
|
|
|
|
|
readonly property int type: model.type
|
|
|
|
|
2024-03-28 23:05:59 +00:00
|
|
|
text: {
|
2024-04-09 12:24:53 +00:00
|
|
|
if (type === Constants.TokenType.ERC20)
|
2024-03-28 23:05:59 +00:00
|
|
|
return LocaleUtils.currencyAmountToLocaleString(
|
|
|
|
root.getCurrencyAmount(model.enabledNetworkBalance,
|
|
|
|
model.symbol))
|
|
|
|
|
|
|
|
return LocaleUtils.numberToLocaleString(model.enabledNetworkBalance)
|
|
|
|
+ " " + model.symbol
|
|
|
|
}
|
2023-07-04 15:11:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-09 12:31:58 +00:00
|
|
|
asset.color: !!model.color ? model.color : ""
|
2023-07-04 15:11:41 +00:00
|
|
|
asset.emoji: model.emoji
|
|
|
|
asset.name: !model.emoji ? "filled-account": ""
|
|
|
|
asset.letterSize: 14
|
|
|
|
asset.isLetterIdenticon: !!model.emoji
|
|
|
|
asset.isImage: asset.isLetterIdenticon
|
|
|
|
|
|
|
|
components: [
|
|
|
|
StatusFlatButton {
|
|
|
|
ButtonGroup.group: d.airdropGroup
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
icon.name: "airdrop"
|
2024-05-02 18:48:06 +00:00
|
|
|
icon.color: checked ? Theme.palette.primaryColor1 : disabledTextColor
|
2023-07-04 15:11:41 +00:00
|
|
|
checkable: true
|
2024-03-19 08:41:41 +00:00
|
|
|
checked: {
|
2024-03-28 23:05:59 +00:00
|
|
|
const obj = root.selectedSharedAddressesMap.get(listItem.address)
|
2024-03-19 08:41:41 +00:00
|
|
|
if (!!obj) {
|
|
|
|
return obj.isAirdrop
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
enabled: shareAddressCheckbox.checked && d.selectedSharedAddressesCount > 1 // last cannot be unchecked
|
2023-07-04 15:11:41 +00:00
|
|
|
visible: shareAddressCheckbox.checked
|
|
|
|
opacity: enabled ? 1.0 : 0.3
|
2024-03-19 08:41:41 +00:00
|
|
|
|
2024-03-28 23:05:59 +00:00
|
|
|
onToggled: root.airdropAddressSelected(listItem.address)
|
2023-07-04 15:11:41 +00:00
|
|
|
|
|
|
|
StatusToolTip {
|
|
|
|
text: qsTr("Use this address for any Community airdrops")
|
|
|
|
visible: parent.hovered
|
|
|
|
delay: 500
|
|
|
|
}
|
|
|
|
},
|
|
|
|
StatusCheckBox {
|
|
|
|
id: shareAddressCheckbox
|
2024-03-28 23:05:59 +00:00
|
|
|
|
2023-07-04 15:11:41 +00:00
|
|
|
ButtonGroup.group: d.addressesGroup
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
checkable: true
|
2024-03-19 08:41:41 +00:00
|
|
|
checked: root.selectedSharedAddressesMap.has(listItem.address)
|
|
|
|
enabled: !(d.selectedSharedAddressesCount === 1 && checked) // last cannot be unchecked
|
2023-07-04 15:11:41 +00:00
|
|
|
|
2024-03-28 23:05:59 +00:00
|
|
|
onToggled: root.toggleAddressSelection(model.keyUid, listItem.address)
|
2023-07-04 15:11:41 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|