feat(SelfDestructPopup): Updated self destruct tokens lists management

- Updated expected model roles (removed `selfDestruct` and `selfDestructAmount`)
- Self destruct tokens list management is now done inside `SelfDestructPopup).
- Store receives a js array with {walletAddress, amount} roles.
This commit is contained in:
Noelia 2023-04-27 12:12:09 +02:00 committed by Jonathan Rainville
parent 2087616b82
commit 42a5236b10
6 changed files with 52 additions and 42 deletions

View File

@ -6,37 +6,28 @@ ListModel {
nzPcxEzGExhBdJGYihtAYQlO+tUZvqrPbqeudo5iJGEJjCE15a3VtodH3q2ImYgiNITTlTdG1nUZ5a92VITQxITFiJmIIjSE0htAYQrMHAAD//+wwFVpz+yqXAAAAAElFTkSuQmCC" nzPcxEzGExhBdJGYihtAYQlO+tUZvqrPbqeudo5iJGEJjCE15a3VtodH3q2ImYgiNITTlTdG1nUZ5a92VITQxITFiJmIIjSE0htAYQrMHAAD//+wwFVpz+yqXAAAAAElFTkSuQmCC"
readonly property var data: [ readonly property var data: [
{ {
ensName: "carmen.eth", name: "carmen.eth",
walletAddress: "0xb794f5450ba39494ce839613fffba74279579268", walletAddress: "0xb794f5450ba39494ce839613fffba74279579261",
imageSource: image, imageSource: image,
amount: 15, amount: 15
selfDestructAmount: 2,
selfDestruct: false
}, },
{ {
ensName: "chris.eth", name: "chris.eth",
walletAddress: "0xb794f5ea0ba39494ce839613fffba74279579268", walletAddress: "0xb794f5ea0ba39494ce839613fffba74279579262",
imageSource: image, imageSource: image,
amount: 5, amount: 5
selfDestructAmount: 4,
selfDestruct: false
}, },
{ {
ensName: "emily.eth", name: "emily.eth",
walletAddress: "0xb794f5ea0ba39494ce839613fffba74279579268", walletAddress: "0xb794f5ea0ba39494ce839613fffba74279579263",
imageSource: image, imageSource: image,
amount: 2, amount: 2
selfDestructAmount: 2,
selfDestruct: false
}, },
{ {
ensName: "", name: "",
walletAddress: "0xb794f5ea0ba39494ce839613fffba74279579268", walletAddress: "0xb794f5ea0ba39494ce839613fffba74279579268",
imageSource: "", imageSource: "",
amount: 1, amount: 1
selfDestructAmount: 1,
selfDestruct: false
} }
] ]

View File

@ -51,7 +51,7 @@ SettingsPageLayout {
signal signMintTransactionOpened(int chainId, string accountAddress) signal signMintTransactionOpened(int chainId, string accountAddress)
signal remoteSelfDestructCollectibles(var tokenOwnersModel, signal remoteSelfDestructCollectibles(var selfDestructTokensList, // [key , amount]
int chainId, int chainId,
string accountName, string accountName,
string accountAddress) string accountAddress)
@ -90,6 +90,7 @@ SettingsPageLayout {
property string chainName property string chainName
property var tokenOwnersModel property var tokenOwnersModel
property var selfDestructTokensList
readonly property var initialItem: (root.tokensModel && root.tokensModel.count > 0) ? mintedTokensView : welcomeView readonly property var initialItem: (root.tokensModel && root.tokensModel.count > 0) ? mintedTokensView : welcomeView
onInitialItemChanged: updateInitialStackView() onInitialItemChanged: updateInitialStackView()
@ -287,6 +288,7 @@ SettingsPageLayout {
model: d.tokenOwnersModel model: d.tokenOwnersModel
onSelfDestructClicked: { onSelfDestructClicked: {
d.selfDestructTokensList = selfDestructTokensList
alertPopup.tokenCount = tokenCount alertPopup.tokenCount = tokenCount
alertPopup.open() alertPopup.open()
} }
@ -304,7 +306,7 @@ SettingsPageLayout {
function signSelfRemoteDestructTransaction() { function signSelfRemoteDestructTransaction() {
root.isFeeLoading = true root.isFeeLoading = true
root.feeText = "" root.feeText = ""
root.remoteSelfDestructCollectibles(d.tokenOwnersModel, root.remoteSelfDestructCollectibles(d.selfDestructTokensList,
d.chainId, d.chainId,
d.accountName, d.accountName,
d.accountAddress) d.accountAddress)

View File

@ -21,8 +21,8 @@ Control {
property string tokenName property string tokenName
property bool isSelectorMode: false property bool isSelectorMode: false
signal selfDestructChanged() signal selfDestructAmountChanged(string walletAddress, int amount)
signal selfDestructRemoved(string walletAddress)
QtObject { QtObject {
id: d id: d
@ -125,8 +125,8 @@ Control {
} }
control.onDisplayTextChanged: { control.onDisplayTextChanged: {
selfDestructAmount = combo.currentIndex + 1 if(checkBox.checked)
root.selfDestructChanged() root.selfDestructAmountChanged(walletAddress, Number(combo.currentIndex) + 1)
} }
} }
@ -135,11 +135,12 @@ Control {
Layout.leftMargin: Style.current.padding Layout.leftMargin: Style.current.padding
visible: root.isSelectorMode visible: root.isSelectorMode
checked: root.isSelectorMode ? selfDestruct : false
padding: 0 padding: 0
onCheckStateChanged: { onCheckStateChanged: {
selfDestruct = checked if(checked)
root.selfDestructChanged() root.selfDestructAmountChanged(model.walletAddress, Number(combo.currentIndex) + 1)
else
root.selfDestructRemoved(model.walletAddress)
} }
} }
} }

View File

@ -20,13 +20,14 @@ StatusDialog {
property string collectibleName property string collectibleName
signal selfDestructClicked(int tokenCount) signal selfDestructClicked(int tokenCount, var selfDestructTokensList)
QtObject { QtObject {
id: d id: d
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 {}
function getVerticalPadding() { function getVerticalPadding() {
return root.topPadding + root.bottomPadding return root.topPadding + root.bottomPadding
@ -36,15 +37,26 @@ StatusDialog {
return root.leftPadding + root.rightPadding return root.leftPadding + root.rightPadding
} }
function calculateTotalTokensToDestruct() { function updateTokensToDestruct(walletAddress, amount) {
d.tokenCount = 0 if(ModelUtils.contains(d.selfDestructTokensList, "walletAddress", walletAddress))
for(var i = 0; i < tokenHoldersPanel.model.count; i ++) { clearTokensToDesctruct(walletAddress)
var item = ModelUtils.get(tokenHoldersPanel.model, i)
if(item.selfDestruct) { d.selfDestructTokensList.append({"walletAddress": walletAddress,
d.tokenCount += item.selfDestructAmount "amount": amount})
} updateTokensCount()
}
} }
function clearTokensToDesctruct(walletAddress) {
var index = ModelUtils.indexOf(d.selfDestructTokensList, "walletAddress", walletAddress)
d.selfDestructTokensList.remove(index)
updateTokensCount()
}
function updateTokensCount() {
d.tokenCount = 0
for(var i = 0; i < d.selfDestructTokensList.count; i ++)
d.tokenCount += ModelUtils.get(d.selfDestructTokensList, i, "amount")
}
} }
title: qsTr("Remotely self-destruct %1 token").arg(root.collectibleName) title: qsTr("Remotely self-destruct %1 token").arg(root.collectibleName)
@ -66,7 +78,8 @@ StatusDialog {
tokenName: root.collectibleName tokenName: root.collectibleName
isSelectorMode: true isSelectorMode: true
onSelfDestructChanged: d.calculateTotalTokensToDestruct() onSelfDestructAmountChanged: d.updateTokensToDestruct(walletAddress, amount)
onSelfDestructRemoved: d.clearTokensToDesctruct(walletAddress)
} }
} }
@ -77,7 +90,9 @@ StatusDialog {
enabled: d.tokenCount > 0 enabled: d.tokenCount > 0
text: qsTr("Self-destruct %n token(s)", "", d.tokenCount) text: qsTr("Self-destruct %n token(s)", "", d.tokenCount)
type: StatusBaseButton.Type.Danger type: StatusBaseButton.Type.Danger
onClicked: root.selfDestructClicked(d.tokenCount) onClicked: root.selfDestructClicked(d.tokenCount,
ModelUtils.modelToArray(d.selfDestructTokensList,
["walletAddress", "amount"]))
} }
} }
} }

View File

@ -302,7 +302,7 @@ StatusSectionLayout {
} }
onSignSelfDestructTransactionOpened: communityTokensStore.computeSelfDestructFee(chainId) onSignSelfDestructTransactionOpened: communityTokensStore.computeSelfDestructFee(chainId)
onRemoteSelfDestructCollectibles: { onRemoteSelfDestructCollectibles: {
communityTokensStore.remoteSelfDestructCollectibles(tokenOwnersModel, communityTokensStore.remoteSelfDestructCollectibles(selfDestructTokensList,
chainId, chainId,
accountName, accountName,
accountAddress) accountAddress)

View File

@ -46,8 +46,9 @@ QtObject {
console.warn("TODO: Compute self-destruct fee backend") console.warn("TODO: Compute self-destruct fee backend")
} }
function remoteSelfDestructCollectibles(holdersModel, chainId, accountName, accountAddress) { function remoteSelfDestructCollectibles(selfDestructTokensList, chainId, accountName, accountAddress) {
// TODO BACKEND // TODO BACKEND
// selfDestructTokensList is a js array with properties: `walletAddress` and `amount`
console.warn("TODO: Remote self-destruct collectible backend") console.warn("TODO: Remote self-destruct collectible backend")
} }