feat(CommunitySettingsView): Integrate Kick/Ban/Destruct popups for TokenMaster

Closes: #12066
This commit is contained in:
Michał Cieślak 2023-09-21 15:02:18 +02:00 committed by Michał
parent ec5bed6261
commit 82a5147bb5
6 changed files with 116 additions and 28 deletions

View File

@ -67,6 +67,11 @@ StackView {
signal remotelyDestructCollectibles(var walletsAndAmounts, // { [walletAddress (string), amount (int)] } signal remotelyDestructCollectibles(var walletsAndAmounts, // { [walletAddress (string), amount (int)] }
string tokenKey, string tokenKey,
string accountAddress) string accountAddress)
signal remotelyDestructAndBan(string contactId, string tokenKey, string accountAddress,
bool removeMessages)
signal remotelyDestructAndKick(string contactId, string tokenKey, string accountAddress)
signal burnToken(string tokenKey, string amount, string accountAddress) signal burnToken(string tokenKey, string amount, string accountAddress)
signal airdropToken(string tokenKey, string amount, int type, var addresses) signal airdropToken(string tokenKey, string amount, int type, var addresses)
signal deleteToken(string tokenKey) signal deleteToken(string tokenKey)
@ -551,28 +556,31 @@ StackView {
view.token.type, [address]) // tokenKey instead when backend airdrop ready to use key instead of symbol view.token.type, [address]) // tokenKey instead when backend airdrop ready to use key instead of symbol
} }
onViewProfileRequested: {
Global.openProfilePopup(contactId)
}
onViewMessagesRequested: {
// TODO: https://github.com/status-im/status-desktop/issues/11860
console.warn("View Messages is not implemented yet")
}
onRemoteDestructRequested: { onRemoteDestructRequested: {
if (token.isPrivilegedToken) { if (token.isPrivilegedToken) {
tokenMasterActionPopup.openPopup( tokenMasterActionPopup.openPopup(
TokenMasterActionPopup.ActionType.RemotelyDestruct, name, address) TokenMasterActionPopup.ActionType.RemotelyDestruct,
name, address, "")
} else { } else {
remotelyDestructPopup.open() remotelyDestructPopup.open()
// TODO: set the address selected in the popup's list // TODO: set the address selected in the popup's list
} }
} }
onViewProfileRequested: {
Global.openProfilePopup(contactId)
}
onViewMessagesRequested: {
// TODO: https://github.com/status-im/status-desktop/issues/11860
console.warn("View Messages is not implemented yet")
}
onBanRequested: { onBanRequested: {
if (token.isPrivilegedToken) if (token.isPrivilegedToken)
tokenMasterActionPopup.openPopup( tokenMasterActionPopup.openPopup(
TokenMasterActionPopup.ActionType.Ban, name) TokenMasterActionPopup.ActionType.Ban, name,
address, contactId)
else else
kickBanPopup.openPopup(KickBanPopup.Mode.Ban, name, contactId) kickBanPopup.openPopup(KickBanPopup.Mode.Ban, name, contactId)
} }
@ -580,7 +588,8 @@ StackView {
onKickRequested: { onKickRequested: {
if (token.isPrivilegedToken) if (token.isPrivilegedToken)
tokenMasterActionPopup.openPopup( tokenMasterActionPopup.openPopup(
TokenMasterActionPopup.ActionType.Kick, name) TokenMasterActionPopup.ActionType.Kick, name,
address, contactId)
else else
kickBanPopup.openPopup(KickBanPopup.Mode.Kick, name, contactId) kickBanPopup.openPopup(KickBanPopup.Mode.Kick, name, contactId)
} }
@ -589,6 +598,7 @@ StackView {
id: tokenMasterActionPopup id: tokenMasterActionPopup
property string address: "" property string address: ""
property string contactId: ""
communityName: root.communityName communityName: root.communityName
networkName: view.token.chainName networkName: view.token.chainName
@ -598,16 +608,22 @@ StackView {
feeErrorText: selfDestructFeesSubscriber.feeErrorText feeErrorText: selfDestructFeesSubscriber.feeErrorText
isFeeLoading: !selfDestructFeesSubscriber.feesResponse isFeeLoading: !selfDestructFeesSubscriber.feesResponse
function openPopup(type, userName, address) { function openPopup(type, userName, address, contactId) {
tokenMasterActionPopup.actionType = type tokenMasterActionPopup.actionType = type
tokenMasterActionPopup.userName = userName || tokenMasterActionPopup.userName = userName ||
SQUtils.Utils.elideAndFormatWalletAddress(address) SQUtils.Utils.elideAndFormatWalletAddress(address)
tokenMasterActionPopup.address = address tokenMasterActionPopup.address = address
tokenMasterActionPopup.contactId = contactId
open() open()
} }
onRemotelyDestructClicked: signPopup.open()
onKickClicked: signPopup.open()
onBanClicked: signPopup.open()
SelfDestructFeesSubscriber { SelfDestructFeesSubscriber {
id: selfDestructFeesSubscriber id: selfDestructFeesSubscriber
walletsAndAmounts: [{ walletsAndAmounts: [{
walletAddress: tokenMasterActionPopup.address, walletAddress: tokenMasterActionPopup.address,
amount: 1 amount: 1
@ -615,7 +631,56 @@ StackView {
accountAddress: tokenMasterActionPopup.selectedAccount accountAddress: tokenMasterActionPopup.selectedAccount
tokenKey: view.token.key tokenKey: view.token.key
enabled: tokenMasterActionPopup.opened enabled: tokenMasterActionPopup.opened
Component.onCompleted: root.registerSelfDestructFeesSubscriber(selfDestructFeesSubscriber) Component.onCompleted: root.registerSelfDestructFeesSubscriber(
selfDestructFeesSubscriber)
}
SignTransactionsPopup {
id: signPopup
title: qsTr("Sign transaction - Remotely-destruct TokenMaster token")
totalFeeText: tokenMasterActionPopup.feeText
errorText: tokenMasterActionPopup.feeErrorText
accountName: tokenMasterActionPopup.selectedAccountName
model: QtObject {
readonly property string title: tokenMasterActionPopup.feeLabel
readonly property string feeText: tokenMasterActionPopup.feeText
readonly property bool error: tokenMasterActionPopup.feeErrorText !== ""
}
onSignTransactionClicked: {
// https://bugreports.qt.io/browse/QTBUG-91917
var contactId = tokenMasterActionPopup.contactId
var tokenKey = tokenViewPage.token.key
var accountAddress = tokenMasterActionPopup.selectedAccount
switch (tokenMasterActionPopup.actionType) {
case TokenMasterActionPopup.ActionType.RemotelyDestruct:
var tokenToDestruct = {
walletAddress: tokenMasterActionPopup.address,
amount: 1
}
root.remotelyDestructCollectibles(
[tokenToDestruct],
tokenKey, accountAddress)
break
case TokenMasterActionPopup.ActionType.Kick:
root.remotelyDestructAndKick(contactId, tokenKey,
accountAddress)
break
case TokenMasterActionPopup.ActionType.Ban:
root.remotelyDestructAndBan(contactId, tokenKey,
accountAddress,
tokenMasterActionPopup.deleteMessages)
break
}
tokenMasterActionPopup.close()
}
} }
} }

View File

@ -31,8 +31,8 @@ Control {
signal viewMessagesRequested(string contactId) signal viewMessagesRequested(string contactId)
signal airdropRequested(string address) signal airdropRequested(string address)
signal remoteDestructRequested(string name, string address) signal remoteDestructRequested(string name, string address)
signal kickRequested(string name, string contactId) signal kickRequested(string name, string contactId, string address)
signal banRequested(string name, string contactId) signal banRequested(string name, string contactId, string address)
signal generalAirdropRequested signal generalAirdropRequested
@ -202,7 +202,8 @@ Control {
enabled: !menu.rawAddress enabled: !menu.rawAddress
type: StatusBaseButton.Type.Danger type: StatusBaseButton.Type.Danger
onTriggered: root.kickRequested(menu.name, menu.contactId) onTriggered: root.kickRequested(menu.name, menu.contactId,
menu.currentAddress)
} }
StatusAction { StatusAction {
@ -213,7 +214,8 @@ Control {
enabled: !menu.rawAddress enabled: !menu.rawAddress
type: StatusBaseButton.Type.Danger type: StatusBaseButton.Type.Danger
onTriggered: root.banRequested(menu.name, menu.contactId) onTriggered: root.banRequested(menu.name, menu.contactId,
menu.currentAddress)
} }
} }
} }

View File

@ -45,6 +45,9 @@ StatusDialog {
property var accountsModel property var accountsModel
readonly property alias selectedAccount: d.accountAddress readonly property alias selectedAccount: d.accountAddress
readonly property alias selectedAccountName: d.accountName
readonly property alias deleteMessages: deleteMessagesSwitch.checked
readonly property string feeLabel: qsTr("Remotely destruct 1 TokenMaster token on %1").arg( readonly property string feeLabel: qsTr("Remotely destruct 1 TokenMaster token on %1").arg(
root.networkName) root.networkName)
@ -53,6 +56,13 @@ StatusDialog {
signal kickClicked signal kickClicked
signal banClicked signal banClicked
QtObject {
id: d
property string accountAddress: ""
property string accountName: ""
}
ColumnLayout { ColumnLayout {
anchors.fill: parent anchors.fill: parent
spacing: 20 spacing: 20
@ -155,6 +165,7 @@ StatusDialog {
const item = ModelUtils.get(accountsSelector.model, const item = ModelUtils.get(accountsSelector.model,
accountsSelector.currentIndex) accountsSelector.currentIndex)
d.accountAddress = item.address d.accountAddress = item.address
d.accountName = item.name
} }
} }
} }
@ -191,10 +202,4 @@ StatusDialog {
} }
} }
} }
QtObject {
id: d
property string accountAddress: ""
}
} }

View File

@ -353,6 +353,14 @@ StatusSectionLayout {
communityTokensStore.remoteSelfDestructCollectibles( communityTokensStore.remoteSelfDestructCollectibles(
root.community.id, walletsAndAmounts, tokenKey, accountAddress) root.community.id, walletsAndAmounts, tokenKey, accountAddress)
onRemotelyDestructAndBan:
communityTokensStore.remotelyDestructAndBan(
root.community.id, contactId, tokenKey, accountAddress)
onRemotelyDestructAndKick:
communityTokensStore.remotelyDestructAndKick(
root.community.id, contactId, tokenKey, accountAddress)
onBurnToken: onBurnToken:
communityTokensStore.burnToken(root.community.id, tokenKey, amount, accountAddress) communityTokensStore.burnToken(root.community.id, tokenKey, amount, accountAddress)

View File

@ -71,8 +71,8 @@ StatusScrollView {
signal viewMessagesRequested(string contactId) signal viewMessagesRequested(string contactId)
signal remoteDestructRequested(string name, string address) signal remoteDestructRequested(string name, string address)
signal kickRequested(string name, string contactId) signal kickRequested(string name, string contactId, string address)
signal banRequested(string name, string contactId) signal banRequested(string name, string contactId, string address)
QtObject { QtObject {
id: d id: d
@ -213,8 +213,8 @@ StatusScrollView {
onGeneralAirdropRequested: root.generalAirdropRequested() onGeneralAirdropRequested: root.generalAirdropRequested()
onRemoteDestructRequested: root.remoteDestructRequested(name, address) onRemoteDestructRequested: root.remoteDestructRequested(name, address)
onKickRequested: root.kickRequested(name, contactId) onKickRequested: root.kickRequested(name, contactId, address)
onBanRequested: root.banRequested(name, contactId) onBanRequested: root.banRequested(name, contactId, address)
} }
} }
} }

View File

@ -137,6 +137,14 @@ QtObject {
communityTokensModuleInst.selfDestructCollectibles(communityId, JSON.stringify(walletsAndAmounts), tokenKey, accountAddress) communityTokensModuleInst.selfDestructCollectibles(communityId, JSON.stringify(walletsAndAmounts), tokenKey, accountAddress)
} }
function remotelyDestructAndBan(communityId, contactId, tokenKey, accountAddress, deleteMessages) {
console.warn("remotelyDestructAndBan, not implemented yet!")
}
function remotelyDestructAndKick(communityId, contactId, tokenKey, accountAddress) {
console.warn("remotelyDestructAndKick, not implemented yet!")
}
function burnToken(communityId, tokenKey, burnAmount, accountAddress) { function burnToken(communityId, tokenKey, burnAmount, accountAddress) {
console.assert(typeof burnAmount === "string") console.assert(typeof burnAmount === "string")
communityTokensModuleInst.burnTokens(communityId, tokenKey, burnAmount, accountAddress) communityTokensModuleInst.burnTokens(communityId, tokenKey, burnAmount, accountAddress)