2023-07-04 15:11:41 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQml.Models 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
import QtGraphicalEffects 1.15
|
|
|
|
|
|
|
|
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
|
2023-08-02 17:39:42 +00:00
|
|
|
import StatusQ.Internal 0.1 as SQInternal
|
2023-07-04 15:11:41 +00:00
|
|
|
|
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
|
|
|
import AppLayouts.Profile.controls 1.0
|
|
|
|
import AppLayouts.Communities.controls 1.0
|
|
|
|
import AppLayouts.Communities.views 1.0
|
|
|
|
import AppLayouts.Communities.helpers 1.0
|
|
|
|
|
|
|
|
import utils 1.0
|
2023-08-02 17:39:42 +00:00
|
|
|
import shared.panels 1.0
|
2023-07-04 15:11:41 +00:00
|
|
|
|
|
|
|
Control {
|
|
|
|
id: root
|
|
|
|
|
2024-03-19 08:41:41 +00:00
|
|
|
required property string componentUid
|
|
|
|
required property bool isEditMode
|
|
|
|
required property var selectedSharedAddressesMap // Map[address, [keyUid, selected, isAirdrop]
|
|
|
|
property var currentSharedAddressesMap // Map[address, [keyUid, selected, isAirdrop]
|
|
|
|
required property int totalNumOfAddressesForSharing
|
|
|
|
required property bool profileProvesOwnershipOfSelectedAddresses
|
|
|
|
required property bool allAddressesToRevealBelongToSingleNonProfileKeypair
|
2024-03-27 12:48:17 +00:00
|
|
|
required property int /*PermissionTypes.Type*/ eligibleToJoinAs
|
2023-07-04 15:11:41 +00:00
|
|
|
|
2023-08-22 18:04:58 +00:00
|
|
|
property bool requirementsCheckPending: false
|
|
|
|
|
2024-03-28 23:05:59 +00:00
|
|
|
required property string communityId
|
2023-07-04 15:11:41 +00:00
|
|
|
required property string communityName
|
|
|
|
required property string communityIcon
|
|
|
|
|
2024-01-24 16:35:53 +00:00
|
|
|
required property var walletAssetsModel
|
2024-03-28 23:05:59 +00:00
|
|
|
required property var walletCollectiblesModel
|
|
|
|
|
2023-07-04 15:11:41 +00:00
|
|
|
required property var walletAccountsModel // name, address, emoji, colorId, assets
|
|
|
|
required property var permissionsModel // id, key, permissionType, holdingsListModel, channelsListModel, isPrivate, tokenCriteriaMet
|
2024-03-28 23:05:59 +00:00
|
|
|
|
2023-07-04 15:11:41 +00:00
|
|
|
required property var assetsModel
|
|
|
|
required property var collectiblesModel
|
|
|
|
|
2024-03-19 08:41:41 +00:00
|
|
|
readonly property string title: isEditMode ? qsTr("Edit which addresses you share with %1").arg(root.communityName)
|
|
|
|
: qsTr("Select addresses to share with %1").arg(root.communityName)
|
2023-07-04 15:11:41 +00:00
|
|
|
|
2024-03-19 08:41:41 +00:00
|
|
|
readonly property var rightButtons: root.isEditMode? [d.cancelButton, d.saveButton] : [d.shareAddressesButton]
|
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)
|
|
|
|
signal shareSelectedAddressesClicked()
|
2023-08-02 17:39:42 +00:00
|
|
|
signal close()
|
2023-07-04 15:11:41 +00:00
|
|
|
|
2023-08-02 17:39:42 +00:00
|
|
|
padding: 0
|
2023-07-04 15:11:41 +00:00
|
|
|
spacing: Style.current.padding
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
// internal logic
|
|
|
|
readonly property bool hasPermissions: root.permissionsModel && root.permissionsModel.count
|
2024-03-19 08:41:41 +00:00
|
|
|
readonly property int selectedSharedAddressesCount: root.selectedSharedAddressesMap.size
|
2023-08-02 17:39:42 +00:00
|
|
|
|
2024-03-19 08:41:41 +00:00
|
|
|
readonly property bool dirty: {
|
|
|
|
if (root.currentSharedAddressesMap.size !== root.selectedSharedAddressesMap.size) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
for (const [key, value] of root.currentSharedAddressesMap) {
|
|
|
|
const obj = root.selectedSharedAddressesMap.get(key)
|
|
|
|
if (!obj || value.selected !== obj.selected || value.isAirdrop !== obj.isAirdrop) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2023-08-02 17:39:42 +00:00
|
|
|
|
|
|
|
// warning states
|
|
|
|
readonly property bool lostCommunityPermission: root.isEditMode && permissionsView.lostPermissionToJoin
|
|
|
|
readonly property bool lostChannelPermissions: root.isEditMode && permissionsView.lostChannelPermissions
|
2023-07-04 15:11:41 +00:00
|
|
|
|
2024-03-19 08:41:41 +00:00
|
|
|
readonly property var cancelButton: StatusFlatButton {
|
|
|
|
visible: root.isEditMode
|
|
|
|
borderColor: Theme.palette.baseColor2
|
|
|
|
text: qsTr("Cancel")
|
|
|
|
onClicked: root.close()
|
|
|
|
}
|
2023-08-02 17:39:42 +00:00
|
|
|
|
2024-03-19 08:41:41 +00:00
|
|
|
readonly property var saveButton: StatusButton {
|
|
|
|
enabled: d.dirty
|
|
|
|
type: d.lostCommunityPermission || d.lostChannelPermissions ? StatusBaseButton.Type.Danger : StatusBaseButton.Type.Normal
|
|
|
|
visible: root.isEditMode
|
2023-08-24 20:36:38 +00:00
|
|
|
|
2024-03-19 08:41:41 +00:00
|
|
|
text: {
|
|
|
|
if (d.lostCommunityPermission) {
|
|
|
|
return qsTr("Save changes & leave %1").arg(root.communityName)
|
|
|
|
}
|
|
|
|
if (d.lostChannelPermissions) {
|
|
|
|
return qsTr("Save changes & update my permissions")
|
|
|
|
}
|
|
|
|
if (d.selectedSharedAddressesCount === root.totalNumOfAddressesForSharing) {
|
|
|
|
return qsTr("Reveal all addresses")
|
|
|
|
}
|
|
|
|
return qsTr("Reveal %n address(s)", "", d.selectedSharedAddressesCount)
|
|
|
|
}
|
2023-08-24 20:36:38 +00:00
|
|
|
|
2024-03-19 08:41:41 +00:00
|
|
|
icon.name: {
|
|
|
|
if (!d.lostCommunityPermission
|
|
|
|
&& !d.lostChannelPermissions
|
|
|
|
&& root.profileProvesOwnershipOfSelectedAddresses) {
|
|
|
|
if (userProfile.usingBiometricLogin) {
|
|
|
|
return "touch-id"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userProfile.isKeycardUser) {
|
|
|
|
return "keycard"
|
|
|
|
}
|
|
|
|
|
|
|
|
return "password"
|
|
|
|
}
|
|
|
|
if (root.allAddressesToRevealBelongToSingleNonProfileKeypair) {
|
|
|
|
return "keycard"
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
root.shareSelectedAddressesClicked()
|
|
|
|
}
|
2023-08-02 17:39:42 +00:00
|
|
|
}
|
2024-03-19 08:41:41 +00:00
|
|
|
|
|
|
|
readonly property var shareAddressesButton: StatusButton {
|
|
|
|
visible: !root.isEditMode
|
2024-03-27 12:48:17 +00:00
|
|
|
enabled: root.eligibleToJoinAs !== PermissionTypes.Type.None
|
2024-03-19 08:41:41 +00:00
|
|
|
text: {
|
|
|
|
if (d.selectedSharedAddressesCount === root.totalNumOfAddressesForSharing) {
|
|
|
|
return qsTr("Share all addresses to join")
|
2023-08-02 17:39:42 +00:00
|
|
|
}
|
2024-03-19 08:41:41 +00:00
|
|
|
return qsTr("Share %n address(s) to join", "", d.selectedSharedAddressesCount)
|
|
|
|
}
|
2023-08-02 17:39:42 +00:00
|
|
|
|
2024-03-19 08:41:41 +00:00
|
|
|
icon.name: {
|
|
|
|
if (root.profileProvesOwnershipOfSelectedAddresses) {
|
|
|
|
if (userProfile.usingBiometricLogin) {
|
|
|
|
return "touch-id"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userProfile.isKeycardUser) {
|
|
|
|
return "keycard"
|
|
|
|
}
|
|
|
|
|
|
|
|
return "password"
|
2023-08-02 17:39:42 +00:00
|
|
|
}
|
2024-03-19 08:41:41 +00:00
|
|
|
if (root.allAddressesToRevealBelongToSingleNonProfileKeypair) {
|
|
|
|
return "keycard"
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
2023-08-02 17:39:42 +00:00
|
|
|
}
|
2024-03-19 08:41:41 +00:00
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
root.shareSelectedAddressesClicked()
|
|
|
|
}
|
|
|
|
}
|
2023-08-02 17:39:42 +00:00
|
|
|
}
|
2023-07-04 15:11:41 +00:00
|
|
|
|
|
|
|
contentItem: ColumnLayout {
|
|
|
|
spacing: 0
|
2023-08-02 17:39:42 +00:00
|
|
|
|
|
|
|
// warning panel
|
|
|
|
ModuleWarning {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 32
|
|
|
|
text: d.lostCommunityPermission ? qsTr("Selected addresses have insufficient tokens to maintain %1 membership").arg(root.communityName) :
|
|
|
|
d.lostChannelPermissions ? qsTr("By deselecting these addresses, you will lose channel permissions") :
|
|
|
|
""
|
2024-03-27 12:48:17 +00:00
|
|
|
active: d.lostCommunityPermission || d.lostChannelPermissions
|
|
|
|
visible: active
|
2023-08-02 17:39:42 +00:00
|
|
|
closeBtnVisible: false
|
|
|
|
}
|
|
|
|
|
2023-07-04 15:11:41 +00:00
|
|
|
// addresses
|
|
|
|
SharedAddressesAccountSelector {
|
|
|
|
id: accountSelector
|
|
|
|
hasPermissions: d.hasPermissions
|
2024-03-28 23:05:59 +00:00
|
|
|
|
2023-07-04 15:11:41 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: contentHeight + topMargin + bottomMargin
|
|
|
|
Layout.maximumHeight: hasPermissions ? permissionsView.implicitHeight > root.availableHeight / 2 ? root.availableHeight / 2 : root.availableHeight : -1
|
|
|
|
Layout.fillHeight: !hasPermissions
|
2024-03-28 23:05:59 +00:00
|
|
|
|
|
|
|
uniquePermissionAssetsKeys:
|
|
|
|
PermissionsHelpers.getUniquePermissionTokenKeys(
|
|
|
|
root.permissionsModel, Constants.TokenType.ERC20)
|
|
|
|
|
|
|
|
uniquePermissionCollectiblesKeys:
|
|
|
|
PermissionsHelpers.getUniquePermissionTokenKeys(
|
|
|
|
root.permissionsModel, Constants.TokenType.ERC721)
|
|
|
|
|
2023-08-09 12:31:58 +00:00
|
|
|
model: root.walletAccountsModel
|
2024-01-24 16:35:53 +00:00
|
|
|
walletAssetsModel: root.walletAssetsModel
|
2024-03-28 23:05:59 +00:00
|
|
|
walletCollectiblesModel: root.walletCollectiblesModel
|
|
|
|
|
|
|
|
communityId: root.communityId
|
|
|
|
communityCollectiblesModel: root.collectiblesModel
|
|
|
|
|
2024-03-19 08:41:41 +00:00
|
|
|
selectedSharedAddressesMap: root.selectedSharedAddressesMap
|
|
|
|
|
|
|
|
onToggleAddressSelection: {
|
|
|
|
root.toggleAddressSelection(keyUid, address)
|
|
|
|
}
|
|
|
|
|
|
|
|
onAirdropAddressSelected: {
|
|
|
|
root.airdropAddressSelected(address)
|
2023-08-02 17:39:42 +00:00
|
|
|
}
|
2024-03-19 08:41:41 +00:00
|
|
|
|
2024-03-27 12:48:17 +00:00
|
|
|
getCurrencyAmount: function (balance, symbol) {
|
2024-01-24 16:35:53 +00:00
|
|
|
return root.getCurrencyAmount(balance, symbol)
|
|
|
|
}
|
2023-07-04 15:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// divider with top rounded corners + drop shadow
|
|
|
|
Rectangle {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: Style.current.padding * 2
|
2024-03-27 12:48:17 +00:00
|
|
|
color: permissionsView.color
|
2023-07-04 15:11:41 +00:00
|
|
|
radius: Style.current.padding
|
|
|
|
border.width: 1
|
|
|
|
border.color: Theme.palette.baseColor3
|
2024-01-18 14:06:25 +00:00
|
|
|
visible: permissionsView.hasAnyVisiblePermission
|
2023-07-04 15:11:41 +00:00
|
|
|
|
|
|
|
layer.enabled: true
|
|
|
|
layer.effect: DropShadow {
|
|
|
|
horizontalOffset: 0
|
|
|
|
verticalOffset: -9
|
|
|
|
radius: 14
|
|
|
|
samples: 29
|
|
|
|
color: Qt.rgba(0, 0, 0, 0.04)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// permissions
|
|
|
|
SharedAddressesPermissionsPanel {
|
|
|
|
id: permissionsView
|
2023-08-02 17:39:42 +00:00
|
|
|
isEditMode: root.isEditMode
|
2023-07-04 15:11:41 +00:00
|
|
|
permissionsModel: root.permissionsModel
|
|
|
|
assetsModel: root.assetsModel
|
|
|
|
collectiblesModel: root.collectiblesModel
|
2024-03-25 18:39:45 +00:00
|
|
|
requirementsCheckPending: root.requirementsCheckPending
|
2023-07-04 15:11:41 +00:00
|
|
|
communityName: root.communityName
|
|
|
|
communityIcon: root.communityIcon
|
2024-03-27 12:48:17 +00:00
|
|
|
eligibleToJoinAs: root.eligibleToJoinAs
|
2023-07-04 15:11:41 +00:00
|
|
|
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: -Style.current.padding // compensate for the half-rounded divider above
|
2024-01-18 14:06:25 +00:00
|
|
|
visible: permissionsView.hasAnyVisiblePermission
|
2023-07-04 15:11:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|