fix(@desktop/chat): filter paid stickers if the wallet is not enabled

Fixes: #5923
This commit is contained in:
Sale Djenic 2022-06-21 10:56:12 +02:00 committed by Iuri Matias
parent b83f45c68b
commit 8f4e9bb3da
3 changed files with 185 additions and 137 deletions

View File

@ -52,9 +52,16 @@ QtObject:
self.stickers.insert(sticker, 0) self.stickers.insert(sticker, 0)
self.endInsertRows() self.endInsertRows()
proc findIndexByPackId(self: StickerList, packId: string): int =
for i in 0 ..< self.stickers.len:
if(self.stickers[i].getPackId() == packId):
return i
return -1
proc removeStickersFromList*(self: StickerList, packId: string) = proc removeStickersFromList*(self: StickerList, packId: string) =
if not self.stickers.anyIt(it.getPackId == packId): let idx = self.findIndexByPackId(packId)
if idx == -1:
return return
self.beginRemoveRows(newQModelIndex(), 0, 0) self.beginRemoveRows(newQModelIndex(), idx, idx)
self.stickers.keepItIf(it.getPackId != packId) self.stickers.delete(idx)
self.endRemoveRows() self.endRemoveRows()

View File

@ -105,21 +105,19 @@ QtObject:
proc removeStickerPackFromList*(self: StickerPackList, packId: string) = proc removeStickerPackFromList*(self: StickerPackList, packId: string) =
let idx = self.findIndexById(packId) let idx = self.findIndexById(packId)
self.beginRemoveRows(newQModelIndex(), idx, idx) self.beginRemoveRows(newQModelIndex(), idx, idx)
self.packs.keepItIf(it.pack.id != packId) self.packs.delete(idx)
self.endRemoveRows() self.endRemoveRows()
proc updateStickerPackInList*(self: StickerPackList, packId: string, installed: bool, pending: bool) = proc updateStickerPackInList*(self: StickerPackList, packId: string, installed: bool, pending: bool) =
if not self.hasKey(packId): let idx = self.findIndexById(packId)
if idx == -1:
return return
let index = self.createIndex(idx, 0, nil)
let topLeft = self.createIndex(0, 0, nil)
let bottomRight = self.createIndex(self.packs.len, 0, nil)
self.packs.apply(proc(it: var StickerPackView) = self.packs.apply(proc(it: var StickerPackView) =
if it.pack.id == packId: if it.pack.id == packId:
it.installed = installed it.installed = installed
it.pending = pending) it.pending = pending)
self.dataChanged(index, index, @[StickerPackRoles.Installed.int, StickerPackRoles.Pending.int])
self.dataChanged(topLeft, bottomRight, @[StickerPackRoles.Installed.int, StickerPackRoles.Pending.int])
proc getStickers*(self: StickerPackList): QVariant {.slot.} = proc getStickers*(self: StickerPackList): QVariant {.slot.} =
let packInfo = self.packs[self.packIdToRetrieve] let packInfo = self.packs[self.packIdToRetrieve]

View File

@ -2,6 +2,7 @@ import QtQuick 2.13
import QtQuick.Controls 2.13 import QtQuick.Controls 2.13
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0
import QtQml.Models 2.13
import utils 1.0 import utils 1.0
import shared 1.0 import shared 1.0
@ -39,147 +40,189 @@ Item {
anchors.topMargin: Style.current.padding anchors.topMargin: Style.current.padding
cellWidth: parent.width - (Style.current.padding * 2) cellWidth: parent.width - (Style.current.padding * 2)
cellHeight: height - 72 cellHeight: height - 72
model: stickerPacks
focus: true focus: true
clip: true clip: true
delegate: Item { model: DelegateModel {
width: availableStickerPacks.cellWidth id: delegateModel
height: availableStickerPacks.cellHeight
RoundedImage { function update() {
id: imgPreview if (items.count > 0) {
anchors.top: parent.top items.setGroups(0, items.count, "items");
anchors.left: parent.left }
anchors.right: parent.right
height: 220 var visible = [];
width: parent.width for (var i = 0; i < items.count; ++i) {
radius: 12 var item = items.get(i);
source: model.preview if (delegateModel.walletEnabled ||
onClicked: { !delegateModel.walletEnabled && item.model.price == 0) {
stickerPackDetailsPopup.open() visible.push(item);
}
}
for (i = 0; i < visible.length; ++i) {
item = visible[i];
item.inVisible = true;
if (item.visibleIndex !== i) {
visibleItems.move(item.visibleIndex, i, 1);
}
} }
} }
// TODO: replace with StatusModal readonly property bool walletEnabled: localAccountSensitiveSettings.isWalletEnabled
ModalPopup { onWalletEnabledChanged: {
id: stickerPackDetailsPopup update()
height: 540 }
header: StatusStickerPackDetails {
model: stickerPacks
items.onChanged: update()
filterOnGroup: "visible"
groups: DelegateModelGroup {
id: visibleItems
name: "visible"
includeByDefault: false
}
delegate: Item {
width: availableStickerPacks.cellWidth
height: availableStickerPacks.cellHeight
RoundedImage {
id: imgPreview
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
height: 220
width: parent.width
radius: 12
source: model.preview
onClicked: {
stickerPackDetailsPopup.open()
}
}
// TODO: replace with StatusModal
ModalPopup {
id: stickerPackDetailsPopup
height: 540
header: StatusStickerPackDetails {
packThumb: thumbnail
packName: name
packAuthor: author
packNameFontSize: 17
spacing: Style.current.padding / 2
}
contentWrapper.anchors.topMargin: 0
contentWrapper.anchors.bottomMargin: 0
StatusStickerList {
id: stickerGridInPopup
anchors.fill: parent
anchors.topMargin: Style.current.padding
model: stickers
packId: root.packId
}
footer: StatusStickerButton {
height: 44
anchors.right: parent.right
style: StatusStickerButton.StyleType.LargeNoIcon
packPrice: price
isInstalled: installed
isBought: bought
isPending: pending
onInstallClicked: root.installClicked(stickers, packId, index)
onUninstallClicked: root.uninstallClicked(packId)
onCancelClicked: root.cancelClicked(packId)
onUpdateClicked: root.updateClicked(packId)
onBuyClicked: {
Global.openPopup(stickerPackPurchaseModal)
root.buyClicked(packId)
}
}
}
Component {
id: stickerPackPurchaseModal
StatusSNTTransactionModal {
store: root.store
stickersStore: root.store.stickersStore
contractAddress: root.store.stickersStore.getStickersMarketAddress()
contactsStore: root.store.contactsStore
assetPrice: price
chainId: root.store.stickersStore.getChainIdForStickers()
estimateGasFunction: function(selectedAccount, uuid) {
if (packId < 0 || !selectedAccount || !price) return 325000
return root.store.stickersStore.estimate(packId, selectedAccount.address, price, uuid)
}
onSendTransaction: function(selectedAddress, gasLimit, gasPrice, tipLimit, overallLimit, password, eip1559Enabled) {
return root.store.stickersStore.buy(packId,
selectedAddress,
gasLimit,
gasPrice,
tipLimit,
overallLimit,
password,
eip1559Enabled)
}
onClosed: {
destroy()
}
asyncGasEstimateTarget: root.store.stickersStore.stickersModule
width: stickerPackDetailsPopup.width
height: stickerPackDetailsPopup.height
}
}
StatusStickerPackDetails {
id: stickerPackDetails
height: 64 - (Style.current.smallPadding * 2)
width: parent.width - (Style.current.padding * 2)
anchors.top: imgPreview.bottom
anchors.topMargin: Style.current.smallPadding
anchors.bottomMargin: Style.current.smallPadding
anchors.left: parent.left
anchors.right: parent.right
packThumb: thumbnail packThumb: thumbnail
packName: name packName: name
packAuthor: author packAuthor: author
packNameFontSize: 17
spacing: Style.current.padding / 2
}
contentWrapper.anchors.topMargin: 0 StatusStickerButton {
contentWrapper.anchors.bottomMargin: 0 anchors.right: parent.right
StatusStickerList { packPrice: price
id: stickerGridInPopup width: 75 // only needed for Qt Creator
anchors.fill: parent isInstalled: installed
anchors.topMargin: Style.current.padding isBought: bought
model: stickers isPending: pending
packId: root.packId onInstallClicked: root.installClicked(stickers, packId, index)
} onUninstallClicked: root.uninstallClicked(packId)
onCancelClicked: root.cancelClicked(packId)
footer: StatusStickerButton { onUpdateClicked: root.updateClicked(packId)
height: 44 onBuyClicked: {
anchors.right: parent.right if (!SharedStores.RootStore.isWalletEnabled) {
style: StatusStickerButton.StyleType.LargeNoIcon confirmationPopup.open()
packPrice: price return
isInstalled: installed }
isBought: bought Global.openPopup(stickerPackPurchaseModal)
isPending: pending root.buyClicked(packId)
onInstallClicked: root.installClicked(stickers, packId, index)
onUninstallClicked: root.uninstallClicked(packId)
onCancelClicked: root.cancelClicked(packId)
onUpdateClicked: root.updateClicked(packId)
onBuyClicked: {
Global.openPopup(stickerPackPurchaseModal)
root.buyClicked(packId)
}
}
}
Component {
id: stickerPackPurchaseModal
StatusSNTTransactionModal {
store: root.store
stickersStore: root.store.stickersStore
contractAddress: root.store.stickersStore.getStickersMarketAddress()
contactsStore: root.store.contactsStore
assetPrice: price
chainId: root.store.stickersStore.getChainIdForStickers()
estimateGasFunction: function(selectedAccount, uuid) {
if (packId < 0 || !selectedAccount || !price) return 325000
return root.store.stickersStore.estimate(packId, selectedAccount.address, price, uuid)
}
onSendTransaction: function(selectedAddress, gasLimit, gasPrice, tipLimit, overallLimit, password, eip1559Enabled) {
return root.store.stickersStore.buy(packId,
selectedAddress,
gasLimit,
gasPrice,
tipLimit,
overallLimit,
password,
eip1559Enabled)
}
onClosed: {
destroy()
}
asyncGasEstimateTarget: root.store.stickersStore.stickersModule
width: stickerPackDetailsPopup.width
height: stickerPackDetailsPopup.height
}
}
StatusStickerPackDetails {
id: stickerPackDetails
height: 64 - (Style.current.smallPadding * 2)
width: parent.width - (Style.current.padding * 2)
anchors.top: imgPreview.bottom
anchors.topMargin: Style.current.smallPadding
anchors.bottomMargin: Style.current.smallPadding
anchors.left: parent.left
anchors.right: parent.right
packThumb: thumbnail
packName: name
packAuthor: author
StatusStickerButton {
anchors.right: parent.right
packPrice: price
width: 75 // only needed for Qt Creator
isInstalled: installed
isBought: bought
isPending: pending
onInstallClicked: root.installClicked(stickers, packId, index)
onUninstallClicked: root.uninstallClicked(packId)
onCancelClicked: root.cancelClicked(packId)
onUpdateClicked: root.updateClicked(packId)
onBuyClicked: {
if (!SharedStores.RootStore.isWalletEnabled) {
confirmationPopup.open()
return
} }
}
}
ConfirmationDialog {
id: confirmationPopup
showCancelButton: true
confirmationText: qsTr("This feature is experimental and is meant for testing purposes by core contributors and the community. It's not meant for real use and makes no claims of security or integrity of funds or data. Use at your own risk.")
confirmButtonLabel: qsTr("I understand")
onConfirmButtonClicked: {
SharedStores.RootStore.enableWallet();
close()
Global.openPopup(stickerPackPurchaseModal) Global.openPopup(stickerPackPurchaseModal)
root.buyClicked(packId) root.buyClicked(packId)
} }
}
}
ConfirmationDialog { onCancelButtonClicked: {
id: confirmationPopup close()
showCancelButton: true }
confirmationText: qsTr("This feature is experimental and is meant for testing purposes by core contributors and the community. It's not meant for real use and makes no claims of security or integrity of funds or data. Use at your own risk.")
confirmButtonLabel: qsTr("I understand")
onConfirmButtonClicked: {
SharedStores.RootStore.enableWallet();
close()
Global.openPopup(stickerPackPurchaseModal)
root.buyClicked(packId)
}
onCancelButtonClicked: {
close()
} }
} }
} }