mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-20 10:38:47 +00:00
fix(Communities): Remotely destruct popup for regular collectibles integrated
Closes: #11924
This commit is contained in:
parent
d031072514
commit
81cc2070e9
@ -31,7 +31,9 @@ SplitView {
|
|||||||
orientation: Qt.Vertical
|
orientation: Qt.Vertical
|
||||||
SplitView.fillWidth: true
|
SplitView.fillWidth: true
|
||||||
|
|
||||||
Item {
|
Pane {
|
||||||
|
id: pane
|
||||||
|
|
||||||
SplitView.fillWidth: true
|
SplitView.fillWidth: true
|
||||||
SplitView.fillHeight: true
|
SplitView.fillHeight: true
|
||||||
|
|
||||||
@ -49,17 +51,35 @@ SplitView {
|
|||||||
RemotelyDestructPopup {
|
RemotelyDestructPopup {
|
||||||
id: dialog
|
id: dialog
|
||||||
|
|
||||||
anchors.centerIn: parent
|
margins: 250
|
||||||
|
topMargin: 30
|
||||||
|
|
||||||
|
closePolicy: Popup.NoAutoClose
|
||||||
|
visible: true
|
||||||
|
modal: false
|
||||||
|
destroyOnClose: false
|
||||||
|
parent: pane
|
||||||
|
anchors.centerIn: pane
|
||||||
|
|
||||||
|
|
||||||
collectibleName: editorCollectible.text
|
collectibleName: editorCollectible.text
|
||||||
model: TokenHoldersModel {}
|
model: TokenHoldersModel {}
|
||||||
accounts: accountsModel
|
accounts: accountsModel
|
||||||
chainName: "Optimism"
|
chainName: "Optimism"
|
||||||
feeText: "0,01et(100Usd)"
|
feeText: "0,01 ETH (60,34 USD)"
|
||||||
onRemotelyDestructClicked: {
|
onRemotelyDestructClicked: {
|
||||||
logs.logEvent("RemoteSelfDestructPopup::onRemotelyDestructClicked")
|
logs.logEvent("RemoteSelfDestructPopup::onRemotelyDestructClicked",
|
||||||
|
["walletsAndAmounts", "accountAddress"], [
|
||||||
|
JSON.stringify(walletsAndAmounts), accountAddress
|
||||||
|
])
|
||||||
close()
|
close()
|
||||||
}
|
}
|
||||||
onRemotelyDestructFeesRequested: logs.logEvent("RemoteSelfDestructPopup::onRemotelyDestructClicked")
|
onRemotelyDestructFeesRequested: {
|
||||||
|
logs.logEvent("RemoteSelfDestructPopup::onRemotelyDestructFeesRequested",
|
||||||
|
["walletsAndAmounts", "accountAddress"], [
|
||||||
|
JSON.stringify(walletsAndAmounts), accountAddress
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
open()
|
open()
|
||||||
|
@ -56,6 +56,9 @@ QtObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function indexOf(model, role, key) {
|
function indexOf(model, role, key) {
|
||||||
|
if (!model)
|
||||||
|
return -1
|
||||||
|
|
||||||
const count = model.rowCount()
|
const count = model.rowCount()
|
||||||
|
|
||||||
for (let i = 0; i < count; i++)
|
for (let i = 0; i < count; i++)
|
||||||
|
@ -67,10 +67,10 @@ StackView {
|
|||||||
|
|
||||||
signal deployFeesRequested(int chainId, string accountAddress, int tokenType)
|
signal deployFeesRequested(int chainId, string accountAddress, int tokenType)
|
||||||
signal burnFeesRequested(string tokenKey, string amount, string accountAddress)
|
signal burnFeesRequested(string tokenKey, string amount, string accountAddress)
|
||||||
signal remotelyDestructFeesRequest(var remotelyDestructTokensList, // [key , amount]
|
signal remotelyDestructFeesRequest(var walletsAndAmounts, // { [walletAddress (string), amount (int)] }
|
||||||
string tokenKey,
|
string tokenKey,
|
||||||
string accountAddress)
|
string accountAddress)
|
||||||
signal remotelyDestructCollectibles(var remotelyDestructTokensList, // [key , amount]
|
signal remotelyDestructCollectibles(var walletsAndAmounts, // { [walletAddress (string), amount (int)] }
|
||||||
string tokenKey,
|
string tokenKey,
|
||||||
string accountAddress)
|
string accountAddress)
|
||||||
signal signBurnTransactionOpened(string tokenKey, string amount, string accountAddress)
|
signal signBurnTransactionOpened(string tokenKey, string amount, string accountAddress)
|
||||||
@ -623,7 +623,7 @@ StackView {
|
|||||||
onBurnClicked: burnTokensPopup.open()
|
onBurnClicked: burnTokensPopup.open()
|
||||||
|
|
||||||
// helper properties to pass data through popups
|
// helper properties to pass data through popups
|
||||||
property var remotelyDestructTokensList
|
property var walletsAndAmounts
|
||||||
property string burnAmount
|
property string burnAmount
|
||||||
property string accountAddress
|
property string accountAddress
|
||||||
|
|
||||||
@ -639,15 +639,16 @@ StackView {
|
|||||||
isFeeLoading: root.isFeeLoading
|
isFeeLoading: root.isFeeLoading
|
||||||
feeErrorText: root.feeErrorText
|
feeErrorText: root.feeErrorText
|
||||||
|
|
||||||
onRemotelyDestructFeesRequested:root.remotelyDestructFeesRequest(remotelyDestructTokensList,
|
onRemotelyDestructFeesRequested: {
|
||||||
tokenKey,
|
root.remotelyDestructFeesRequest(walletsAndAmounts,
|
||||||
|
view.token.key,
|
||||||
accountAddress)
|
accountAddress)
|
||||||
|
}
|
||||||
|
|
||||||
onRemotelyDestructClicked: {
|
onRemotelyDestructClicked: {
|
||||||
remotelyDestructPopup.close()
|
remotelyDestructPopup.close()
|
||||||
footer.accountAddress = accountAddress
|
footer.accountAddress = accountAddress
|
||||||
footer.remotelyDestructTokensList = remotelyDestructTokensList
|
footer.walletsAndAmounts = walletsAndAmounts
|
||||||
alertPopup.tokenCount = tokenCount
|
|
||||||
alertPopup.open()
|
alertPopup.open()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -655,9 +656,8 @@ StackView {
|
|||||||
AlertPopup {
|
AlertPopup {
|
||||||
id: alertPopup
|
id: alertPopup
|
||||||
|
|
||||||
property int tokenCount
|
title: qsTr("Remotely destruct %n token(s)", "",
|
||||||
|
remotelyDestructPopup.tokenCount)
|
||||||
title: qsTr("Remotely destruct %n token(s)", "", tokenCount)
|
|
||||||
acceptBtnText: qsTr("Remotely destruct")
|
acceptBtnText: qsTr("Remotely destruct")
|
||||||
alertText: qsTr("Continuing will destroy tokens held by members and revoke any permissions they are given. To undo you will have to issue them new tokens.")
|
alertText: qsTr("Continuing will destroy tokens held by members and revoke any permissions they are given. To undo you will have to issue them new tokens.")
|
||||||
|
|
||||||
@ -677,7 +677,8 @@ StackView {
|
|||||||
root.setFeeLoading()
|
root.setFeeLoading()
|
||||||
|
|
||||||
if(signTransactionPopup.isRemotelyDestructTransaction)
|
if(signTransactionPopup.isRemotelyDestructTransaction)
|
||||||
root.remotelyDestructCollectibles(footer.remotelyDestructTokensList, tokenKey, footer.accountAddress)
|
root.remotelyDestructCollectibles(footer.walletsAndAmounts,
|
||||||
|
tokenKey, footer.accountAddress)
|
||||||
else
|
else
|
||||||
root.burnToken(tokenKey, footer.burnAmount, footer.accountAddress)
|
root.burnToken(tokenKey, footer.burnAmount, footer.accountAddress)
|
||||||
|
|
||||||
@ -698,7 +699,7 @@ StackView {
|
|||||||
onOpened: {
|
onOpened: {
|
||||||
root.setFeeLoading()
|
root.setFeeLoading()
|
||||||
signTransactionPopup.isRemotelyDestructTransaction
|
signTransactionPopup.isRemotelyDestructTransaction
|
||||||
? root.remotelyDestructFeesRequest(footer.remotelyDestructTokensList, tokenKey, footer.accountAddress)
|
? root.remotelyDestructFeesRequest(footer.walletsAndAmounts, tokenKey, footer.accountAddress)
|
||||||
: root.signBurnTransactionOpened(tokenKey, footer.burnAmount, footer.accountAddress)
|
: root.signBurnTransactionOpened(tokenKey, footer.burnAmount, footer.accountAddress)
|
||||||
}
|
}
|
||||||
onSignTransactionClicked: signTransaction()
|
onSignTransactionClicked: signTransaction()
|
||||||
|
@ -79,12 +79,9 @@ Control {
|
|||||||
Layout.topMargin: 12
|
Layout.topMargin: 12
|
||||||
isSelectorMode: root.isSelectorMode
|
isSelectorMode: root.isSelectorMode
|
||||||
model: filteredModel
|
model: filteredModel
|
||||||
onSelfDestructRemoved: {
|
onSelfDestructRemoved: root.selfDestructRemoved(walletAddress)
|
||||||
root.selfDestructRemoved(walletAddress);
|
onSelfDestructAmountChanged: root.selfDestructAmountChanged(
|
||||||
}
|
walletAddress, amount)
|
||||||
onSelfDestructAmountChanged: {
|
|
||||||
root.selfDestructAmountChanged(walletAddress, amount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Rectangle {
|
Rectangle {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import QtQuick 2.14
|
import QtQuick 2.15
|
||||||
import QtQuick.Controls 2.14
|
import QtQuick.Controls 2.15
|
||||||
import QtQuick.Layouts 1.14
|
import QtQuick.Layouts 1.15
|
||||||
import QtQml.Models 2.14
|
import QtQml.Models 2.15
|
||||||
|
|
||||||
import StatusQ.Core 0.1
|
import StatusQ.Core 0.1
|
||||||
import StatusQ.Controls 0.1
|
import StatusQ.Controls 0.1
|
||||||
@ -26,10 +26,12 @@ StatusDialog {
|
|||||||
property string feeErrorText: ""
|
property string feeErrorText: ""
|
||||||
property string feeLabel: qsTr("Remotely destruct %1 token on %2").arg(root.collectibleName).arg(root.chainName)
|
property string feeLabel: qsTr("Remotely destruct %1 token on %2").arg(root.collectibleName).arg(root.chainName)
|
||||||
|
|
||||||
|
readonly property alias tokenCount: d.tokenCount
|
||||||
|
|
||||||
// Account expected roles: address, name, color, emoji, walletType
|
// Account expected roles: address, name, color, emoji, walletType
|
||||||
property var accounts
|
property var accounts
|
||||||
signal remotelyDestructClicked(int tokenCount, var remotelyDestructTokensList, string accountAddress)
|
signal remotelyDestructClicked(var walletsAndAmounts, string accountAddress)
|
||||||
signal remotelyDestructFeesRequested(int tokenCount, var remotelyDestructTokensList, string accountAddress)
|
signal remotelyDestructFeesRequested(var walletsAndAmounts, string accountAddress)
|
||||||
|
|
||||||
QtObject {
|
QtObject {
|
||||||
id: d
|
id: d
|
||||||
@ -37,7 +39,7 @@ StatusDialog {
|
|||||||
property string accountAddress
|
property string accountAddress
|
||||||
readonly property int maxHeight: 560 // by design
|
readonly property int maxHeight: 560 // by design
|
||||||
property int tokenCount: 0
|
property int tokenCount: 0
|
||||||
readonly property ListModel selfDestructTokensList: ListModel {}
|
readonly property ListModel walletsAndAmountsList: ListModel {}
|
||||||
readonly property bool isFeeError: root.feeErrorText !== ""
|
readonly property bool isFeeError: root.feeErrorText !== ""
|
||||||
|
|
||||||
function getVerticalPadding() {
|
function getVerticalPadding() {
|
||||||
@ -49,27 +51,40 @@ StatusDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateTokensToDestruct(walletAddress, amount) {
|
function updateTokensToDestruct(walletAddress, amount) {
|
||||||
if(ModelUtils.contains(d.selfDestructTokensList, "walletAddress", walletAddress))
|
const index = ModelUtils.indexOf(d.walletsAndAmountsList,
|
||||||
clearTokensToDesctruct(walletAddress)
|
"walletAddress", walletAddress)
|
||||||
|
|
||||||
|
if (index !== -1)
|
||||||
|
d.walletsAndAmountsList.setProperty(index, "amount", amount)
|
||||||
|
else
|
||||||
|
d.walletsAndAmountsList.append({ walletAddress, amount })
|
||||||
|
|
||||||
d.selfDestructTokensList.append({"walletAddress": walletAddress,
|
|
||||||
"amount": amount})
|
|
||||||
updateTokensCount()
|
updateTokensCount()
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearTokensToDesctruct(walletAddress) {
|
function clearTokensToDestruct(walletAddress) {
|
||||||
var index = ModelUtils.indexOf(d.selfDestructTokensList, "walletAddress", walletAddress)
|
const index = ModelUtils.indexOf(d.walletsAndAmountsList,
|
||||||
d.selfDestructTokensList.remove(index)
|
"walletAddress", walletAddress)
|
||||||
|
d.walletsAndAmountsList.remove(index)
|
||||||
updateTokensCount()
|
updateTokensCount()
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTokensCount() {
|
function updateTokensCount() {
|
||||||
d.tokenCount = 0
|
const amounts = ModelUtils.modelToFlatArray(
|
||||||
for(var i = 0; i < d.selfDestructTokensList.count; i ++)
|
d.walletsAndAmountsList, "amount")
|
||||||
d.tokenCount += ModelUtils.get(d.selfDestructTokensList, i, "amount")
|
const sum = amounts.reduce((a, b) => a + b, 0)
|
||||||
if (d.tokenCount > 0) {
|
d.tokenCount = sum
|
||||||
root.remotelyDestructFeesRequested(d.tokenCount, d.selfDestructTokensList, d.accountAddress);
|
|
||||||
|
if (sum > 0)
|
||||||
|
sendFeeRequest()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendFeeRequest() {
|
||||||
|
const walletsAndAmounts = ModelUtils.modelToArray(
|
||||||
|
d.walletsAndAmountsList)
|
||||||
|
|
||||||
|
root.remotelyDestructFeesRequested(walletsAndAmounts,
|
||||||
|
d.accountAddress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +101,7 @@ StatusDialog {
|
|||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
isSelectorMode: true
|
isSelectorMode: true
|
||||||
onSelfDestructAmountChanged: d.updateTokensToDestruct(walletAddress, amount)
|
onSelfDestructAmountChanged: d.updateTokensToDestruct(walletAddress, amount)
|
||||||
onSelfDestructRemoved: d.clearTokensToDesctruct(walletAddress)
|
onSelfDestructRemoved: d.clearTokensToDestruct(walletAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
FeesBox {
|
FeesBox {
|
||||||
@ -108,21 +123,13 @@ StatusDialog {
|
|||||||
if (accountsSelector.currentIndex < 0)
|
if (accountsSelector.currentIndex < 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
const item = ModelUtils.get(accountsSelector.model, accountsSelector.currentIndex)
|
const item = ModelUtils.get(accountsSelector.model,
|
||||||
|
accountsSelector.currentIndex)
|
||||||
d.accountAddress = item.address
|
d.accountAddress = item.address
|
||||||
|
|
||||||
// Whenever a change in the form happens, new fee calculation:
|
// Whenever a change in the form happens, new fee calculation:
|
||||||
if (d.tokenCount > 0)
|
if (d.tokenCount > 0)
|
||||||
root.remotelyDestructFeesRequested(d.tokenCount, d.selfDestructTokensList, d.accountAddress)
|
d.sendFeeRequest()
|
||||||
}
|
|
||||||
|
|
||||||
ModelChangeTracker {
|
|
||||||
model: d.selfDestructTokensList
|
|
||||||
|
|
||||||
// Whenever a change in the form happens, new fee calculation:
|
|
||||||
onRevisionChanged: {
|
|
||||||
root.remotelyDestructFeesRequested(d.tokenCount, d.selfDestructTokensList, d.accountAddress)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QtObject {
|
QtObject {
|
||||||
@ -149,10 +156,15 @@ StatusDialog {
|
|||||||
enabled: d.tokenCount > 0
|
enabled: d.tokenCount > 0
|
||||||
text: qsTr("Remotely destruct %n token(s)", "", d.tokenCount)
|
text: qsTr("Remotely destruct %n token(s)", "", d.tokenCount)
|
||||||
type: StatusBaseButton.Type.Danger
|
type: StatusBaseButton.Type.Danger
|
||||||
onClicked: root.remotelyDestructClicked(d.tokenCount,
|
|
||||||
ModelUtils.modelToArray(d.selfDestructTokensList,["walletAddress", "amount"]),
|
onClicked: {
|
||||||
|
const walletsAndAmounts = ModelUtils.modelToArray(
|
||||||
|
d.walletsAndAmountsList)
|
||||||
|
|
||||||
|
root.remotelyDestructClicked(walletsAndAmounts,
|
||||||
d.accountAddress)
|
d.accountAddress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -385,11 +385,11 @@ StatusSectionLayout {
|
|||||||
|
|
||||||
onRemotelyDestructFeesRequest:
|
onRemotelyDestructFeesRequest:
|
||||||
communityTokensStore.computeSelfDestructFee(
|
communityTokensStore.computeSelfDestructFee(
|
||||||
remotelyDestructTokensList, tokenKey, accountAddress)
|
walletsAndAmounts, tokenKey, accountAddress)
|
||||||
|
|
||||||
onRemotelyDestructCollectibles:
|
onRemotelyDestructCollectibles:
|
||||||
communityTokensStore.remoteSelfDestructCollectibles(
|
communityTokensStore.remoteSelfDestructCollectibles(
|
||||||
root.community.id, remotelyDestructTokensList, tokenKey, accountAddress)
|
root.community.id, walletsAndAmounts, tokenKey, accountAddress)
|
||||||
|
|
||||||
onSignBurnTransactionOpened:
|
onSignBurnTransactionOpened:
|
||||||
communityTokensStore.computeBurnFee(tokenKey, amount, accountAddress)
|
communityTokensStore.computeBurnFee(tokenKey, amount, accountAddress)
|
||||||
|
@ -108,14 +108,23 @@ QtObject {
|
|||||||
communityTokensModuleInst.computeDeployFee(chainId, accountAddress, tokenType, isOwnerDeployment)
|
communityTokensModuleInst.computeDeployFee(chainId, accountAddress, tokenType, isOwnerDeployment)
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeSelfDestructFee(selfDestructTokensList, tokenKey, accountAddress) {
|
/**
|
||||||
|
* walletsAndAmounts - array of following structure is expected:
|
||||||
|
* [
|
||||||
|
* {
|
||||||
|
* walletAddress: string
|
||||||
|
* amount: int
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
*/
|
||||||
|
function computeSelfDestructFee(walletsAndAmounts, tokenKey, accountAddress) {
|
||||||
//TODO uncomment accountAddress when supported in backend
|
//TODO uncomment accountAddress when supported in backend
|
||||||
communityTokensModuleInst.computeSelfDestructFee(JSON.stringify(selfDestructTokensList), tokenKey, /*accountAddress*/)
|
communityTokensModuleInst.computeSelfDestructFee(JSON.stringify(walletsAndAmounts), tokenKey, /*accountAddress*/)
|
||||||
}
|
}
|
||||||
|
|
||||||
function remoteSelfDestructCollectibles(communityId, selfDestructTokensList, tokenKey, accountAddress) {
|
function remoteSelfDestructCollectibles(communityId, walletsAndAmounts, tokenKey, accountAddress) {
|
||||||
//TODO uncomment accountAddress when supported in backend
|
//TODO uncomment accountAddress when supported in backend
|
||||||
communityTokensModuleInst.selfDestructCollectibles(communityId, JSON.stringify(selfDestructTokensList), tokenKey, /*accountAddress*/)
|
communityTokensModuleInst.selfDestructCollectibles(communityId, JSON.stringify(walletsAndAmounts), tokenKey, /*accountAddress*/)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Burn:
|
// Burn:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user