fix(stickers): fix crash in async task + clean up + set bought status

Fixes #12664
This commit is contained in:
Jonathan Rainville 2023-11-09 15:31:11 -05:00
parent 3b06ae5893
commit cf74fc2111
4 changed files with 19 additions and 18 deletions

View File

@ -122,8 +122,11 @@ QtObject:
self.packs.apply(proc(it: var StickerPackView) =
if it.pack.id == packId:
it.installed = installed
if installed:
it.bought = true
it.pending = pending)
self.dataChanged(index, index, @[StickerPackRoles.Installed.int, StickerPackRoles.Pending.int])
self.dataChanged(index, index, @[StickerPackRoles.Installed.int, StickerPackRoles.Bought.int,
StickerPackRoles.Pending.int])
proc getStickers*(self: StickerPackList): QVariant {.slot.} =
let packInfo = self.packs[self.packIdToRetrieve]

View File

@ -120,7 +120,8 @@ method onUserAuthenticated*(self: Module, password: string) =
self.tmpBuyStickersTransactionDetails.eip1559Enabled
)
if response.error.isEmptyOrWhitespace():
self.view.stickerPacks.updateStickerPackInList(self.tmpBuyStickersTransactionDetails.packId, false, true)
self.view.stickerPacks.updateStickerPackInList(self.tmpBuyStickersTransactionDetails.packId, installed = false,
pending = true)
self.view.transactionWasSent(chainId = response.chainId, txHash = response.txHash, error = response.error)
method obtainMarketStickerPacks*(self: Module) =
@ -250,10 +251,10 @@ method getChainIdForStickers*(self: Module): int =
return self.controller.getChainIdForStickers()
method stickerTransactionConfirmed*(self: Module, trxType: string, packID: string, transactionHash: string) =
self.view.stickerPacks.updateStickerPackInList(packID, true, false)
self.view.stickerPacks.updateStickerPackInList(packID, installed = true, pending = false)
self.controller.installStickerPack(packID)
self.view.emitTransactionCompletedSignal(true, transactionHash, packID, trxType)
method stickerTransactionReverted*(self: Module, trxType: string, packID: string, transactionHash: string) =
self.view.stickerPacks.updateStickerPackInList(packID, false, false)
self.view.stickerPacks.updateStickerPackInList(packID, installed = false, pending = false)
self.view.emitTransactionCompletedSignal(false, transactionHash, packID, trxType)

View File

@ -7,12 +7,13 @@ type
packId*: string
fromAddress*: string
uuid*: string
ObtainMarketStickerPacksTaskArg = ref object of QObjectTaskArg
chainId*: int
InstallStickerPackTaskArg = ref object of QObjectTaskArg
packId*: string
chainId*: int
hasKey*: bool
AsyncGetRecentStickersTaskArg* = ref object of QObjectTaskArg
AsyncGetInstalledStickerPacksTaskArg* = ref object of QObjectTaskArg
@ -68,9 +69,7 @@ const obtainMarketStickerPacksTask: Task = proc(argEncoded: string) {.gcsafe, ni
const installStickerPackTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[InstallStickerPackTaskArg](argEncoded)
if not arg.hasKey:
arg.finish(false)
return
var installed = false
try:
let installResponse = status_stickers.install(arg.chainId, arg.packId)

View File

@ -174,10 +174,6 @@ QtObject:
error "Error reverting sticker transaction", message = getCurrentExceptionMsg()
proc init*(self: Service) =
# TODO redo the connect check when the network is refactored
# if self.status.network.isConnected:
self.obtainMarketStickerPacks() # TODO: rename this to obtain sticker market items
self.events.on(PendingTransactionTypeDto.BuyStickerPack.event) do(e: Args):
var receivedData = TransactionMinedArgs(e)
if receivedData.success:
@ -258,16 +254,16 @@ QtObject:
for stickerPack in availableStickers:
if self.marketStickerPacks.contains(stickerPack.id): continue
let isBought = stickerPack.status == StickerPackStatus.Purchased
self.marketStickerPacks[stickerPack.id] = stickerPack
self.events.emit(SIGNAL_STICKER_PACK_LOADED, StickerPackLoadedArgs(
stickerPack: stickerPack,
isInstalled: false,
isBought: isBought,
isBought: stickerPack.status == StickerPackStatus.Purchased,
isPending: false
))
let chainId = self.networkService.getNetworkForStickers().chainId
# TODO move this to be async
let pendingStickerPacksResponse = status_stickers.pending()
for (packID, stickerPackJson) in pendingStickerPacksResponse.result.pairs():
if self.marketStickerPacks.contains(packID): continue
@ -379,7 +375,6 @@ QtObject:
error "error loading installed sticker packs", msg = error.message
return
var stickerPacks: Table[string, StickerPackDto] = initTable[string, StickerPackDto]()
for (packID, stickerPackJson) in rpcResponseObj{"result"}.pairs():
self.installedStickerPacks[packID] = stickerPackJson.toStickerPackDto()
self.events.emit(SIGNAL_LOAD_INSTALLED_STICKER_PACKS_DONE, StickerPacksArgs(packs: self.installedStickerPacks))
@ -403,20 +398,23 @@ QtObject:
slot: "onStickerPackInstalled",
chainId: self.networkService.getNetworkForStickers().chainId,
packId: packId,
hasKey: self.marketStickerPacks.hasKey(packId)
)
self.threadpool.start(arg)
proc onStickerPackInstalled*(self: Service, installedPackJson: string) {.slot.} =
let installedPack = Json.decode(installedPackJson, tuple[packId: string, installed: bool])
if installedPack.installed:
if self.marketStickerPacks.hasKey(installedPack.packId):
self.marketStickerPacks[installedPack.packId].status = StickerPackStatus.Installed
self.events.emit(SIGNAL_STICKER_PACK_INSTALLED, StickerPackInstalledArgs(
packId: installedPack.packId
))
else:
error "Sticker pack did not get installed", packId = installedPack.packId
proc uninstallStickerPack*(self: Service, packId: string) =
try:
let installedResponse = status_stickers.uninstall(packId)
discard status_stickers.uninstall(packId)
except RpcException:
error "Error removing installed sticker", message = getCurrentExceptionMsg()