diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 9abd295bf5..7b1e629614 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -1,4 +1,4 @@ -import NimQml, Tables, json, sequtils, chronicles, times, re, sugar, strutils, os +import NimQml, Tables, json, sequtils, chronicles, times, re, sugar, strutils, os, sets import ../../status/status import ../../status/mailservers import ../../status/stickers @@ -91,8 +91,8 @@ QtObject: self.oldestMessageTimestamp = times.toUnix(times.getTime()) self.oldestMessageTimestampChanged() - proc addStickerPackToList*(self: ChatsView, stickerPack: StickerPack, isInstalled, isBought: bool) = - self.stickerPacks.addStickerPackToList(stickerPack, newStickerList(stickerPack.stickers), isInstalled, isBought) + proc addStickerPackToList*(self: ChatsView, stickerPack: StickerPack, isInstalled, isBought, isPending: bool) = + self.stickerPacks.addStickerPackToList(stickerPack, newStickerList(stickerPack.stickers), isInstalled, isBought, isPending) proc getStickerPackList(self: ChatsView): QVariant {.slot.} = newQVariant(self.stickerPacks) @@ -118,6 +118,7 @@ QtObject: proc buyStickerPack*(self: ChatsView, packId: int, address: string, price: string, gas: string, gasPrice: string, password: string): string {.slot.} = try: let response = self.status.stickers.buyPack(packId, address, price, gas, gasPrice, password) + self.stickerPacks.updateStickerPackInList(packId, false, true) result = $(%* { "result": %response }) self.transactionWasSent(response) @@ -145,11 +146,18 @@ QtObject: purchasedStickerPacks = self.status.stickers.getPurchasedStickerPacks(address) let availableStickers = JSON.decode($availableStickersJSON, seq[StickerPack]) + let pendingTransactions = status_wallet.getPendingTransactions().parseJson["result"] + var pendingStickerPacks = initHashSet[int]() + for trx in pendingTransactions.getElems(): + if trx["type"].getStr == $PendingTransactionType.BuyStickerPack: + pendingStickerPacks.incl(trx["data"].getStr.parseInt) + for stickerPack in availableStickers: let isInstalled = installedStickerPacks.hasKey(stickerPack.id) let isBought = purchasedStickerPacks.contains(stickerPack.id) + let isPending = pendingStickerPacks.contains(stickerPack.id) and not isBought self.status.stickers.availableStickerPacks[stickerPack.id] = stickerPack - self.addStickerPackToList(stickerPack, isInstalled, isBought) + self.addStickerPackToList(stickerPack, isInstalled, isBought, isPending) proc getChatsList(self: ChatsView): QVariant {.slot.} = newQVariant(self.chats) @@ -260,12 +268,12 @@ QtObject: proc installStickerPack*(self: ChatsView, packId: int) {.slot.} = self.status.stickers.installStickerPack(packId) - self.stickerPacks.updateStickerPackInList(packId, true) + self.stickerPacks.updateStickerPackInList(packId, true, false) proc uninstallStickerPack*(self: ChatsView, packId: int) {.slot.} = self.status.stickers.uninstallStickerPack(packId) self.status.stickers.removeRecentStickers(packId) - self.stickerPacks.updateStickerPackInList(packId, false) + self.stickerPacks.updateStickerPackInList(packId, false, false) self.recentStickers.removeStickersFromList(packId) proc getRecentStickerList*(self: ChatsView): QVariant {.slot.} = diff --git a/src/app/chat/views/sticker_pack_list.nim b/src/app/chat/views/sticker_pack_list.nim index 0bcee5279e..d9f79f9164 100644 --- a/src/app/chat/views/sticker_pack_list.nim +++ b/src/app/chat/views/sticker_pack_list.nim @@ -1,4 +1,4 @@ -import NimQml, Tables, sequtils, sugar +import NimQml, Tables, sequtils, sugar, sets import ../../../status/chat/stickers, ./sticker_list import ../../../status/libstatus/types, ../../../status/libstatus/utils @@ -13,9 +13,10 @@ type Thumbnail = UserRole + 7 Installed = UserRole + 8 Bought = UserRole + 9 + Pending = UserRole + 10 type - StickerPackView* = tuple[pack: StickerPack, stickers: StickerList, installed, bought: bool] + StickerPackView* = tuple[pack: StickerPack, stickers: StickerList, installed, bought, pending: bool] QtObject: type @@ -52,6 +53,7 @@ QtObject: of StickerPackRoles.Thumbnail: result = newQVariant(decodeContentHash(stickerPack.thumbnail)) of StickerPackRoles.Installed: result = newQVariant(packInfo.installed) of StickerPackRoles.Bought: result = newQVariant(packInfo.bought) + of StickerPackRoles.Pending: result = newQVariant(packInfo.pending) method roleNames(self: StickerPackList): Table[int, string] = { @@ -63,7 +65,8 @@ QtObject: StickerPackRoles.Stickers.int: "stickers", StickerPackRoles.Thumbnail.int: "thumbnail", StickerPackRoles.Installed.int: "installed", - StickerPackRoles.Bought.int: "bought" + StickerPackRoles.Bought.int: "bought", + StickerPackRoles.Pending.int: "pending" }.toTable @@ -85,9 +88,9 @@ QtObject: raise newException(ValueError, "Sticker pack list does not have a pack with id " & $packId) result = find(self.packs, (view: StickerPackView) => view.pack.id == packId).pack - proc addStickerPackToList*(self: StickerPackList, pack: StickerPack, stickers: StickerList, installed, bought: bool) = + proc addStickerPackToList*(self: StickerPackList, pack: StickerPack, stickers: StickerList, installed, bought, pending: bool) = self.beginInsertRows(newQModelIndex(), 0, 0) - self.packs.insert((pack: pack, stickers: stickers, installed: installed, bought: bought), 0) + self.packs.insert((pack: pack, stickers: stickers, installed: installed, bought: bought, pending: pending), 0) self.endInsertRows() proc removeStickerPackFromList*(self: StickerPackList, packId: int) = @@ -96,7 +99,7 @@ QtObject: self.packs.keepItIf(it.pack.id != packId) self.endRemoveRows() - proc updateStickerPackInList*(self: StickerPackList, packId: int, installed: bool) = + proc updateStickerPackInList*(self: StickerPackList, packId: int, installed: bool, pending: bool) = if not self.hasKey(packId): return @@ -104,7 +107,7 @@ QtObject: let bottomRight = self.createIndex(self.packs.len, 0, nil) self.packs.apply(proc(it: var StickerPackView) = if it.pack.id == packId: - it.installed = installed) - - self.dataChanged(topLeft, bottomRight, @[StickerPackRoles.Installed.int]) + it.installed = installed + it.pending = pending) + self.dataChanged(topLeft, bottomRight, @[StickerPackRoles.Installed.int, StickerPackRoles.Pending.int]) diff --git a/ui/app/AppLayouts/Chat/components/StickerButton.qml b/ui/app/AppLayouts/Chat/components/StickerButton.qml index a08b551753..48fd1ad1d6 100644 --- a/ui/app/AppLayouts/Chat/components/StickerButton.qml +++ b/ui/app/AppLayouts/Chat/components/StickerButton.qml @@ -242,8 +242,9 @@ Item { id: mouseArea anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton - cursorShape: Qt.PointingHandCursor + cursorShape: root.isPending ? Qt.ArrowCursor : Qt.PointingHandCursor onClicked: { + if (root.isPending) return; if (root.isInstalled) return root.uninstallClicked(); if (root.packPrice === 0 || root.isBought) return root.installClicked() if (root.isTimedOut) return root.cancelClicked() diff --git a/ui/app/AppLayouts/Chat/components/StickerMarket.qml b/ui/app/AppLayouts/Chat/components/StickerMarket.qml index 7603e4b386..5a3a40d425 100644 --- a/ui/app/AppLayouts/Chat/components/StickerMarket.qml +++ b/ui/app/AppLayouts/Chat/components/StickerMarket.qml @@ -73,6 +73,7 @@ Item { packPrice: price isInstalled: installed isBought: bought + isPending: pending onInstallClicked: root.installClicked(stickers, packId, index) onUninstallClicked: root.uninstallClicked(packId) onCancelClicked: root.cancelClicked(packId) @@ -117,6 +118,7 @@ Item { 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)